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.

Can't access non-loaded lazy locales using $t

See original GitHub issue

Hello.

I was trying to put two different languages on the same page. In my example, I’m trying to pull messages for two different languages i.e. polish and french. The idea is to get language from a browser (fr) and compare it to language from URL(pl) which will show the message about difference and choose between two of them. That message should be in those two languages that I’ve got from the browser and URL.

I tried use v-t directive with the locale attribute, but it seems to not work as I expected. Tried also $t with same effect.

After checking i18n object I had only current language messages (in this situation polish) and both strings were translated into polish only…

My nuxt-i18n config

  parsePages: false,
  locales: LOCALES,
  defaultLocale: process.env.NODE_ENV !== 'production' ? 'en' : 'en-gb',
  lazy: true,
  langDir: 'lang/',
  vueI18n: {
    fallbackLocale: 'en',
    silentFallbackWarn: true,
    formatFallbackMessages: true,
  },

Is there any possibility to use both languages on the same page?

Issue Analytics

  • State:open
  • Created 3 years ago
  • Reactions:1
  • Comments:6

github_iconTop GitHub Comments

2reactions
rchlcommented, May 28, 2020

The $t API [1] takes a locale argument so you could use that if you would have all locales loaded. But since you are lazy loading them, you can’t do that.

Interestingly, there is no way to trigger loading of additional locales right now, short of changing to a given locale. I guess it makes sense to add that. Then you would need to manually ensure that all locales you want to use are loaded before you try to get the translations for that locale.

Would that work for you? You would need to programmatically call something like await $i18n.loadLocale('fr') before using it.

[1] https://kazupon.github.io/vue-i18n/api/#vue-injected-methods

0reactions
Louvkicommented, Mar 1, 2021

Any updates on this?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Lazy-loaded modules dont get their translations when "isolate ...
So the module can access the main file translations but not theirs. When "isolate" is true the file is correctly loaded but the...
Read more >
vue-i18n lazy loading is loading all locales - Stack Overflow
I was not able to instruct webpack to package each file individually using the syntax from the documentation, but found the following ...
Read more >
Lazy Loading Locales with Angular - ANGULARarchitects
The method toGerman is bound to the shown button and uses our SimpleLoaderService to load the German locale. After that, it updates the...
Read more >
Step by step guide (v9) - react-i18next documentation
You will keep translations as separated from your code as you can - so developers and translators can work as independent as possible....
Read more >
Dynamic Import of Locales in Angular | by Michael Karén
Lazy load your locale when changing countries. “assorted-flag” by Vladislav Klapin ... The other day I read 'Using TypeScript Dynamic Imports in Angular'...
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