Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Lazy-load translations #23

Closed
paulgv opened this issue Feb 17, 2018 · 11 comments
Closed

Lazy-load translations #23

paulgv opened this issue Feb 17, 2018 · 11 comments

Comments

@paulgv
Copy link
Collaborator

paulgv commented Feb 17, 2018

Lazy-loading translations seems like an important feature to some of us.
An initial implementation is available in version 2.3.0 which is tagged as a pre-release. I'd love to have some feedback from you guys if you'd be willing to give it a try.
To get the prerelease:

yarn add nuxt-i18n@2.3.0-0

Have a look at the doc for usage: https://github.com/nuxt-community/nuxt-i18n#lazy-load-translations

Thanks!

#20
#7

This feature request is available on Nuxt.js community (#c42)
@mahmoudmy
Copy link

I tried the new release.
Lazy loading is OK but after loading server-side-rendered pages, all of the translations disappear and message keys appear in a flick. (In the Page source there are the correct translations but in a half a second they replace with message keys!)

@paulgv
Copy link
Collaborator Author

paulgv commented Feb 19, 2018

@mahmoudmy that's weird 😮
What does you nuxt.config.js look like?

@mahmoudmy
Copy link

Here is my config:

{
  locales: [{
    code: 'fa',
    iso: 'fa-IR',
    name: 'فارسی'
  }, {
    code: 'en',
    iso: 'en-US',
    name: 'English'
  }],
  defaultLocale: 'fa',
  vueI18n: {
    fallbackLocale: 'fa',
    silentTranslationWarn: true
  },
  loadLanguagesAsync: true,
  langDir: 'locales/',
  langFiles: {
    fa: 'fa.js',
    en: 'en.js'
  }
}

@paulgv
Copy link
Collaborator Author

paulgv commented Feb 19, 2018

Thanks @mahmoudmy ! I tried your config in my example project and it seems to be working okay. Any way you could provide a repo with the issue so I can reproduce?

@mahmoudmy
Copy link

Thanks @paulgv , I created a simple repo resulting the same problem:
https://github.com/mahmoudmy/nuxt-i18n-test

@paulgv
Copy link
Collaborator Author

paulgv commented Feb 20, 2018

Thanks! I'm not sure what's going on there, I need to give it a closer look. I released another version where langFiles option has been dropped in favor of individual langFile options in the locales array, make sure you update your config accordingly if you start using v2.3.0.
I'll do more tests to try and understand the bug you've got.

@paulgv
Copy link
Collaborator Author

paulgv commented Feb 22, 2018

@mahmoudmy did you find a solution to your problem by any chance? I've been messing around with your repo and couldn't make it work properly, even after stripping it down to the bare minimum. But using a similar setup in another Nuxt project works fine so this feels pretty strange...

@mahmoudmy
Copy link

I also tried the new version (2.3.0), but the problem still exists!

@mahmoudmy
Copy link

@paulgv
I deployed the sample repo to heroku, you can see the strange behavior on every page load (refresh):
https://nuxt-18n-test.herokuapp.com/

@paulgv
Copy link
Collaborator Author

paulgv commented Feb 25, 2018

@mahmoudmy apparently, nuxt-i18n's plugin was missing a simple return... 😅
Just pushed v2.3.4 which should fix your problem :)

@mahmoudmy
Copy link

Thanks @paulgv , You made my day ;)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants