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.

Feature(messageformat): Support locale to lang mapping in MessageFormatTranspiler

See original GitHub issue

Current behavior

In our app we use EN, DE and FR languages. We have dedicated jsons for translations and also use corresponding locales. Also we have an empty json called ‘keys’ and it is our ‘keys’ language. This allows us to see the keys in the UI to help with translations.

Recently we added the locale support with transloco locale package, and also pluralization support with messageformatt. Overall it works as it should. But we lost the ability to show the keys in the UI.

After digging around I found that when we change the language from ‘en’ to ‘keys’, messageformat breaks with the error:

core.js:6479 ERROR Error: Localisation function not found for locale "keys"

This was weird because there is a setting option called langToLocaleMapping which should map ‘keys’ to the English values. For some reason that was ignored. So I went to sources and found out that MessageFormatTranspiler does this: image

I got the feeling that the map is not used here because it is used in TranslocoLocaleModule, not TranslocoMessageFormatModule. And also setLocale(lang) seems wrong, at least naming wise.

Expected behavior

I’d expect MessageFormatTranspiler to resolve lang to locale and pass correct value to MessageFormat.

Minimal reproduction of the problem with instructions

Provide the STEPS TO REPRODUCE and if possible a MINIMAL DEMO of the problem, for that you could use our stackblitz example

Screenshots

If applicable, add screenshots to help explain your problem.

Transloco config

Environment


"@ngneat/transloco": "^2.23.0",
"@ngneat/transloco-locale": "^1.4.0",
"@ngneat/transloco-messageformat": "^1.3.1",
"messageformat": "^2.3.0",
 Angular version: ^12.2.5

Browser:

  • Chrome (desktop) version 93
  • Chrome (Android) version XX
  • Chrome (iOS) version XX
  • Firefox version XX
  • Safari (desktop) version XX
  • Safari (iOS) version XX
  • IE version XX
  • Edge version XX

Contribution

I would like to make a pull request for this feature: [x] Yes! 🚀 [ ] Maybe next time

Issue Analytics

  • State:open
  • Created 2 years ago
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
MikeDabrowskicommented, Sep 16, 2021

I guess I would not, unless hitting some language specific quirk that one locale handles better than other. Ok, so kick out the PR and keep setting language as locale. I overrode this on my end and things are again working as they used to. Im used to hitting the ‘1% cases’ errors 😁

1reaction
MikeDabrowskicommented, Sep 16, 2021

Let me explain my reasoning. My initial reaction when I read setLocale(lang) and saw the implementation was ‘it’s a bug’. And that is because the setLocale implementation had a parameter called locale but when it was used it received lang. In Transloco locale and lang are not interchangeable. Why should they be here? Then I went to messageformat and it turns out they resolve both lang and locale, from the same parameter.

Why shouldn’t I be able to pick whick lang uses which localized message format? Transloco already have the tools to allow for similar remappings, and I may not be far from the truth if I say most of the users using mf also do use TranslocoLocale.

In the end, I agree, I can handle this on my own just like you said.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Supporting Multiple Locales - MessageFormat
Built-in support for multiple languages or locales is inherent to messageformat at all levels. For the best results, you may want to separate...
Read more >
message-format-inline - npm
locale is a string with a BCP 47 language tag, or an array of such strings. internal apis. format.number , format.
Read more >
@phensley/messageformat | Yarn - Package Manager
Compact and extensible ICU message formatter with built-in support for plural , select , and selectordinal . Also supports plural calculations using ...
Read more >
Guide to Angular localization with Transloco examples
The library provides features for testing multi-language support. ... transloco-locale, and transloco-messageformat libraries.
Read more >
MessageFormat (Java Platform SE 7 ) - Oracle Help Center
MessageFormat provides a means to produce concatenated messages in a language-neutral way. Use this to construct messages displayed for end users.
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