-
-
Notifications
You must be signed in to change notification settings - Fork 334
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
te function returns false although fallback exists #1765
Comments
Thank you for your feeback! As the reason provide The t function has a fallback cost. |
I think we agree that there are different UseCases. Our own fallback translationExists function looks like this now:
But it raises an error for missing transations in our test cases. We could also create our own fallback schema for te but it seems weird recreating the logik of t. What are your thoughts on this? |
Would something like this be what you're looking for? function hasTranslationOrFallback(i18n, key) {
return i18n.te(key) || i18n.te(key, i18n.fallbackLocale.value)
} |
As far as I know you can define multiple fallback levels (de-DE-BR -> de-AT -> de -> en). So it would need to be iterative. |
Thinking about it. I actually don't care about the te function. Because in my eyes it is more efficient to directly try to translate and check if I got the key returned than first checking if it exists and then translate it (-> 2x resolving). So I silenced the warnings I get in the jest tests. If you agree we can close this ticket |
Reporting a bug?
te function returns false for de-AT locale although t function is able to fallback to language de.
Expected behavior
I think it is problematic that the behaviour of t and te is different.
I propose:
if you provide no locale to te function it should be true if t function resolves to a fallback (eg. de-AT -> de)
if you provide a locale it should only return true if the message exists in the given locale ignoring fallbacks
Reproduction
https://stackblitz.com/edit/vitejs-vite-tr2dcd?file=src%2FApp.vue
System Info
Screenshot
Additional context
No response
Validations
The text was updated successfully, but these errors were encountered: