-
-
Notifications
You must be signed in to change notification settings - Fork 350
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
i18n.global.locale
type definiton wrong
#1003
Comments
Thank you for your reporting! I seem that the i18n instance is created with The You can check the mode of an i18n instance with |
Sorry, should specify, I actually created with const i18n = createI18n<I18nOptions, [MessageSchema], 'zh-CN' | 'en-CA'>({
legacy: false,
locale: getLang(),
messages: {
'zh-CN': zhCN,
'en-CA': enCA,
},
// something vue-i18n options here ...
}); |
Hi, I was facing the same problem on vue-i18n 9.2.0-beta.31. I had a look at the type of i18n.global.locale and it's of type export const changeLocale = (i18n: I18n, locale: string) => {
if (i18n.mode === 'legacy') {
i18n.global.locale = locale;
} else if (isRef(i18n.global.locale)) {
i18n.global.locale.value = locale;
}
}; That way the type changes to Ref inside the else block. |
Hi I am facing the same issue. I'm using i18n 9.1.10 (fixed version) Here is my i18n setup const i18n = createI18n({
locale: 'fr',
legacy: false,
fallbackLocale: 'en',
globalInjection: true,
messages: messages as LocaleMessages<VueMessageType>,
}) In the same file, I try to access and modify the locale using I've checked and I'm using the composition mode (i18n.mode is Any help is appreciated |
Have the same problem with next-version. With |
To me it’s clear that this bug only occurs when |
I'm using [email protected] and having issues with |
@kazupon I believe @timothymctim has laid out the scenario quite well. Non-legacy users are having trouble getting |
sorry, I'm focusing on nuxtjs/i18n for v8 alpha release. please Type definitions in vue-i18n are really complex. |
I'm experiencing the same problem in 9.2.2 Any update on this? |
I’m currently working around this issue by exporting the result of import i18n from 'path/to/file/calling/createI18n.ts';
function myFunctionNeedingTheGlobalI18nObject() {
const { locale } = i18n.global; // or anything else you need
// rest of code
} Here, |
I was also encountering this issue:
Passing |
I also ran into this issue while trying to define types using Using the example from the docs const i18n = createI18n<[MessageSchema], 'en-US' | 'ja-JP', false>({
legacy: false,
locale: 'en-US',
messages: {
'en-US': enUS
}
}) Notice the Adding that fixed the issue for me. |
Reporting a bug?
When I implemented a function to globally switch locale as follows:
![截屏2022-05-07 下午11 31 39](https://user-images.githubusercontent.com/15679461/167280563-b0d39325-3257-464e-88f2-d97002f7b75b.png)
The type definition for
![截屏2022-05-07 下午11 32 31](https://user-images.githubusercontent.com/15679461/167280585-e5b1d0ff-83dc-4008-86b8-a9a595a9ba2e.png)
i18n.global.locale
is wrong:By printing out the console, I was able to see that
i18n.global.locale
should be a computed valueExpected behavior
TypeScript not throw error
Reproduction
Type definition problem
System Info
Screenshot
No response
Additional context
No response
Validations
The text was updated successfully, but these errors were encountered: