This document discusses internationalization (i18n) in Magento 2. It explains how language translations work by loading translations from different sources in order, with the most specific taking precedence. It provides examples of translating text using inline translations, language packs, and theme translations. It notes some limitations, such as theme translations not working for JavaScript translations, and recommends avoiding direct changes to template files. It also suggests future improvements like translating to CMS blocks.
4. ▪ 300+ e-commerce websites since 1997
▪ Substantial e-commerce website experience (ca. 100 yrs)
▪ Magento specialists since 2010 (ca. 100 implementations)
▪ Magento 2 certified
▪ Shopify Plus certified
I work for a company called “Screen Pages”
7 YEARS OF
MAGENTO
9. i18n?
Let’s THINK BIG!
internationalisation and localisation are means of adapting computer
software to different languages, regional differences and technical
requirements of a target market (locale)
14. module-contact: contents of en_US.csv
"Write Us","Write Us"
"Jot us a note and we’ll get back to you as quickly as possible.","Jot us a note and we’ll get back to you as
quickly as possible."
Name,Name
Email,Email
"Phone Number","Phone Number"
"What’s on your mind?","What’s on your mind?"
Submit,Submit
"Name: %name","Name: %name"
"Email: %email","Email: %email"
"Phone Number: %telephone","Phone Number: %telephone"
"Comment: %comment","Comment: %comment"
"Contacts Section","Contacts Section"
Contacts,Contacts
"Contact Us","Contact Us"
18. How do translations work:
public function loadData($area = null, $forceReload = false)
{
…
$this->_loadModuleTranslation();
$this->_loadThemeTranslation();
$this->_loadPackTranslation();
$this->_loadDbTranslation();
…
return $this;
}
[YOUR SITE]/vendor/magento/framework/Translate.php
19. Who wins?
1. $this->_loadDbTranslation();
Not there?
2. $this->_loadPackTranslation();
Not there?
3. $this->_loadThemeTranslation();
Not there?
4. $this->_loadModuleTranslation();
Not there? It will simply output the original phrase.
20. Golden rules for today:
WEBSITE OWNER ALWAYS THINKING BIG!
e.g. future multilingual website store views,
in-house seasonal store views
Not allowed to change a translation in template files
29. Language Pack: Example files
Some examples in es_ES.csv:
In our en_GB.csv:
(note: remember to clear your translation caches and any others that apply)
37. Anything else?
1. $this->_loadDbTranslation(); (GLOBAL)
2. $this->_loadPackTranslation(); (GLOBAL)
3. $this->_loadThemeTranslation(); (GLOBAL)
4. $this->_loadModuleTranslation(); (MODULE)
What about theme level changes in a foreign language website
e.g. two Spanish store views?
38. How about this solution:
1. $this->_loadDbTranslation(); (GLOBAL)
2. $this->_loadThemeModuleTranslation(); (MODULE)
3. $this->_loadThemeTranslation(); (GLOBAL)
4. $this->_loadPackTranslation(); (GLOBAL)
5. $this->_loadModuleTranslation(); (MODULE)
39. But what about super active client…?
What if the client wants to change their own translations at a
very specific module level!?
44. Basket page translations: where they come from
<!-- ko ifnot: getCartParam('summary_count') -->
<strong class="subtitle empty" data-bind="visible:
closeSidebar()">
<!-- ko i18n: 'You have no items in your shopping cart.' --
><!-- /ko -->
</strong>
.../module-checkout/view/frontend/web/template/minicart/content.html
…/module-checkout/view/frontend/templates/cart/noItems.phtml
<div class="cart-empty">
<?php echo $block->getChildHtml('checkout_cart_empty_widget'); ?>
<p><?php echo __('You have no items in your shopping cart.') ?></p>
…
</div>
…
46. Oops.
Careful: Theme translations don’t currently work with js-translation.json file.
In vendor/magento/module-translation/Model/Json/PreProcessor.php function process(…)
$area = $this->areaList->getArea($areaCode);
$area->load(MagentoFrameworkAppArea::PART_TRANSLATE);
needs to be:
$area = $this->areaList->getArea($areaCode);
$area->load(MagentoFrameworkAppArea::PART_DESIGN);
$area->load(MagentoFrameworkAppArea::PART_TRANSLATE);
Ref: https://github.com/magento/magento2/issues/8508#issuecomment-281329241
48. Another nice to have: Translation Phrase -> CMS Block:
In our en_GB.csv:
"Jot us a note and we’ll get back to you as quickly as possible.","{{{Contact_Us_Write_To_Us_Into}}}"
49. To summarise:
▪ Magento 2 has translations well covered.
▪ Make sure you create a i18n folder and translation .csv in your module.
▪ Try to avoid making phrase changes directly in template files.
▪ Be careful when making an existing phrase change. Does it exist elsewhere!?
▪ Read the devdocs ☺ devdocs.magento.com/guides/v2.0/ search for “Translations”
▪ Drink Horchata – It’s good for you too apparently! ☺