question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Nesting of translations breaks Testing

See original GitHub issue

Since nesting (similar to this) is not supported by ember-intl yet, the alternative is to define a translation json as:

{
  "reuseText": "{count, plural, =1 {Name} other {Names}}",
  "secondKey: "{reuseText} has Hello world"
}

and in the template we define the usage as {{t "secondKey" reuseText=(t "reuseText" count=2)}}. This isn’t going to throw an error. Instead, the reuseText key is translated to proper text and applied as a param to the secondKey.

But the same template when running in its test case throws an error similar to this.

After debugging, the test cases scenario, I figured out that the stringify method makes an additional escape character for double quotes: ". And the same value is now applied to the first translation as a value to reuseText. But since the intl.message.parser cannot translate a key that contains a \, the error of #616 comes up - but only in test cases. The reason being, ember-intl’s test-support helper overrides the missing-message translation util.

  1. One possible solution is to fix this to replace even the escaped double quotes with a simple doubt quotes in here.

  2. Or, if nesting translations is itself a part of the ember-intl addon, the solution gets simpler where we could define the translation something like the following similar to i18next:

{
  "reuseText": "{count, plural, =1 {Name} other {Names}}",
  "secondKey: "$t(reuseText) has Hello world"
}
  1. Or, is it a mistake to do a translation and then apply that string value to another key?

  2. The other possible solution is to rewrite all the strings which are similar to reuseText as it’s value manually in all the places which are again a tedious manual process like the following:

{
  "reuseText": "{count, plural, =1 {Name} other {Names}}",
  "secondKey: "{count, plural, =1 {Name} other {Names}} has Hello world"
}
  1. Or, is there another totally different solution to this?
  • I am on the latest ember-intl version
  • I have searched the issues of this repo and believe that this is not a duplicate

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:1
  • Comments:12 (12 by maintainers)

github_iconTop GitHub Comments

2reactions
buschtoenscommented, Nov 13, 2019

I’ll take a look!

1reaction
jasonmitcommented, Apr 26, 2020

Released as v4.3.2

Thanks!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Formatting nested translations · Issue #1377 · i18next ... - GitHub
The question is, if manually interpolating nested translation from format function (besides being ugly) would not break further flow if ...
Read more >
How can I enable react-i18n translation file to be used in the ...
Now when I run the tests, it seems that it doesn't find/use the translation files and all places where there should read something, ......
Read more >
Interpolation - i18next documentation
Interpolation is one of the most used functionalities in I18N. It allows integrating dynamic values into your translations.
Read more >
How to Assess Translation Quality Without a Test ... - Lionbridge
Sample translations break all the rules. Although a test translation seems like the easiest way to evaluate a professional translation ...
Read more >
Unable to translate some parts of our nested Gravity Forms
I am trying to: Translate one of our forms built in Gravity Forms. I can translate most of it, however, there are built...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found