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
Fast Mode

When Enable fast mode is on, autocomplete does not read the translation files on each request. Its messages are saved when the autocomplete configuration is generated, so new translations appear in autocomplete only after you do one of the following:

  • save Stores -> Configuration -> Mirasvit Extensions -> Search Ultimate;
  • run a full reindex of the search index: php -f bin/magento indexer:reindex catalogsearch_fulltext.

The search results page and autocomplete with Fast Mode off use the new translations right after the 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. Open the translation file for your language if it already exists, or create a new one (e.g. nl_NL.csv) by copying en_US.csv;

  3. Add or update the lines as below:

    • "Sorry, nothing has been found for ""%1""." → "Sorry, niets gevonden voor ""%1""."
    • "View all %1 results →" → "Bekijk alle %1 resultaten →"
  4. Apply translations as described in step 4.

Translate the misspell notices "Your search returned no results for" and "Showing results for … instead"

These notices appear in autocomplete and on the search results page when the extension corrects a misspelled query. Their source lines are in two dictionaries: src/SearchAutocomplete/i18n/ and src/Misspell/i18n/. Add your lines to the translation file in your theme directory: it overrides both dictionaries.

  1. Open or create app/design/frontend/THEME_VENDOR/theme_name/i18n/lg_LG.csv (e.g. nl_NL.csv);

  2. Add the lines as below:

    • "Your search returned no results for '<strong>%1</strong>'.","Uw zoekopdracht naar '<strong>%1</strong>' leverde geen resultaten op."
    • "Showing results for '<strong>%1</strong>' instead.","In plaats daarvan worden resultaten voor '<strong>%1</strong>' getoond."
  3. Apply translations as described in step 4.

warning

Copy the original line exactly as it is, including the <strong> and </strong> tags and the quotes. If the original line differs in any character, Magento does not match it and the notice keeps its previous text without any error.

note

Since version 2.8.3, these notices use the same %1 placeholder whether Fast Mode is enabled or disabled. In earlier versions, autocomplete with Fast Mode enabled used %s instead of %1 in these two lines, so translations made with %1 were not applied there.