-
Notifications
You must be signed in to change notification settings - Fork 55
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
How do I check if a given message has a translation available? #22
Comments
Hi @Eiskis, I understand your use case, but I am not sure if providing a message exists function is the best way to go about this. Especially edge cases with variable replacements and pluralization might be hard to get right as well. Maybe another way to go about this would be to have the option to provide a default translation for a key (as second argument) computed: {
pageTitle: function () {
var messageKey = 'pageTitles.' + this.$route.name;
return 'My App' + this.$t(key, '');
}
} |
I added the function $i18n.keyExists to the plugin in version 1.3.7. Might come in handy for other use cases as well. I will also think a little more about the option to provide a default translation key. |
Thanks for the quick response and quick fix! I'll use I like the default translation approach a lot actually, cuts down on the boilerplate and provides a good pattern to the user that can also be documented easily. Basically I don't think rendering keys makes sense in production very often (if ever?), but now they serve as default translations which the user has no control over. This would be really useful, other localisation solutions probably have something similar. |
Our initial idea was, that the key itself would be the default translation. This way you would not have to think about keys for translations strings but just use the translation string directly. However, this proved to be not working so well if using multiple locales and changing the translations later on. Therefore the default option would probably make more sense. |
That's exactly my experience as well. Having douple-purpose keys like that is tricky because then those keys will be in constant flux and the default translations will have to be synced across all localisation files, and thus might be duplicated who knows how man times. It's better to separate those concerns. |
It seems that there is no way to check if a given translation message exists. I can use
$i18n.exists
to check if a local exists, but that's it.I'd like to be able to perform the same checks that the plugin does when deciding what to render (for example when to fall back to the key), so I can decide to not render anything in any given situation. For example, if there is no translation for the title of the current page, I'd rather just render the app title than the untranslated key as the page title. So something like the following:
Is this possible currently?
The text was updated successfully, but these errors were encountered: