I mean never write like this:
<?php
echo "Hello World!";
?>
But use Magento inbuilt translation method as:
<?php echo $this->__('Hello World'); ?>!
This method will look into the tanslation CSV file of you module and will replace the string to its complementary value.
Define translation CSV file for your module
You can define the translation file for your module in the config.xml file of your Magento module as:
<config>
...
<frontend>
...
<translate>
<modules>
<MyNamespace_MyModule>
<files>
<default>MyModule.csv</default>
</files>
</MyNamespace_MyModule>
</modules>
</translate>
</frontend>
<config>
Create the translation CSV file
Now create the MyModule.csv at this location: [root]appdesignfrontend[theme_folder]defaultlocale[localization_folder]MyModule.csvwhere [localization_folder] can be fr_FR or en_EN based upon the locale you want to translate into. The CSV file should contain the trannslation strings in the key-value pair format as:
"Hello World", "Bonjour tout le monde"
"Checkout", "Caisse"
"Discount", "Réduction"
This is all and you are done!
Nice explanation but I want to make a small correction. The best practices say that the name of the translation file should be formed by the namespace and the extension name because you can have to modules with the same name but not in the same namespace. This ensures that the file is unique. So the file name in this case should be ‘MyNamespace_MyModule.csv’.
Thanks for your advice 🙂
Thanks !!! Good Info