3

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

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

如果 view.phtml 如下所示,则为 fox 示例:

 <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 数据。您可以自由询问更多详细信息。我尝试添加大部分需要的数据来配置内联翻译。希望尽快得到答案。提前谢谢

4

1 回答 1

1

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

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

有关创建控制器的教程,请参阅类似的教程,或者还有许多其他教程。

于 2013-04-13T18:04:24.993 回答