-
-
Notifications
You must be signed in to change notification settings - Fork 861
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
TypeError: Cannot read property '$i18n' of undefined #259
Comments
@kazupon I think there is no need to bind /*
Monkey-patches vue-i18n's pluralization support. The original pluralization
uses "|" (pipe) character to separate singular and plural translations.
This is not robust enough; we explicitly define "zero", "one" and "other" translations for pluralization.
*/
// TypeError: Cannot read property '_t' of undefined reported!!!
import * as mappings from '../localization/mappings';
export function patchPluralization(vue) {
if (typeof vue.prototype.$t === 'function') {
// cannot override $tc because it is readonly by the declear in vue-i18n
vue.prototype.$tc2 = function (key, count, values) {
const translate = vue.prototype.$t;
const mapping = mappings[key];
if (typeof mapping === 'object') {
if (count === 1 && mapping.one) {
return translate.call(this, `${key}.one`, values);
} else if (count === 0 && mapping.zero) {
return translate.call(this, `${key}.zero`, values);
} else {
return translate.call(this, `${key}.other`, values);
}
} else {
return translate.call(this, key, values);
}
};
}
} So is there any possible to make the implemention back to the old way. And, I think there is no necessary to guarantee |
kazupon#260 was referenced twice, but this is fixing kazupon#259 and reverting kazupon#260
Problems still exist. |
Same problem here with Nuxt on 8.8.0 |
it's very annoying, especially in render functions. I have to write const $t = key => this.$t(key);
// or
const $t = this.$t.bind(this); instead of const { $t, /* necessary props and data */ } = this; |
it's 2020 and still can't const { $t } = this;
// or
const callback = $t => $t('key')
callback(this.$t) all other libraries I use work this way ( |
same for me |
1 similar comment
same for me |
still does not work |
+1 |
Still not working for me |
Still not working in 2021 |
Have you found a solution? |
vue & vue-i18n version
ex: ^2.5.3,^7.3.2
Reproduction Link
Steps to reproduce
What is Expected?
What is actually happening?
This Not equal to component instance
The text was updated successfully, but these errors were encountered: