magento / magento/community-features

Problem with the translations from javascript in Magento 2.2.2

Open
#73 0 comments 0 reactions 0 assignees View on GitHub
moved from magento2 Priority: P4
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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.