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.

Changing locale doesn't work for js files

See original GitHub issue

Versions: “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:closed
  • Created 3 years ago
  • Comments:12 (3 by maintainers)

github_iconTop GitHub Comments

2reactions
kazuponcommented, May 22, 2021

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/640edbdaa829ac2a50dc6ad02f3707db40544492

Computed 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.

0reactions
DariaYereminacommented, May 24, 2021

@kazupon thank you for your help

Read more comments on GitHub >

github_iconTop 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 >

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