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.

Implicit fallback locale rules and lazy loading

See original GitHub issue

If you are in universal mode, and lazy loading locales, you can have problems with fallback locale. I was wondering how to deal with it? Should I merge manually the locale files for the fallback languages or should it be handled by the plugin?

For exemple: en.json

{
  title: "My title",
  description: "Lorem Ipsum"
}

en-US.json

{
  title: "My awesome title"
}

I want to modify only some words in a fallback language and use the base language for the rest. The vue-i18n merge strategy is perfect for that. But, since I lazy load locales, I have something like this:

lang/
  lazy/
    en.js
    en-US.js
  translations/
    en.json
    en-US.json

en.js

import en from '../translation/en.json'
export default en

en-US.js

import enUS from '../translation/en-US.json'
export default enUS

So if I navigate through the en version, en.json is loaded and then I switch, en-US.json is loaded and everything works as expected. Problem is when I refresh the en-US version. What is the strategy to adopt here?

Thanks

Issue Analytics

  • State:open
  • Created 2 years ago
  • Comments:10

github_iconTop GitHub Comments

1reaction
rchlcommented, May 21, 2021

It works if you define a fallback.

  i18n: {
    defaultLocale: "en",
    locales: [
      { code: "en", iso: "en-EN", file: "en.js" },
      { code: "en-US", iso: "en-US", file: "en-US.js" }
    ],
    langDir: "lang/lazy/",
    lazy: true,
    seo: false,
    vueI18n: {
      fallbackLocale: {
        "en-US": ["en"]
      }
    }
  }

https://codesandbox.io/s/suspicious-leavitt-62b68?file=/nuxt.config.js

0reactions
stale[bot]commented, Jul 21, 2021

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Unable to find a way to lazy load messages per component ...
Hi,. Currently my messages are stored in JSON files in src/locales folder. I have one JSON for each component/language (e.g. MyLocalizedComponent.vue ...
Read more >
Domain model purity and lazy loading
Lazy loading is a design pattern where you defer initialization of an object until the time when it's needed. The purpose of this...
Read more >
Disable Lazy Loading in Entity Framework Core - Stack Overflow
There seems to be some confusion about what lazy loading off means. When the lazy loading is off, then EF Core won't load...
Read more >
Rails Internationalization (I18n) API - Ruby on Rails Guides
The backend lazy-loads these translations when a translation is looked up for the first time. This backend can be swapped with something else...
Read more >
Lazy Loading - Spartacus Documentation - SAP
Lazy loading, also known as code splitting, lets you divide your JavaScript code into multiple chunks. The result is that you do not...
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