Comments (18)
I don't understand why you may need this?
Maybe try: const translation = i18next.exists('ns1:key1') ? t('ns1:key1') : t('ns2:key1')
from i18next-gitbook.
I'm using fallback for both, namespaces and language. So in case an EN translation is not found. I don't want it to switch to a DE translation. Instead, find an EN translation from another namespace.
Wouldn't t('ns1:key1') return a DE translation from namespace 1?
from i18next-gitbook.
if there is a de translation yes
But if you pass in the lng option in the exists call I think it could work.
But honestly I don't get why you do this at all. š¤·āāļø
from i18next-gitbook.
Honestly, Iām not a fan of the namespace fallback.
What is your use case?
from i18next-gitbook.
I use some language fallback as well as some namespace language. And the translation by default. check the en translation from common namespace, if it's not found, it switch to another language, de from common namespace. And I don't want that.
I want to check en in other namespaces( like custom) and only if it didn't find it en in other namespace. Only then pick other language (de) from common namespace.
from i18next-gitbook.
the question is. why you need that. why you have a key not in common en but in common de?
from i18next-gitbook.
why you want the key to fallback to the other namespace in en but not for de
from i18next-gitbook.
Because the user expects an en translation. So first I would check the en translations only than switch to another one.
from i18next-gitbook.
than again. why is the key not in common en?
from i18next-gitbook.
Maybe misspelled or was not added.
from i18next-gitbook.
so you just lucky search around in other namespaces and hope to find that key some where else?
thats not really a use case that is missing translation management.
a use case would be something like a generic error msg. or something similar.
from i18next-gitbook.
Yea, but I was hoping that the translation order can be configured.
from i18next-gitbook.
PR welcome
from i18next-gitbook.
Hi, I was just browsing i18next, since we just started using it for our app and we have a use case, which would be good if we can accomplish something similar to original request.
Use case is that we have general app translations (all the translations possible) and specific translations (only translations needed) per user company type. So, we should be looking for the translation in order like this:
en-custom
en-common
de-custom
de-common
Or maybe it is ok that this be accomplished by testing if the key exists in a given namespace as adrai suggested? Disadvantage is as I see it that then we need to test it with each key.
from i18next-gitbook.
There's also the possibility to use custom language.
i.e. de-x-custom which fallbacks to de and then en
from i18next-gitbook.
It would be nice to have this feature.
Honestly, Iām not a fan of the namespace fallback.
What is your use case?
For example in our use case, we have modules with custom glossaries to reword concepts inside that module, and we store those keys as custom namespaces. Admins can modify these glosaries per language and we have a set of common keys per language because it's optional to do. So whenever you access this module, we would like to have yourLang-custom || yourLang-common before defaulting to the default language, because the rewording of the concept is only for that specific language.
from i18next-gitbook.
https://www.i18next.com/how-to/backend-fallback
from i18next-gitbook.
Just for the record, we ended up implementing our own t function in a custom HOC that uses i18next t from useTranslation
in a certain way. We use it first but overriding the opts with fallbackLng as empty [] and a special defaultValue. If the translation obtained is that special value (or we can use i18next exists
), we assume we have gone through all namespaces in that language and there is no translation, so then we just use i18next t normally without touching the opts so the fallbackLng set in the config is picked up.
Not the prettiest because I guess in the worst case scenario you are "double" translating, but it's working for our use case and we couldn't find a different approach at that moment.
from i18next-gitbook.
Related Issues (20)
- Migration guide for up to v19 HOT 4
- Extended example in "Getting Started" uses deprecated XHR backend HOT 1
- Need help to "Plurals" for muti-language support HOT 4
- Django-i18next is not related to i18next HOT 2
- Missing Keys when target="_blank" HOT 4
- loading translate not working a server side HOT 1
- Improve docs on nesting/multiple counts
- Getting started i18next.init() too complicated for beginners HOT 6
- copy paste issue in docs HOT 1
- Documentation contradicts itself concerning support of json format HOT 3
- "Supported frameworks" needs cleanup HOT 1
- Fallback parsing HOT 1
- How to use Interpolation in html attributes tag HOT 7
- Language change can be reflected to URL route? HOT 6
- node_modules/react-i18next/ts4.1/index.d.ts(259,35): error TS2344: Type 'undefined' does not satisfy the constraint 'KeyPrefix<N>'.
- Setting default language to 'dev' HOT 3
- 404 and Broken link! HOT 1
- Intellisense works only with TypeScript v5, while in documentation it's just recommendation to use v5 HOT 2
- Add dark mode? HOT 2
- Running documentation preview on local machine 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 i18next-gitbook.