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.

Locale property of useI18n seems as it is not Reactive

See original GitHub issue

Hi vue-i18n authors, I am working on Vue 3 project and trying to switch locale via URL i18n.locale=to.params.lang. In the components where I am using ...useI18n() inside the return of setup() to retrievelocale , but locale property does not change dynamically as expected. Thanks!

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:13 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
yusuf-iocommented, Oct 4, 2020

Actually in my app I use object destructuring, but for purpose of clarity I used ...useI18n() in my aforementioned example. @ux-engineer Thank you for your advice.

0reactions
ux-engineercommented, Oct 4, 2020

@YusufISMAILOGLU I’d advise against using this syntax:

return {
  ...useI18n(),
};

This way you are exposing everything to the template when actually needing just one property. Instead consider using object-desctructed properties:

const { locale } = useI18n();

return {
  locale,
};

Also in some cases, you might need to wrap the returned property as ref, but I’m not yet sure when this is needed to be more specific…perhaps not helpful here:

const { locale } = useI18n();

return {
  locale: ref(locale),
};
Read more comments on GitHub >

github_iconTop Results From Across the Web

Problem to use VueI18n outside a component - Stack Overflow
To use i18n with Vue 3's composition API, but outside a component's setup() , you can access its translation API (such as the...
Read more >
Support Composition API · Issue #693 · kazupon/vue-i18n
But for i18n it seems like having to useI18n() in every component just ... @OrestHk - Since the i18n object isn't reactive, there's...
Read more >
Composition API - Vue I18n
global property: VueI18n instance to Composer instance. You are now ready to use useI18n in the component setup . The code looks like...
Read more >
The Ultimate Vue Localization Guide | Phrase
Let's refactor our LocaleSwitcher and LocalizedLink components to use the reactive locale property. src/components/l10n/LocaleSwitcher.vue.
Read more >
The Ultimate Guide to Vue Localization with Vue I18n - Medium
The nice thing about VueI18n 's locale property is that it's read/write and reactive. So if we set a new value to the...
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