Comments (3)
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.
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.
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)
- Support for getting the currency symbol directly. HOT 6
- Is there a way this library can detect the locale automatically? HOT 2
- Undefinided is not an object <FormattedCurrency> HOT 1
- gulp cldr error HOT 1
- pt-BR is missing HOT 1
- Typescript support HOT 4
- postinstall step failing on CircleCI HOT 2
- typing of `useGlobalize().formatMessage` HOT 1
- [Proposal] useGlobalize generic type HOT 7
- getCurrencySymbol() with GlobalizeProvider throwing TypeError HOT 4
- How to use useGlobalize with class component HOT 4
- formatCurrency always return Error value must be anumber HOT 5
- Fallback locale does not fork HOT 4
- Customizing Formatted Currency Component HOT 4
- [RNGlobalize] Error processing message welcome HOT 1
- Translate functions strings HOT 1
- Access functions outside components HOT 2
- On demand loading of locales in a web app HOT 2
- Unable to resolve "../../../../../globalize" HOT 2
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 react-native-globalize.