Join GitHub today
GitHub is home to over 50 million developers working together to host and review code, manage projects, and build software together.
Sign upChange the way missing translation keys are detected #563
Comments
|
I just ran across this problem as well, also with Crowdin translations. As mentioned, an option when instantiating vue-i18n to consider empty string valid or not would be a good fix for this. I would be willing to look into creating a PR for this if it will be considered for inclusion. |
|
Welcome contribution! :) |
|
Localisation services often provide option for deciding on behaviour of exporting empty translations. At least |
|
@rchl You're right. Crowdin have this option in their settings for some file types but not for JSON. We asked them what's up the same day I opened this issue and they added it. So my issue is "fixed". Nonetheless, this feature would be a nice-to-have. |
|
@WilliamDASILVA Really. So it's possible to change it so that crowdin will not export empty strings? Where exactly do I set this? |
|
@nekosaur Go to your project, then click on "Settings". On the "Export" section, ensure the "Skip untranslated strings" is checked. Hope that helps! |
|
@nekosaur Have you started work on this? If not I would like to have a go at it :) |
|
@makeupsomething Some things got in the way for me, so have at it |
|
Does anyone have a fix for this yet? it would be really useful if we could set empty strings to be considered fallback. Thanks! |
|
@ssuess This code is placed among app bootstrapping code, after // We decorate translation-retrieving functions so that empty strings
// (effectively untranslated strings) are replaced with translation keys (like undefined strings are).
Vue.prototype.$t = function (key, locale, values) {
const result = this.$i18n.t(key, locale, values);
if (result === '') {
return key;
}
return result;
};
Vue.prototype.$tc = function (key, choice, locale, values) {
const result = this.$i18n.tc(key, choice, locale, values);
if (result === '') {
return key;
}
return result;
}; |
You code is working in most cases but it has a problem when render messages that include parameter. I would like to change the code as below to fix this issue Vue.prototype.$t = function (...args) {
const result = this.$i18n.t.apply(this.$i18n, args)
if (result === '') {
return args[0]
}
return result
}
Vue.prototype.$tc = function (...args) {
const result = this.$i18n.tc.apply(this.$i18n, args)
if (result === '') {
return args[0]
}
return result
} |
|
@lbngoc you're right, my code fails when parameters passed but locale is not — I forgot about this case. Actually I think it's bad decision in the library that these 2 signatures of |
|
FYI: And also |


Hello,
Our translations are handled with Crowdin and one particularity with Crowdin is that, if a key wasn't translated yet and we sync them; Crowdin will return the key with an empty string instead of returning the file without the missing keys.
The thing is that, vue-i18n considers the empty string as an already-translated key, so it will uses it instead of fallbacking to the default version (english).
It would be great to override this default rule, so I can say that: "If my key is missing OR my key is empty, fallback to the default version".
An implementation suggestion would be a handler in the config that returns true or false if the key passed should be considered as missing?