Using locales to translate phrases in your store

Magento supports multilingual stores, and offers locale files to allow content in the interface to be translated. Page and product content is translated through Magento's administration panel (for example, you will have an English "terms and conditions" page and a separate "terms and conditions" page for the French version of your store). Interface labels—such as the text in buttons and the user bar—can be translated by adding a locale file to your Magento theme.

At the moment, our Magento theme displays the text as Add to Cart on the product screen:

Using locales to translate phrases in your store

By using Magento locale files, you can change the wording to something more appropriate for your store; in the following example, Add to Cart will be changed to Add to basket.

Creating a Magento locale file

A Magento locale file is a Comma Separate Values (CSV) file, which contains alternate translations for specified labels in your store's interface. The default text for this phrase is in the left-hand column; the right-hand column contains the new translation for this text.

Tip

You can download the official locale files for Magento in many languages from http://www.magentocommerce.com/translations.

Create a file called translate.csv in the /app/design/frontend/default/m18/locale/en_GB/ directory. The last directory's name equates to the locale language's ISO 639 code; en_GB indicates that this is a British English translation. Add the following line for a change in the button's label on the product page highlighted above:

"Add to Cart", "Add to basket"

You can add more translations for your store's theme in this locale file by adding one phrase per line:

"Add to Cart", "Add to basket"
"My Cart", "My basket"
"Cart", "Basket"

You now need to navigate to System | Configuration, and select Locale Options under the General tab to see the value of the Locale field; in the following screenshot, it is set to English (United Kingdom):

Creating a Magento locale file

If you have changed the value of Locale, click on the Save Config button at the top-right corner of the screen and refresh your store once you've saved these changes. You should now be able to see the new translations, as shown in the following screenshot:

Creating a Magento locale file

The translate function

Only the text filtered through the __() function, which is an alias (alternate name) of the translate() function, is translated in this way. For example, the following code snippet will allow you to translate the text of the heading through locale files:

<h2><?php echo $this->__('Create an Account') ?></h2>

Alternatively, the following example, which does not use the __() function, will not use the alternate text provided in the locale file:

<h2>Create an Account</h2>

You can also enable inline translation for your Magento store by navigating to System | Configuration | Developer | Translate Inline.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset