Skip to main content

How to translate service messages

Our extension supports multilanguage stores. To translate it, we have used the same logic as default Magento.

1. Find i18n folders

All our translation files are in the i18n folder of each sub-module.

i18n files should be located at:

  • If installed via composer: vendor/mirasvit/module-name/src/ModuleName/i18n
  • If installed manually: app/code/Mirasvit/ModuleName/i18n

2. Create a separate .csv file of your language for our extension

The names of all languages can be found with this command:

php -f bin/magento info:language:list

3. Override the strings in your dictionary file

First column is original line, second column your translated line:

example

"Original line" , "Translated line"

To avoid rewriting the file with the updating of the module, replace the translation file to your theme directory at app/design/frontend/THEME_VENDOR/theme_name/i18n/lg_LG.csv. Where lg_LG.csv is a translation file in another locale.


4. Apply translations

To apply changes run static content deploy :

rm -rf pub/static/*
rm -rf var/view_preprocessed/*
php -f bin/magento setup:static-content:deploy
php -f bin/magento cache:flush

Examples

Use the examples below to translate service messages in Autocomplete:

Translate "Sorry, nothing has been found for" and "View all results →"
  1. Open src/SearchAutocomplete/i18n/ directory to find the translation files;
  2. Make a copy of original en_EN.csv file, for example, nl_NL.csv file;
  3. Open nl_NL.csv file for editing;
  1. Change lines as below:

    • "Sorry, nothing has been found for ""%1."" change %1 to %s
    • View all %1 results → change %1 to %d

    Examples:

    • "Sorry, nothing has been found for ""%s."", "Sorry niets gevonden voor ""%s.""
    • "View all %d results →", "Bekijk alle %d resultaten →"
  2. Temporarily disable a Fast mode in the autocomplete settings;

  3. Run static content deploy;

  4. Enable Fast Mode and run Magento reindex.

Please do not add both kinds of translations in your locale file for a Fast mode enabled and disabled option. It will not work.