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

Translations with multiple words don't work #33

Closed
eminos opened this issue Jun 29, 2022 · 2 comments
Closed

Translations with multiple words don't work #33

eminos opened this issue Jun 29, 2022 · 2 comments

Comments

@eminos
Copy link

eminos commented Jun 29, 2022

I have a strange issue where translations that have multiple words don't load. Only single word translations load.

I'm using Vite and the new laravel-vite-plugin like this:

.use(i18nVue, {
    resolve: lang => {
        const langs = import.meta.globEager('../../lang/*.json');
        return langs[`../../lang/${lang}.json`];
    }
})

I don't like the flash of untranslated text when loading them async, so I do that instead. This part seems to work fine!

What's strange is the exported/loaded translation file looks like this:
image

Single word translations are set as a constants, and multi word translations are just strings.
This should still work, right?
But it doesn't for some reason.

// these translate fine
{{ $t('Search') }}
{{ $t('Filter') }}

// but these don't - and yes, they are available in the translation file
{{ $t('Confirm Password') }}
{{ $t('Price range') }}
{{ $t('Visit store') }} 

Any clue? Am I doing something wrong?

@eminos
Copy link
Author

eminos commented Jun 29, 2022

Hmm. I figured it out I think.
Doing this instead works:

.use(i18nVue, {
    resolve: lang => {
        const langs = import.meta.globEager('../../lang/*.json');
        return langs[`../../lang/${lang}.json`].default;
    }
})

Notice the .default

@xiCO2k
Copy link
Owner

xiCO2k commented Jun 29, 2022

Awesome, nice find. Any issue let me know

@xiCO2k xiCO2k closed this as completed Jun 29, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants