SPECIAL OFFER: ENJOY 3 MONTHS OF SHOPIFY FOR $1/MONTH SPECIAL OFFER: ENJOY 3 MONTHS OF SHOPIFY FOR $1/MONTH SPECIAL OFFER: ENJOY 3 MONTHS OF SHOPIFY FOR $1/MONTH SPECIAL OFFER: ENJOY 3 MONTHS OF SHOPIFY FOR $1/MONTH SPECIAL OFFER: ENJOY 3 MONTHS OF SHOPIFY FOR $1/MONTH SPECIAL OFFER: ENJOY 3 MONTHS OF SHOPIFY FOR $1/MONTH SPECIAL OFFER: ENJOY 3 MONTHS OF SHOPIFY FOR $1/MONTH SPECIAL OFFER: ENJOY 3 MONTHS OF SHOPIFY FOR $1/MONTH SPECIAL OFFER: ENJOY 3 MONTHS OF SHOPIFY FOR $1/MONTH SPECIAL OFFER: ENJOY 3 MONTHS OF SHOPIFY FOR $1/MONTH
I18n
I18n

What is i18n and how to use them in Magento 2?

In the current globalization trend, using many different languages in a website is essential to help your service reach many customers around the world. Multilanguage helps sellers provide service and products to many customers coming from any country increase customer experiences. Today we are going to learn about the i18n multilingual package that allows you to express multiple languages on your Magento website.

1. What is i18n in Magento 2?

i18n stands for ‘Internationalization’. This is an important ingredient and is used a lot in Magento. It helps to translate the current language into other languages, localizes the Magento store for many different regions and markets, and varies from string to string in all places that contain the string that order on the site.

2. Where to put i18n?

  • Package: app / i18n /
  • Module: <module_dir> / i18n /
  • Theme:

             <parent_theme_dir> / i18n / (repeated on all child themes)

             <current_theme_dir> / i18n / (works on current theme only)

3. Structure of i18n

Folder i18n includes dictionary files with the extension (.csv), the filename is the locale code of the country where the language you want to translate to (Magento’s default locale is en_US). For example: en_AU.csv, de_DE.csv, km_KH.csv …

The files (.csv) located in the i18n folder contain at least 2 columns:

  • Column 1: Phrase, an original string of default locale (en_US)
  • Column 2: Translation of phrase, a string of characters in another locale or within that locale.

 For example: “Add to Cart”, “Zum Warenkorb hinzufügen

4. How to use i18n?

Step 1: Install a new language pack (Eg: de_DE):

Step 2: Find and download the language pack to install with the keyword: ‘github magento 2 language <locale code>’. Eg: github magento 2 language de_DE

Step 3: Place the downloaded language pack at: app / i18n / [your package name] /de_DE/de_DE.csv

Step 4 : Config locale in admin: Dashboard> STORES> Configuration> GENERAL> General> Locale Options – Locale = German (Germany)

Step 5: Run the deploy command with the language locale: php bin / magento setup: static-content: deploy de_DE

Step 6: Clear the Cache in admin or run the command: php bin/magento cache:flush

5. Notes

For i18n to work properly, the translated text must ensure:

In the .phtml

Text file is placed in the __ (‘<your_string>’) method.   For example: <? Php echo __ (‘Add to cart ‘)?>

In email template

Text is placed in structure in:

{{trans “Lorem Ipsum is simply dummy text of the printing”}}

{trans “% items items” items = “numItems”}}

In the UI component template

Text must be placed in the structure

 <span data-bind = “i18n:‘ string name ‘”> </span>

 <! – ko i18n: ‘String name ‘-> <! – / ko ->

 <input type = “text” data-bind = “attr: {placeholder: $ t (‘ String name ‘)} “/>

In js file

Need to add library ‘mage / translate’:

define ([‘jquery’, ‘mage / translate’], function ($) {…});

Use the function: $ .mage .__ (‘String name ‘); to add text.

Above is information about the i18n package and how to use them in Magento 2. Hope this guide helps you!