1

I am having a translation issue where magento generates empty js-translation.json files only. This issue has been reported a number of times:

Github:

https://github.com/magento/magento2/issues/8508 https://github.com/magento/magento2/issues/9073 https://github.com/magento/magento2/issues/4067

Magento.stackexchange / stackoverflow:

Magento 2 - Translations : how does js-translation.json get populated? Mine is empty! https://stackoverflow.com/questions/35876380/magento-2-translating-strings-in-js-ko

(Many more example can be found on google for these or similar.)

The only general solution seems to be to generate the file yourself. Now, It looks like the format described here should work: http://i18njs.com/ , but magento can handle a couple more things, like making translations dependent on modules and such.

Could someone give me a sample of a working js-translation.json file? Just a translatable string or 2 should probably be enough for me to create my own file.

1 Answer 1

0

js-translation.json file contains only array, so technically you can just add [].

If you have problem with autogeneration, use simple command: bin/magento setup:static-content:deploy --theme=Vendor/Theme en_US -f with your theme: Vendor/Theme and language code: en_US.

5
  • Autotheme generation, even with that command, didn't work. We already tried that. Also, I know the empty array - that's all we have. What I needed is a sample of how to map values.
    – Gloweye
    Commented May 22, 2018 at 6:48
  • [edit timed out] Currently, we have just changed the template that generated the javascript, which works well enough. (the javascript in question was in a phtml template, so I shifted the translation to PHP.)(file in question was vendor/magento/module-configurable-product/view/base/templates/product/price/tier_price.phtml)
    – Gloweye
    Commented May 22, 2018 at 6:54
  • Map is pretty simple - just a key:value: ["Please enter at least {0} characters":"Podaj co najmniej {0} znaków"]
    – dudzio
    Commented May 23, 2018 at 7:14
  • That's not even valid JSON. Or are you talking about {"Please enter at least {0} characters":"Podaj co najmniej {0} znaków"}, with the curly braces? If so, update the answer with that and I'll accept it.
    – Gloweye
    Commented May 24, 2018 at 8:18
  • Sure, sorry for the mistake.
    – dudzio
    Commented May 25, 2018 at 10:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.