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 json files after generating static files #31

Closed
elpeyotl opened this issue Feb 23, 2018 · 9 comments
Closed

Lazy Load json files after generating static files #31

elpeyotl opened this issue Feb 23, 2018 · 9 comments
Labels

Comments

@elpeyotl
Copy link

elpeyotl commented Feb 23, 2018

Hello!

I was trying around a bit if I can use this plugin for my next project. It is awsome by the way. Could set up routing and translation in about 40 minutes! yay!

But I found one issue. When using "npm run generate" to generate static files - the first page load does not show the translations! If I change the language it starts working. It seems that on inital load the json language file is not working. Does anybody have any clue how i can solve that?

I made a git repo here https://github.com/elpeyotl/nuxt-translation. attached a screenshot of the behaviour.

Well it is only not working when generating static pages. In npn run dev it is working.

nuxt

my config
module.exports = { modules: [ ['nuxt-i18n', { locales: [ { code: 'en', iso: 'en-US', name: 'English', langFile: 'en-US.json' }, { code: 'fr', iso: 'fr-FR', name: 'Français', langFile: 'fr-FR.json' }, { code: 'de', iso: 'de-DE', name: 'Deutsch', langFile: 'de-DE.json' } ], loadLanguagesAsync: true, langDir: 'lang/', defaultLocale: 'en', // ... }] ] }

This bug report is available on Nuxt.js community (#c24)
@elpeyotl
Copy link
Author

Even if I run "npm run build" and then "npm run start" i see the same behaviour.

@elpeyotl
Copy link
Author

If load the files not asynchrously it works:

    vueI18n: {
      messages: {
       fr: require('./lang/fr-FR.json'),
      en: require('./lang/en-US.json'),
      de: require('./lang/de-DE.json')
    },

@mahmoudmy
Copy link

mahmoudmy commented Feb 23, 2018

I think it's similar to my problem discussing in #23 .

@elpeyotl
Copy link
Author

@mahmoudmy I downloaded your repo and was running it. Could find any issue? How to you build it? I run it with npm run dev. and it was showing first page in english. when i click on house it changed to arabic.

@mahmoudmy
Copy link

Thanks @elpeyotl . The first page wasn't in English, it just shows the message keys (CAPITAL LETTERS) and this is the bug!

@elpeyotl
Copy link
Author

@mahmoudmy

If I change your config file like this it works. But it not asynchrous anymore.

            module.exports = {
        locales: [{
            code: 'fa',
            iso: 'fa-IR',
            name: 'فارسی',
            langFile: 'fa.js'
        }, {
            code: 'en',
            iso: 'en-US',
            name: 'English',
            langFile: 'en.js'
        }],
        defaultLocale: 'fa',
        vueI18n: {
            fallbackLocale: 'fa',
            silentTranslationWarn: true,
            messages: {
            fa: require('../locales/fa.js'),
            en: require('../locales/en.js'),
            },
        },
        }

Probably you can use that as a workaround? Dont know why on inital load the language is not loaded. I have exact the same issue.

@TheAlexLichter
Copy link
Contributor

TheAlexLichter commented Feb 25, 2018

Same problem here. It works in dev mode, but not in production (npm run build && npm start)

@paulgv
Copy link
Collaborator

paulgv commented Feb 25, 2018

Hi guys, sorry for this frustrating issue. Hopefully it's fixed in v2.3.4.
@elpeyotl thanks for the repo, I tested it with the new version and it looks okay!

@TheAlexLichter
Copy link
Contributor

Looks like the bug is fixed. Thank you, Paul! But there is another (rare) edge case. Will open up a new issue for it in a second

@paulgv paulgv closed this as completed Feb 26, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants