Giter Club home page Giter Club logo

Comments (3)

joshswan avatar joshswan commented on August 24, 2024

There isn't currently a locale-based fallback mechanism for formatMessage. That's something that I could potentially explore adding or accept a PR for, though the mechanism for deciding the fallback locale would need to figured out (not everyone will want English).

That said, there are a couple of workarounds that may or may not help:

  • Use the defaultMessage option/prop and set it to the English translation. This doesn't allow formatting/replacements currently (it's just treated as a string), but it would definitely hide the message key.
  • Add the English translations to your German translations object so that all keys are present in the German translations, even if some are in English. You could do this manually or potentially just write a quick function that copies any missing keys from the English object to the German one and do this before even passing the messages to GlobalizeProvider.

from react-native-globalize.

sakarisson avatar sakarisson commented on August 24, 2024

Thanks for your response

(not everyone will want English).

Definitely. I used English as an example, but in practice the fallback locale would probably be decided from a prop.

Add the English translations to your German translations object so that all keys are present in the German translations, even if some are in English. You could do this manually or potentially just write a quick function that copies any missing keys from the English object to the German one and do this before even passing the messages to GlobalizeProvider.

Yeah, this is basically the workaround that I opted for. It has a bit more steps than my example, but essentially:

  loadMessages({
    de: {
      ...englishMessages,
      ...germanMessages,
    },
  });

For now I'm happy with this solution, as it seems to cover my needs entirely 👍

from react-native-globalize.

joshswan avatar joshswan commented on August 24, 2024

Sounds good, that does seem like a decent workaround for now.

Per another issue that came up earlier today, a defaultLocale option/prop is now available. Currently it's used when the specified locale isn't available/loaded, but it could also be used in this situation. The problem is that it'd basically require initializing two instances of all the formatters (one with the specified locale/messages and one with the fallback locale/messages). Not sure if that's the best idea so I'll try to give this issue some thought.

from react-native-globalize.

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.