php - 内联翻译在 magento 中不起作用

标签 php ajax magento

magento 中的内联翻译不适用于从 ajax 加载的数据。

我使用了以下安装: http://blog.chapagain.com.np/magento-language-translation-for-custom-module-step-by-step-guide/

我已经创建了以下模板文件来显示我的产品详细信息。

magento\app\design\frontend\default\default\template\catalog\product\view.phtml

它有以下代码:

<?php $_helper = $this->helper('catalog/output'); ?>
<?php $_product = $this->getProduct(); ?>
<?php echo $this->__('desired word') ?>

我已经创建了一个用于内联翻译的自定义模块,以便为我的所有自定义模块加载 csv 文件。 \magento\app\code\local\Translations\Inline\etc\config.xml

<?xml version="1.0"?>
<config>
  <modules>
    <Translations_Inline>
      <version>0.1.0</version>
    </Translations_Inline>
  </modules>
   <frontend>
        <translate>
            <modules>
                <translations>
                    <files>
                        <default>Translations.csv</default>
                    </files>
                 </translations>
            </modules>
        </translate>
    </frontend>
    <adminhtml>
        <translate>
            <modules>
               <translations>
                    <files>
                        <default>Translations.csv</default>
                    </files>
                </translations>
            </modules>
        </translate>
    </adminhtml>
  <global>
    <helpers>
      <inline>
        <class>Translations_Inline_Helper</class>
      </inline>
     </helpers>
  </global>
</config> 

要激活模块, \magento\app\etc\modules\Translations_Inline.xml

<?xml version="1.0"?>
  <config>
     <modules>
        <Translations_Inline>
          <active>true</active>
          <codePool>local</codePool>
          <version>0.1.0</version>
        </Translations_Inline>
      </modules>
 </config>

我在以下文件夹中添加了 Translation.csv:

\magento\app\locale\en_US

\magento\app\locale\zh_HK

因此,在从管理员端为英文和中文商店 View 启用内联翻译后,它运行良好,但我的问题是,如果我在 view.hmtl 中的数据是从 ajax 加载的,而不是像 __('想要的词');?>

fox exmaple if view.phtml 如下:

 <script type="text/javascript">
var url_magento = '<?php echo        Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_WEB); ?>';    

  var j = jQuery.noConflict();
  j(document).ready(function()
  {
getcontent();

 });
 function getcontent()
 {

jQuery.ajax({
    url:url_magento+'hi.php',
    type:'POST',
    beforeSend: function(){
                jQuery('#product_app').html('loading');
                },      
    ajaxError : function() {                
                jQuery('#product_app').html('Error: Can not load page');
            },
    success: function(data){
                //alert(data);
                jQuery('#product_app').html(data);          
            }
        }); 

    }
</script>
<div id='product_app'></div>

现在hi.php如下:

 <?php  
   echo "hi.This is the page that gives product's detail";
 ?>

所以,我也想对这些数据进行内联翻译。或者有没有其他方法可以在 php 中以 echo 的形式加载 ajax 数据。 您可以自由询问更多详细信息。我尝试添加大部分需要的数据来配置内联翻译。希望尽快得到答案。提前谢谢您

最佳答案

如果您专门谈论内嵌翻译,那么这段代码不可翻译是对的。这是因为 Magento 尚未在 hi.php 中初始化 - 您只是在输出文本。您需要做的是设置一个 Controller 来处理您的 AJAX 调用,然后初始化 Mage,因此您将可以访问整个 Magento 框架。

请注意,我也不对大多数内容使用内联翻译,而是在主题的 translate.csv 文件中定义翻译。

有关创建 Controller 的教程,请参阅类似 this 的教程或者有许多其他人漂浮在周围。

关于php - 内联翻译在 magento 中不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15984940/

相关文章:

javascript - 如何验证我所有的 (JavaScript) AJAX 请求? (发送到 Node.js)

ajax - 仅当请求不是 AJAX 时才包含 CakePHP 组件?

magento - 使用可配置产品创建 Magento 捆绑或组合产品

php - 无法在 wamp 服务器上安装 magento

php - 来自外部应用程序的 OpenSocial 身份验证

php 变量范围 - 包含/必需脚本与 ajax

php - Helm + Kubernetes,在 PHP 中加载和启用扩展或模块

php - 使用php中的多个关键字搜索数据库

php - 来自精确表格的数据

python - 我的 magento python 客户端没有安装