-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
Standard way of using react-intl dynamically #80
Comments
@AntonioAcevedo it seems that a bunch of people are having a hard time trying to imagine how to architect their app in such a way that passing intl messages around is not problematic. we should probably provide some guidance about this, but so far, we have tried hard not to be opinionated on how you should do this, since that belongs to the user-land. I will make sure we answers those questions soon. As for the fallback, react-intl does support fallback on locales, saying if you want to format a number, and you pass |
@caridy thank for that info! Finally we decided to use a very similar approach to react-locale-hot-switch using webpack and a fallback mechanism to fullfill the messages json object (i.e. "es-es" get the messages from "en", "es" and "es-es" and merge them). We have an I18nStore included as a dependency to our main component (using DependentStateMixin from NuclearMail). So each time this I18NStore emits a change the main component detects it and propagate it across all the application. One problem it is that we need to add the locale as state to each component if we want to take advantage from PureRenderMixin. I am sure there are better solutions but hope it makes sense! |
See: #162 |
I have a question about Reactntl, i need to translate my web app at runtime, every combo change i change my app language, someone know how to do it ? js lang files en { pt { index.js const messages = { const language = navigator.language.split(/[-_]/)[0]; console.log(navigator); addLocaleData([...locale_en, ...locale_pt]); ReactDOM.render(, document.getElementById('root')); serviceWorker.unregister(); Best Regards. |
Hi, I just start using react-intl to integrate i18n in my ReactJS application and have 2 questions because I don't know If I am doing thing "the react-intl way":
A)
I need to select the language in a dynamic way based on navigator.language / navigator.browserLanguage value and providing fallback mechanism.
I have been reading that, at this moment, there is no fallback mechanism implemented in react-intl ([https://github.com//issues/35][1]) and the way of doing it could be to generate complete properties files during the packaging process (webpack, gulp, etc) rather than trying to look it up at runtime.
B)
I need to import the messages file in a dynamic way based on this language variable so I though about using the dynamic import syntax provided by ecmascript 6.
Is this approach correct or is there a more standard approach?
The text was updated successfully, but these errors were encountered: