Giter Club home page Giter Club logo

Comments (4)

caridy avatar caridy commented on May 6, 2024

@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.

AntonioAcevedo avatar AntonioAcevedo commented on May 6, 2024

@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.

ericf avatar ericf commented on May 6, 2024

See: #162

from formatjs.

fabianovalle avatar fabianovalle commented on May 6, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.