Magento 2 Localisation – Fix Translating Problem in JS Templates

localisationmagento2

Is there a way to translate phrases defined in JS templates in Magento 2?
I have checked official translation structure overview and searched the net but can't seem to find proper solution.

For example: I wish to translate Qty string within minicart element. I have added the following translation to i18n/xx_XX.csv:

"Qty","Translation"

but doesn't take effect after refreshing. Other strings within the csv that are server side generated are translated fine.

I also have tried with deleting all cache files within /var and refreshing/flushing cache from admin.

Thanks for any suggestions.

Best Answer

Ok, so finally got this resolved by creating a new language pack, modified certain template files and cleared all caches:

  1. Created a new language pack:
    • created new folder inside app/i18n/< vendor >/xx_xx/
    • created 3 necessary files: language.xml, registration.php, xx_XX.csv according to official guidelines (mind lower and uppercases of folders and files)
    • translated the store front within the csv
    • cleared all the caches within administration
  2. As almost all strings were translated except the minicart & checkout items my next steps were:
    • copied each corresponding html file for specific element to my theme_folder/module which started to pull the new translations from my language pack. For example on how i translated mini cart string "Recently added item(s)": i copied the content.html from app/design/frontend/< vendor >/< blank >/Magento_Checkout/web/template/minicart/content.html to my corresponding theme module folder. Doing this the translations from my language package were getting translated.

Those strings that didn't get translated in step 1. and got translated in step 2. by copying the module files to theme folder had the attribute data-bind="i18n.

Reference: Creating a language pack in M2 (official)

Related Topic