Changing locale doesn't work for js files
See original GitHub issueVersions: “vue”: “^2.6.11”, “vue-i18n”: “^8.17.3”
I added i18n in external js file and exported const from that file.
import i18n from '@/plugins/i18n';
export const menu = [
{
title: i18n.t('navigation.schedule'),
children: [
{
title: i18n.t('navigation.planning'),
path: '/checkpoint/control_calendar'
},
{
title: i18n.t('navigation.calendar'),
path: '/checkpoint/control_summary_calendar'
}
]
},
]
Later I imported data in SFC. But When I change locale, data from that js file doesn’t change.
Issue Analytics
- State:
- Created 3 years ago
- Comments:12 (3 by maintainers)
Top Results From Across the Web
How do I change the language of moment.js? - Stack Overflow
2. This should be the correct answer. Just link the desired local with <script src="/bower_components/moment/locale/de. · 8. "There will be no need anymore...
Read more >moment.locale(String) doesn't change locale globally #1875
I'm trying to change locale globally, but I can't. ... is to load the locale files synchronously before the html has loaded which...
Read more >Changing locale globally - momentjs.com
By default, Moment.js comes with English (United States) locale strings. If you need other locales, you can load them into Moment.js for later...
Read more >Locale is unable to rebuild lost Javascript translation files
I've tried the Locale Rebuild JS Module on Drupal 6.9. I run it a couple of times but it seems it didn't work...
Read more >The Ultimate Guide to JavaScript Localization | Phrase
Now let's rework our script so that we load the JSON files asynchronously when needed. /js/scripts.js. // The locale our app first shows....
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Sorry, for the late reply to your response. 🙇
Unfortunately, the way to use it, in this case, is not to let
i18n.t
evaluated messages change reactively when you change the locale. because i18n instances use the mechanism of Vue’s reactive system. Vue’s reactive system (especially Vue 2.x, but Vue 3, which are designed to work outside Vue components) is generally intended to be used within Vue components.The workaround is to define a function that is passed an
i18n
instance, and use the evaluated data in computed prop, as in the code I committed at the following URL. https://github.com/kazupon/vue-i18n-v8-repro-1045/commit/640edbdaa829ac2a50dc6ad02f3707db40544492Computed prop works with Vue’s reactive system.
i18n.t
evaluated in this function will be tracked in the dependency of Vue’s reactive system.Thanks.
@kazupon thank you for your help