Issue with findBestAvailableLanguage
See original GitHub issueBug
findBestAvailableLanguage
is not falling to fallback language i.e. English when I change the language to Spanish.
Steps To Reproduce
Just like the example app, I’m using three languages English, French, and Arabic.
- When I change the language to French it shows the French Text
- Now, when I change the language to Spanish which is not supported and should fallback to English as a fallback, it remains French.
Environment info
"i18n-js": "^3.3.0",
"lodash.memoize": "^4.1.2",
"react": "16.8.3",
"react-native": "0.59.9",
"react-native-localize": "^1.1.3"
Describe what you expected to happen:
- When I change the language to Spanish it should fallback to English language
Reproducible sample code
Find the repo here
Issue Analytics
- State:
- Created 4 years ago
- Comments:9 (5 by maintainers)
Top Results From Across the Web
Issue with findBestAvailableLanguage #57 - GitHub
Bug findBestAvailableLanguage is not falling to fallback language i.e. English when I change the language to Spanish.
Read more >How to use the react-native-localize ... - Snyk
To help you get started, we've selected a few react-native-localize.findBestAvailableLanguage examples, based on popular ways it is used in public projects.
Read more >Missing translation problem with react-native-localize even ...
I think in homescreen during translating one has to import the translate function and use {translate('home')} instead of i18n.t() in ...
Read more >react-native-localize - npm
findBestAvailableLanguage() Returns the best language tag possible and its reading direction ( ⚠️ it respects the user preferred languages list ...
Read more >Discussion on: Creating a Multi-Language App in React Native
Replies for: Hello, I have problem with rewrite your code using Typescript, ... findBestAvailableLanguage(Object.keys(translationGetters)) ...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
@vikrantnegi Thanks for the repo, it helps a lot! I just give it a try, and it worked as planned on my device (android 9). Which OS / version do you target?
Also, please note that the goal of
findBestAvailableLanguage
is to returns the best available translation here.Given the following configs and English, French, and Arabic available translations:
👉 It will returns French, because Spanish translation isn’t available, but your user actually prefer French over English.
👉 It will returns English because it’s the first available translation in the list.
👉 It will returns
undefined
(so the retained value will be your fallback), because none of the user preferred languages are availables in your translations.If you only want to check the first language in the list, a solution could be to use:
But I will not recommand it, it’s not how iOS and Android pick native app translations.
@vikrantnegi That’s a good idea. I updated the README to add a warning about it: https://github.com/react-native-community/react-native-localize/tree/1.1.4#findbestavailablelanguage