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.

Reload of JSON language files

See original GitHub issue

I store translations in JSON files and configure nuxt-i18n like this:

    ['nuxt-i18n', {
      locales: [locale.language],
      vueI18n: {
        messages: {
          [locale.code]: require('./locales/' + locale.code + '.json')
        }
      },
      defaultLocale: locale.code
    }]

My use case is that I use nuxt generate to generate separate sites for all languages that are served from different domains, so I only specify one language per build.

The problem I’m facing is that changes to ./locales/.json are only visible in the app after I restart the dev server.

Having

    watch: [
      '~/locales'
    ],

in nuxt.config.js does cause the page to reload when I save locales files, but the changes are not visible.

Any thoughs on this?

<div align="right">This question is available on Nuxt.js community (#c28)</div>

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:7

github_iconTop GitHub Comments

18reactions
nghiepdevcommented, Jun 15, 2018

using lazy-load-translations to reload the translations.

 [ 'nuxt-i18n',
      {
        locales: [
          {
            code: 'en',
            name: 'English',
            file: 'en-US.js',
          },
        ],
        lazy: true,
        langDir: 'locales/',
      }
]
// locales/en-US.js
export default require('./en.json')
1reaction
katafractaricommented, Apr 20, 2018

I’m currently using nodemon for this purpouse. Of course a full restart of the dev server is still needed to reload the translations.

package.json

{
  "scripts": {
    "dev": "nodemon --watch locales --watch config --exec \"cross-env NODE_ENV=development LOCALE=en nuxt\""
  }
}
Read more comments on GitHub >

github_iconTop Results From Across the Web

Reload of JSON language files · Issue #36 · nuxt-modules/i18n
I store translations in JSON files and configure nuxt-i18n like this: ['nuxt-i18n', { locales: [locale.language], vueI18n: { messages: ...
Read more >
How to refresh a page whenever my json data file changes
Create a timer, fetch the json file every X milliseconds. If the json contents has changed since the last fetch, reload the page....
Read more >
How to translate JSON files: guide to l10n & i18n with examples
In this article you'll learn about JSON localization, internationalization, working with JSON, and how to translate JSON files.
Read more >
json file doesn't seem to reload - GameMaker Community
I'm using this locale system I found on youtube to change languages in my game. Until recently it's been working flawlessly - but...
Read more >
Paste JSON as Code (Refresh) - Visual Studio Marketplace
Extension for Visual Studio Code - Copy JSON, paste as Go, TypeScript, C#, C++ and more.
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