magento / magento/community-features
Problem with the translations from javascript in Magento 2.2.2
- Dominant language
- No language data
- Stars
- 46
- Forks
- 14
- PR merge metrics
- No merged PRs in 30d
Description
Hi! I'm developing a project on _Magento 2.2.2_ and I don't know if it's a new bug or I'm not doing well the correct steps when I try to do a translation from javascript and it works if I do it from a static text...
The problem comes if I try to translate using a variable. In that case the translation is not done correctly and it does not look for the associated translation that is generated in the file js-translation.json
As I know that maybe I do not explain well I put an example in code:
It works!
`$t("Blue")`
Doesn't works... ️:S
`label = "Blue";`
`$t(label);`
If I follow the steps indicated in the official documentation (https://devdocs.magento.com/guides/v2.0/frontend-dev-guide/translations/translate_theory.html), it does not work either.
`$t('%1').replace('%1', label);`
Someone can help me, please?
**Original Report**: https://github.com/magento/magento2/issues/16290 by @ekiba
Contributor guide
No contributing guide indexed for this repository
Research direction
Start with the official translation documentation and inspect how JavaScript messages are represented in js-translation.json. Compare the literal `$t("Blue")` case with the variable and replacement examples, then verify whether a variable-based translation is resolved correctly and document the reproducible result.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript
- Domain
- frontend, internationalization
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100