Reputation: 70
inline translation in magento is not working for the data which is loaded from ajax.
I had used following for installation: http://blog.chapagain.com.np/magento-language-translation-for-custom-module-step-by-step-guide/
I have created following template file for the display of my product details.
magento\app\design\frontend\default\default\template\catalog\product\view.phtml
it has following code:
<?php $_helper = $this->helper('catalog/output'); ?>
<?php $_product = $this->getProduct(); ?>
<?php echo $this->__('desired word') ?>
I have created a custom module for inline translation to load csv file for all my custom modules.
\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>
To activate module, \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>
I have added Translation.csv in following folders:
\magento\app\locale\en_US
\magento\app\locale\zh_HK
So,after enabling inline translation from admin side for English as well Chinese storeview,its working well but my question is what if my data in view.hmtl is loaded from ajax not like __('desired word');?>
fox exmaple if view.phtml is as follows:
<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>
Now hi.php is as follows:
<?php
echo "hi.This is the page that gives product's detail";
?>
so,I want inline translation working for this data too.or is there any other way to load data of ajax in php in form of echo. You are free to ask more details.i try to add most of the needed data to configure inline translation.hoping for the answer asap.thank you in advance
Upvotes: 3
Views: 6035
Reputation: 2334
If you're specifically speaking about inline translation, you are correct that this code is not translatable. This is because Magento has not been initialized within hi.php
- you are just outputting text. What you will need to do is set up a controller to handle your AJAX calls which then will have Mage initialized and therefore you will have access to the entire Magento framework.
Note that I also don't use inline translation for most things, rather I define the translations in my theme's translate.csv
file.
For a tutorial on creating a controller, see a tutorial like this or there are many others floating around.
Upvotes: 1