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