Skip to content

Calling "loadLanguageAsync" on already loaded lang causes Vue App not get rendered #206

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

Open
RedLighttt opened this issue Mar 25, 2025 · 1 comment

Comments

@RedLighttt
Copy link

Hey,
i am working on a bilingual project that will support both German and English, with German as default lang.

The default lang gets definied as html "lang" property in "app.blade.php".
There is a ‘locale’ parameter in the ‘User’ model so that each user can individually define their language. This parameter is made available via Inertia Shared Data. As soon as a user has defined the same language as the default language, the entire Vue app is no longer rendered. To do this, the ‘onMounted’ hook is used to call the ‘loadLanguageAsync’ function with the locale from the shared data.

The error can be reproduced:

onMounted(() => {
    loadLanguageAsync('de')    
});

The result is a blank page, but no errors are displayed in the console.

A workaround is to check beforehand whether the language is already loaded:

onMounted(() => {
    if (!isLoaded('de')) {
        loadLanguageAsync('de');
    } 
})

app.js:

.use(i18nVue, {
    resolve: async lang => {
        const langs = import.meta.glob('../../lang/*.json')
        return await langs[`../../lang/php_${lang}.json`]()
    },
    onLoad: () => {
        // return early if app is mounted already
        if(el && el.__vue_app__){
            return;
        }
  
        app.mount(el); // Mounted here so translations are loaded before vue.
    }
})

Vue: v3.5.13
InertiaJS: v2.0.5
laravel-vue-i18n: v2.7.8

Is the ‘onMounted’ hook not the right way to change the user-defined language?

I would be very grateful for any help.
Kind regards!

@xiCO2k
Copy link
Owner

xiCO2k commented May 10, 2025

Hey Thanks for the report, can you create a repo with that issue?

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