Activities

golubvladimir

golubvladimir posted a new question

nuxt-i18n •

Error [vuex] duplicate namespace lang/ for the namespaced module lang ?

I settings nuxt-i18n ?

    vuex: {
      moduleName: 'lang',
      syncLocale: true
    },

I have error: [vuex] duplicate namespace lang/ for the namespaced module lang

My lang module:

const store = () => ({
  locale: 'en' // default lang
});

export const mutations = {
  setLocale: (state, locale) => {return state.locale = locale},
};

export const getters = {
  locale: state => state.locale,
};
golubvladimir

golubvladimir posted a new question

nuxt-i18n •

Bug: Don't call function onLanguageSwitched on changle local with no_prefix stratege ?

I have component

<template>
  <div class="locale-changer">
    <div class="locale-changer">
      <select v-model="$i18n.locale">
        <option v-for="(lang, i) in langs" :key="`Lang${i}`" :value="lang">{{ lang }}</option>
      </select>
    </div>
    <p>{{ $t('login.login_msg') }}</p>

  </div>
</template>

<script>
    import Cookies from 'js-cookie';

    export default {
        name: "changelang",
        data: () => ({
          langs: ['en', 'ru']
        }),
        mounted() {
          //this.$i18n.locale = 'en';
          //console.log(this.$i18n.locale);
          console.log(this.$i18n);

          Cookies.set('i18n_redirected', 'en');
        },
    }
</script>

My plugin

export default function ({app, store, req}) {
  app.i18n.onLanguageSwitched = (oldLocale, newLocale) => {
    console.log(oldLocale);
    console.log(newLocale);
  }
}

nuxt-i18n config

  i18n: {
    defaultLocale: 'en',
    strategy: 'no_prefix',
    locales: [
      {
        code: 'ru',
        name: 'Russian',
        file: 'ru-RU.js'
      },
      {
        code: 'en',
        name: 'English',
        file: 'en-US.js'
      },
    ],
    differentDomains: false,
    forwardedHost: false,
    lazy: true,
    langDir: 'lang/',
    parsePages: false,
  },
dzcpy

dzcpy posted a new bug report

nuxt-i18n •

bug Cannot get translations when there is some special characters in locale's code name

Version

v5.3.0

Reproduction link

https://codesandbox.io/s/relaxed-ishizaka-tlpim (it's not working for some other errors)

Steps to reproduce

  1. Set a langDir and lazyload: true and properly translate all message
  2. Make sure there is a language which has a '-' in its code, for example zh-CN (which is required, since zh-CN and zh-TW are quite different)
{
  locales: [
    {  // works
      code: 'en',
      file: 'en.js'
    },
    { // does not work
      code: 'zh-CN',
      file: 'zh-CN.js'
    },
    { // works too
      code: 'zh_CN',
      file: 'zh-CN.js'
    }
  ]
}

What is expected ?

Strings to be successfully translated

What is actually happening?

Not working

Additional comments?

However, if put a _ instead of - in locale name, then it works.

golubvladimir

golubvladimir posted a new question

nuxt-i18n •

How to use vuex for storage select lang ?

I want use only vuex for storage select lang.
How to setting get lang from vuex ?
How to disable generation routes ?

moleCuleFFF

moleCuleFFF posted a new bug report

nuxt-i18n •

bug In-Component options do not work with split file page components

Version

v6.4.1

Reproduction link

https://codesandbox.io/s/floral-resonance-qnhqo

Steps to reproduce

In sandbox try to navigate to /fr/test-fr, it will 404.
To fix move the contents of scripts.js into the <script> tag in the index.vue file, restart sandbox, and navigating to the defined path will work.

What is expected ?

We should be presented with a french version of the page

What is actually happening?

We get a 404 not found.

Additional comments?

I discovered this when porting a site over from uVue to nuxt using typescript.

thnima

thnima posted a new bug report

nuxt-i18n •

bug Translations doesn't work when switching language with disabled useCookie property

Version

v6.4.1

Reproduction link

https://codesandbox.io/s/thirsty-lake-m7vwr

Steps to reproduce

Click on the link with the label: "Deutsch"

What is expected ?

The string "English string" should get translated to "Deutscher string"

What is actually happening?

Clicking the link changes the route to "/de", which is fine. But the text doesn't get translated.
If you set useCookie: true in the nuxtConfig again, it works as expected.
Same behaviour can be observed, when you set useCookie: true AND disable the cookies in the browser

prochorz

prochorz posted a new question

nuxt-i18n •

Problem in axios

From v 6.3.1
with this code

~/plugins/axios.ts

const accessor: Plugin = (context: any) => {
    const i18n: any = context.app.i18n;
    context.app.$axios.onRequest((config: any) => {
        if (config.method === 'get' && i18n) {
            const lang = `${i18n.__route.name}`.replace(/^[^_]*___/g, '');
            ...
        }
    });
};

application return error

 ERROR  Cannot read property 'name' of undefined                                                                                                                    

  at $axios.onRequest.config (server.js:11251:36)
  at interceptors.request.use.config (server.js:396:45)
sp0ken

sp0ken posted a new feature request

nuxt-i18n •

idea Dynamic translation

What problem does this feature solve?

This feature will allow translation to be dynamically loaded based on a route parameter.

e.g. a route _parameter.vue could load a 'my-parameter.json' translation file

What does the proposed changes look like?

i18n(context) {
      messages: {
        es: require(`~/locales/es/${context.params.parameter}.json`),
        fr: require(`~/locales/fr/${context.params.parameter}.json`),
        it: require(`~/locales/it/${context.params.parameter}.json`)
      }
    },
34r7h

34r7h posted a new question

nuxt-i18n •

404 on reload to non-default language route

Please point me to the right docs or workaround, spent hours already so would love any help.

When loading to an ru route, i get 404. Upon navigating to another link, the routing responds appropriately. I've tried many variations. Here's my options on nuxt config:

['nuxt-i18n', {
detectBrowserLanguage: {
useCookie: true,
cookieKey: 'i18nredirected', alwaysRedirect: true }, parsePages: false, vueI18nLoader: true, strategy: 'prefixexceptdefault', pages: { about: { en: "/about", ru: "/около" }, contact: { en: "/contact", ru: "/контакт" }, 'listings/tours/index': { en: "/listings/tours", ru: "/объявления/туры" }, 'listings/excursions/index': { en: "/listings/excursions", ru: "/объявления/экскурсии" }, 'offer/tours/id/index': {
en: "/offer/tours/:id",
ru: "/объявления/туры/:id"
},
'offer/excursions/_id/index': {
en: "/listings/excursions/:id",
ru: "/объявления/экскурсии/:id"
},
partners: {
en: '/partners',
ru: '/партнеры'
},
transfers: {
en: '/transfers',
ru: '/трансфер'
}
},
seo: true,
locales: [{
code: 'en',
iso: 'en-GB'
},
{
code: 'ru',
iso: 'ru-RU'
}],
defaultLocale: 'en'
}]

34r7h

34r7h posted a new question

nuxt-i18n •

404 error when reloading on non-default lang

Please point me to the right docs or workaround, spent hours already so would love any help.

When loading to an ru route, i get 404. Upon navigating to another link, the routing responds appropriately. Here's my options on nuxt config:

['nuxt-i18n', {
      detectBrowserLanguage: {
        useCookie: true,
        cookieKey: 'i18n_redirected',
        alwaysRedirect: true
      },
      parsePages: false,
      vueI18nLoader: true,
      strategy: 'prefix_except_default',
      pages: {
        about: {
          en: "/about",
          ru: "/около"
        },
        contact: {
          en: "/contact",
          ru: "/контакт"
        },
        'listings/tours/index': {
          en: "/listings/tours",
          ru: "/объявления/туры"
        },
        'listings/excursions/index': {
          en: "/listings/excursions",
          ru: "/объявления/экскурсии"
        },
        'offer/tours/_id/index': {
          en: "/offer/tours/:id",
          ru: "/объявления/туры/:id"
        },
        'offer/excursions/_id/index': {
          en: "/listings/excursions/:id",
          ru: "/объявления/экскурсии/:id"
        },
        partners: {
          en: '/partners',
          ru: '/партнеры'
        },
        transfers: {
          en: '/transfers',
          ru: '/трансфер'
        }
      },
      seo: true,
      locales: [{
        code: 'en',
        iso: 'en-GB'
      },
      {
        code: 'ru',
        iso: 'ru-RU'
      }],
      defaultLocale: 'en'
    }]
coin-au-carre

coin-au-carre posted a new bug report

nuxt-i18n •

bug this.$i18n.locales seems undefined

Version

v5.3.0

Reproduction link

https://nuxt-community.github.io/nuxt-i18n/lang-switcher.html

Steps to reproduce

Follow the steps on the first section of Lang Switcher

What is expected ?

this.$i18n.locales should contain an array of 3 objects which are defined in nuxt.js.config.

What is actually happening?

this.$i18n.locales is undefined

TypeError
Cannot read property 'filter' of undefined

Additional comments?

this.$i18n.availableLocales returns an array ['en','es','fr]

1isten

1isten posted a new bug report

nuxt-i18n •

bug vuex store is not synced in onLanguageSwitched callback

Version

v5.3.0

Reproduction link

[not provided](not provided)

Steps to reproduce

  1. Enable vuex sync with following options:
{
  vuex: {
    moduleName: 'i18n',

    syncLocale: true,

    syncMessages: true,

    syncRouteParams: true
  },
}
  1. Include the plugin file in nuxt.config.js:
module.exports = {
  plugins: [
    { src: '~plugins/i18n.js' }
  ]
}
  1. The ~/plugins/i18n.js:
export default function ({ app, store }) {

  app.i18n.onLanguageSwitched = (oldLocale, newLocale) => {
    console.log(store.state.i18n.locale === newLocale); // false
    console.log(store.state.i18n.locale === oldLocale); // true
  }

}

What is expected ?

In the onLanguageSwitched callback,

store.state.i18n.locale === newLocale should be true

store.state.i18n.locale === oldLocale should be false

What is actually happening?

store.state.i18n.locale === newLocale is false

store.state.i18n.locale === oldLocale is true

the store is not updated after locale being switched

Additional comments?

Note: actually, I'm using nuxt-i18n v6.4.1, but in the cmty issue creator, the highest nuxt-i18n version number I can choose is v5.3.0 (is this a bug?)

mrleblanc101

mrleblanc101 posted a new question

nuxt-i18n •

Why is this not under @nuxtjs

Hi,
Why is this package not under @nuxtjs/i18n like other official package ?
i.e. @nuxtjs/moment

tvld

tvld posted a new question

nuxt-i18n •

Lazy loading default language for fallback

I have an home page in Dutch/Fr/Es/De/… All other pages are fully English. We need to use lazy loading.

Does anybody know how can I use English / default key for labels we do not have translated?

tvld

tvld posted a new question

nuxt-i18n •

Help...First time install throws: "app.i18n.__detectBrowserLanguage is not a function"

Trying to upgrade from vue-i18n:

$ npm r vuei18n
$ npm i nuxt-i18n

in nuxt.config.js:

modules: [
// Doc: https://axios.nuxtjs.org/usage
'@nuxtjs/axios',
'@nuxtjs/pwa',
[
'nuxt-i18n',
{ /* module options */
detectBrowserLanguage: {
useCookie: true,
cookieKey: 'site_language'
}
}
]
],

$ npm run dev

Immediately throws:
'app.i18n.__detectBrowserLanguage is not a function' in .nuxt/nuxt-i18n/middleware.js line 18

What am I missing?

bayun2

bayun2 posted a new feature request

nuxt-i18n •

idea Is there a way to set cookie's domain

What problem does this feature solve?

For example, my site is a.xxx.com, i want to set cookie in root domain(xxx.com) for other site like b.xxx.com can get the same cookie

cruex-de

cruex-de posted a new question

nuxt-i18n •

strategy prefix gives 404

Hello,

I use the strategy "prefix" to display the pages with "/en", "/de", "/fr". If you go to the website for the first time, this works directly. But if you open the website again and go to "example.com/" and not to "example.com/en" he gives me a "404 Not Found" error message although the cookie was set. If I delete this cookie and go back to "example.com/" he redirects me to one of the prefixes again.

If I set "rootRedirect" to "en" the language cannot be changed, so this is not an option.

Is there a fix for it, or a work around?

i18n: {
    locales: [
      { code: 'en', iso: 'en-US', name: 'English', file: 'en-US.js' },
      { code: 'de', iso: 'de-DE', name: 'Deutsch', file: 'de-DE.js' },
      { code: 'fr', iso: 'fr-FR', name: 'France', file: 'fr-FR.js' },
    ],
    strategy: 'prefix',
    lazy: true,
    langDir: 'lang/',
    detectBrowserLanguage: {
      useCookie: true,
      cookieKey: 'i18n',
    },
    seo: true,
    defaultLocale: 'en',
    vueI18n: {
      fallbackLocale: 'en',
    },
  },
jcfauchet

jcfauchet posted a new question

nuxt-i18n •

Get possibility to differenciate language with locale

Hi,

Today there is no posibility to get browser language with is locale (if available, like en-GB, fr-FR, en-US …) but only with language (fr, en …).
I think it could be interesting to catch it maybe with a dedicated parameter in the options ?

Regards

d0peCode

d0peCode posted a new question

nuxt-i18n •

nuxtI18n.paths with aliases

In my component I have

export default {
    nuxtI18n: {
        paths: {
            pl: '/bilety-miesieczne',
            en: '/season-tickets'
        }
    },

and my default locale is pl so basically if I enter localhost:3000/bilety-miesieczne it shows me page in polish and when I visit localhost:3000/en/season-tickets it shows me same page in english.

However because my site is already existing I need to handle some mix of polish and english because that's how currently it was designed and I want links which already exists (somewhere in net) to be still supported.

For example someone could click mydomain.com/en/bilety-miesieczne (so english prefix but polish name) and I want it to be caught as /en/season-tickets so display season tickets page in english.

So what I need is some kind of alias or to pass array to nuxtI18n.paths.en for example:

export default {
    nuxtI18n: {
        paths: {
            pl: '/bilety-miesieczne',
            en: ['/season-tickets', '/bilety-miesieczne']
        }
    },

but above doesn't work obviously but my question is - is what I want to achieve currently possible with nuxt-i18n and if not where to start digging to add it on my own?

halilyuce

halilyuce posted a new question

nuxt-i18n •

How Can I Change URL When User Change Language?

Im using the dynamic route for show single post page, I`m sending category slug and post name slug as parameters to show it.

Link:

:href="localePath({
name: 'news-category-post',
params: {
category: post.categories ? post.categories[0].slug : '',
post: post.slug
}
})

Route :

'news/category/post': {
en: /news/:category/:post,
es: /pronosticos/:category/:post,
pt: /prognostics/:category/:post,
},
When users change the language on the post page How can I change post slug with a new one? Im using i18n plugin for multilanguage website.

English URL : http://en.localhost:3000/news/soccer/dortmund-barcelona-champions-2019-matchday-5

Expected ESP URL : http://localhost:3000/pronosticos/futbol/barcelona-dortmund-champions-2019-jornada-5

I added all slugs to API result and I can use what I want.

1McTK.png