-
-
Notifications
You must be signed in to change notification settings - Fork 202
Feature(messageformat): Support locale to lang mapping in MessageFormatTranspiler #501
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
So the solution seems to be to inject LOCALE_LANG_MAPPING and use it to translate lang to locale in MessageFormatTranspiler. |
@MikeDabrowski Thanks for the detailed issue. I wonder if all of this is really necessary, you can resolve this issue on your half by extending the Messageformat transpiler and overriding the Correct me if I'm wrong, but if you didn't have the |
Let me explain my reasoning. My initial reaction when I read 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. |
@MikeDabrowski There is no dought that this is a useful feature if it's really needed as I said, would you need it if it wasn't for your Even if we do want to implement it I want to think of how should we do it, not sure I want the coupling that your PR shows between the locale and messageformat packages. I think that for now, we will keep things as is, and if it's raised again in the future we can rethink this. 🙂 |
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 😁 |
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:
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: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
Browser:
Contribution
I would like to make a pull request for this feature:
[x] Yes! 🚀
[ ] Maybe next time
The text was updated successfully, but these errors were encountered: