Nuxt.js: Internationalization with nuxt.js

Created on 8 Jan 2017  路  14Comments  路  Source: nuxt/nuxt.js

Did someone made a multi-languages app? How did you manage the internationalization? plugin or just with an async call in the data function?

This question is available on Nuxt.js community (#c87)
question

Most helpful comment

Hi @gary149

This is planned to make an example when the middleware feature will be released.

All 14 comments

Hi @gary149

This is planned to make an example when the middleware feature will be released.

Very need Nuxt.js multi-languages feature on the box 馃憤
Btw. It will have its own realization or a port of a plugin such as https://github.com/kazupon/vue-i18n

The i18n example is out: https://github.com/nuxt/nuxt.js/tree/master/examples/i18n

Demo: http://i18n.nuxtjs.org/

As seen in #234, vue-i18n is not ready for the SSR, but with the nuxt example, anybody can create its own plugin for nuxt.js :)

@Atinux demo link is broken (502 An error occured with your deployment).

@koddr it's fixed thank you for spotting it

Hello, is it right if I want to localize with html tags do this: div(v-html='$t("home.title")') ?

Try to use a computed property instead @demyan1411

Can you please show how computed properties can help me.

And after npm run generate I haven't got html http://prnt.sc/espzpo
how can i get it?

Actually i18n example does not work with nuxt generate @demyan1411

Maybe its possible to make use of the new https://github.com/kazupon/vue-i18n/releases/tag/v6.0.0 It supports now SSR and might be a good fit into the NUXT ecosystem?

I will try it soon @dohomi

@koddr
in i18n example, the language code is derived from local storage. Let's say my users have a drop-down to choose a language (note- I don't want to append anything in url like?locale=fr)
when language chosen, either i will save in LocalStorage or send to the server (PHP, saved there in session). But, I don't want 2nd option bcz i am dealing with 3rd party api's. so no own server there for sessions.

Now if my data is saved in LS, then how I will replace locale: store.state.locale, tolocale: localStorage.getItem('locale').

While middleware executes, there is no client right ?
so we can't access LS. then what is the alternate.
Please suggest.

@koddr i got the same problem , i want get locale from localstorage when reload page and fixed like this

export default ({ app, store }) => {
    // Set i18n instance on app
    // This way we can use it in middleware and pages asyncData/fetch
    let locale=''
    if(process.browser){
        locale=localStorage.tokenup_lang||navigator.language
    }
    app.i18n = new VueI18n({
        locale: locale || store.state.locale,
        fallbackLocale: 'zh',
        messages: {
            zh,
            en
        }
    })

    app.i18n.path = (link) => {
        if (app.i18n.locale === app.i18n.fallbackLocale) {
            return `/${link}`
        }

        return `/${app.i18n.locale}/${link}`
    }
}

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

uptownhr picture uptownhr  路  3Comments

jaredreich picture jaredreich  路  3Comments

VincentLoy picture VincentLoy  路  3Comments

vadimsg picture vadimsg  路  3Comments

danieloprado picture danieloprado  路  3Comments