Comments (4)
@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 locales=['en-FO', 'en']
it will fallback to en
since en-FO
is not available. But falling back to a message is a completely different thing, because resolving the right message is in the user-land, and locales
is only used by the primitive operations (numbers and dates), so you're on your own for the messages. There are few issues (closed) in this repo where we give some recommendations, you should probably look them up.
from formatjs.
@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!
from formatjs.
See: #162
from formatjs.
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
{
"register.client": "Register Client",
"register.name" : "Name",
"register.address" : "Address"
}
pt
{
"register.client": "Registrar Cliente",
"register.name" : "Nome",
"register.address" : "Endereço"
}
index.js
const messages = {
'pt': messages_pt,
'en': messages_en
};
const language = navigator.language.split(/[-_]/)[0];
console.log(navigator);
addLocaleData([...locale_en, ...locale_pt]);
ReactDOM.render(, document.getElementById('root'));
serviceWorker.unregister();
Best Regards.
from formatjs.
Related Issues (20)
- @formatjs/intl-numberformat @ 8.9.0 -> 8.10.0 breaks Chrome 104 HOT 1
- cli-lib: onMsgExtracted never gets called HOT 1
- Update translation of 'last year' for Swedish locale HOT 1
- @formatjs/cli-lib is not an ESM module HOT 1
- formatMessage with ICU behave different then formatNumber HOT 2
- [@formatjs/intl Error MISSING_DATA] should be a warning not an error HOT 3
- [@formatjs/intl-durationformat] package.json deprecation warning HOT 2
- @formatjs/intl-messageformat, 10.5.0: Plural rules aren't applied correctly HOT 2
- @formatjs/intl-numberformat/polyfill: roundingIncrement seems to be a no-op HOT 3
- [docs] Rich Text Formatting example doesn't work HOT 2
- Polyfill.io has been sold to a weird Chinese company and should no longer be recommended HOT 1
- chore: update tzdata to 2024a
- INVALID_TAG when parsing regular HTML tag with attribute HOT 1
- Can't catch error HOT 1
- Feature request: allow units greater than `day` in `FormattedRelativeTime` with `updateIntervalInSeconds` to be picked HOT 2
- It's incredibly slow on lower end Android devices HOT 2
- Intl.Segmenter: isWordLike does not match Node.js and browsers HOT 2
- @formatjs/intl-locale/polyfill-force TypeError: Error uninitialized locale at Locale2.getWeekInfo HOT 3
- .formatMessage is not working when provided messages has object with `type: 1` HOT 8
- Extract does not work on vue template since vue 3.4.0 HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from formatjs.