question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

`i18n.global.locale` type definiton wrong

See original GitHub issue

Reporting a bug?

When I implemented a function to globally switch locale as follows: 截屏2022-05-07 下午11 31 39

The type definition for i18n.global.locale is wrong: 截屏2022-05-07 下午11 32 31

By printing out the console, I was able to see that i18n.global.locale should be a computed value

Expected behavior

TypeScript not throw error

Reproduction

Type definition problem

System Info

System:
  OS: macOS 12.3.1
  CPU: (8) x64 Intel(R) Core(TM) i5-8259U CPU @ 2.30GHz
  Memory: 171.65 MB / 16.00 GB
  Shell: 5.8 - /bin/zsh
Binaries:
  Node: 16.13.2 - ~/.nvm/versions/node/v16.13.2/bin/node
  Yarn: 1.22.10 - /usr/local/bin/yarn
  npm: 8.6.0 - ~/.nvm/versions/node/v16.13.2/bin/npm
  Watchman: 2021.10.18.00 - /usr/local/bin/watchman
Browsers:
  Brave Browser: 91.1.26.77
  Chrome: 101.0.4951.54
  Safari: 15.4

"vue": "^3.2.25",
"vue-i18n": "^9.1.10",
"@intlify/vite-plugin-vue-i18n": "^3.4.0",
"@vitejs/plugin-vue": "^2.3.1",

Screenshot

No response

Additional context

No response

Validations

Issue Analytics

  • State:open
  • Created a year ago
  • Comments:10 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
kazuponcommented, Sep 3, 2022

sorry, I’m focusing on nuxtjs/i18n for v8 alpha release. please

Type definitions in vue-i18n are really complex. I’m not a full-time OSS yet, so it may take some time until I’m starting on this issue.

1reaction
timothymctimcommented, Aug 23, 2022

To me it’s clear that this bug only occurs when useScope: 'global' in useI18n is specified. That is, with const { locale } = useI18n() I get const locale: WritableComputedRef<string>, while with const { locale } = useI18n({ useScope: 'global' }); I get const locale: WritableComputedRef<unknown>.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How would one use I18n in TS classes? #566
I've tried using the .global instance with. const i18n = createI18n({ legacy: false, locale: process.env.VUE_APP_I18N_LOCALE || 'en' ...
Read more >
Internationalization for vue 3 vite with i18n
The i18n plugin registering using app.use(i18n) make a global function $t available for all the children components :
Read more >
Composition API
You want to change the locale with setup , just get a global Composer with useI18n and change it using the locale property...
Read more >
The Ultimate Vue Localization Guide
Dive into Vue localization and learn how to plug the Vue I18n library into your app, so you can make it accessible to...
Read more >
Locale messages syntax | Vue I18n
// As Flowtype definition, Locale Messages syntax like BNF annotation type LocaleMessages = { [key: Locale]: LocaleMessageObject }; type ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found