Repository nuxt-i18n

carneiroskeeled

carneiroskeeled posted a new feature request

nuxt-i18n • 6 hours ago

idea Accept a promise in the pages option

What problem does this feature solve?

In my project I don't have the routes (pages and respective translations) available until I generate/run nuxt since I am getting it from another source (Contentful), and getting them from Contentful is a promise. Shouldn't nuxt-i18n accept a promise in this option or is there a better way to do this?

wildan2711

wildan2711 posted a new question

nuxt-i18n • 2 days ago

Vue-i18n added twice in entry.vendor of webpack config

Just recently, I tried building using npm run dev, and this error came up:

  WebpackOptionsValidationError: Invalid configuration object. Webpack has been initialised using a configuration   object that does not match the API schema.
   - configuration.entry should be one of these:
     object { <key>: non-empty string | [non-empty string] } | non-empty string | [non-empty string] | function
     -> The entry point(s) of the compilation.
     Details:
      * configuration.entry['vendor'] should be a string.
        -> The string is resolved to a module which is loaded upon startup.
      * configuration.entry['vendor'] should not contain the item 'vue-i18n' twice.
      * configuration.entry should be a string.
        -> An entry point without name. The string is resolved to a module which is loaded upon startup.
      * configuration.entry should be an array:
        [non-empty string]
      * configuration.entry should be an instance of function
        -> A Function returning an entry object, an entry string, an entry array or a promise to these things.

So I checked the emitted webpack config using this nuxt.config.js:

require('dotenv').config()

module.exports = {
    head: {
        title: `Dolan`,
        meta: [{
            charset: 'utf-8'
        }]
    },
    router: {
        middleware: ['auth']
    },
    plugins: [
        {src: '~/plugins/vuetify.js', ssr: true},
        {src: '~/plugins/dolan.js', ssr: true},
        {src: '~/plugins/filters.js', ssr: true},
        {src: '~/plugins/mixin.js', ssr: true},
        {src: '~/plugins/vee-validate.js', ssr: true}
    ],
    css: [
        '~/assets/style/app.styl',
        '~/assets/style/font.styl'
    ],
    modules: [
        '@nuxtjs/axios', '@nuxtjs/auth', ['nuxt-i18n', {
            defaultLocale: 'en',
            langDir: 'locales/',
            lazy: true,
            locales: [{
                code: 'en',
                iso: 'en-US',
                name: 'English',
                file: 'en.js'
            },
            {
                code: 'id',
                iso: 'id-ID',
                name: 'Bahasa',
                file: 'id.js'
            }
            ],
            vueI18n: {
                fallbackLocale: 'en'
            }
        }]
    ],
    axios: {
        baseURL: process.env.BASE_URL,
        credentials: true
    },
    auth: {
        defaultStrategy: 'server',
        strategies: {
            server: {
                _scheme: 'oauth2',
                authorization_endpoint: '/oauth2/auth',
                userinfo_endpoint: '/user',
                scope: ['openid', 'profile', 'email'],
                client_id: process.env.CLIENT_ID,
                grant_type: 'password'
            }
        },
        cookie: false,
        rewriteRedirects: true,
        plugins: [
            '~/plugins/auth.js'
        ]
    },
    loading: {
        color: '#3B8070'
    },
    build: {
        vendor: [
            '~/plugins/vuetify.js',
            '~/plugins/vee-validate.js'
        ],
        extractCSS: true,
        extend(config, ctx) {
            console.log(config)
            config.module.rules.push({
                test: /\.tsx?/,
                loader: 'ts-loader'
            })
            config.module.rules.forEach(rule => {
                if (rule.loader === 'vue-loader') {
                    rule.options.loaders.ts = 'ts-loader?{"appendTsSuffixTo":["\\\\.vue$"]}'
                }
            })
        }
    }
}

And this came up in the webpack config:

{ name: 'client',
  entry:
   { app:
      [ 'webpack-hot-middleware/client?name=client&reload=true&timeout=30000&path=/__webpack_hmr',
        'C:\\Users\\wildan\\Documents\\go\\src\\gitlab.com\\dolan-in\\dolan\\ui\\.nuxt\\client.js' ],
     vendor:
      [ 'vue',
        'vue-router',
        'vue-meta',
        'vuex',
        'vue-style-loader/lib/addStylesClient',
        'css-loader/lib/css-base',
        '~/plugins/vuetify.js',
        '~/plugins/vee-validate.js',
        'vue-i18n',
        'vue-i18n' ] },

vue-i18n is added twice on the webpack config. Anything wrong in my nuxt config?

Nuxt version: 1.4.2
Nuxt-i18n version: 5.1.1

MomenYasser

MomenYasser posted a new bug report

nuxt-i18n • 3 days ago

bug Non-Latin characters encoding issue

Version

v5.1.1

Reproduction link

https://github.com/MomenYasser/nuxt-i18n-non-encoding-issue

Steps to reproduce

1- git clone https://github.com/MomenYasser/nuxt-i18n-non-encoding-issue
2- npm install
3- npm run dev
4- go to http://localhost:3000/about
5- Check your terminal

What is expected ?

Expected to encode Non-Latin characters in URL like Arabic

What is actually happening?

I got this error

{ statusCode: 404,
path: '/ar/%D8%B9%D9%86%D8%A7',
message: 'This page could not be found' }

[nuxt-i18n] Locale ISO code is required to generate alternate link

bartlomieju

bartlomieju resolved the question #c121

nuxt-i18n • 4 days ago

Do not delete name of route with children

Hi @paulgv sorry for trouble, it looks like my Nuxt route config is improper, I should have added index.vue file to vendors directory.

bartlomieju

bartlomieju posted a new question

nuxt-i18n • 4 days ago

Do not delete name of route with children

Hi!

Today I stumbled across a problem that deletes name of routes that have children. I think this is unexpected behaviour, as I tend to have directory structure like this:
zrzut ekranu 2018-08-16 o 18 00 38
and do a redirect in vendors/_slug.vue file.

The culprit is this line:
https://github.com/nuxt-community/nuxt-i18n/blob/45ff90d1b8076c12f5c1a75fb7e2d398450e7c51/src/helpers/routes.js#L70

What is your opinion on this one?

liuhuanhui

liuhuanhui posted a new question

nuxt-i18n • 5 days ago

element-ui after calling the popup, I found that the attributes of the html tag (such as lang="en-US") were deleted?

https://github.com/ElemeFE/element/issues/12378#issuecomment-413163214

Element UI version
2.4.6

OS/Browsers version
GOOGLE

Vue version
2.5.17

Reproduction Link
https://github.com/liuhuanhui/bug01/

Steps to reproduce
https://github.com/liuhuanhui/bug01/
F12, run, check the HTML tag, and then click the button on the page.

redijedi

redijedi posted a new question

nuxt-i18n • 5 days ago

Acorn suddenly raising issues with module

This was working yesterday. Suddenly today when I restarted my server (before doing any work) I am getting:

[1] 2018-08-15T13:20:40.941Z nuxt:build Generating files...
[1] 2018-08-15T13:20:40.947Z nuxt:build Generating routes...
[1]
[1]  ERROR
[1]
[1]   SyntaxError: Shorthand property assignments are valid only in destructuring pa  tterns (11:25)
[1]
[1]   - acorn.js:2756 Parser.pp$4.raise
[1]     [ui]/[acorn]/dist/acorn.js:2756:13
[1]
[1]   - acorn.js:673 Parser.pp.checkExpressionErrors
[1]     [ui]/[acorn]/dist/acorn.js:673:12
[1]
[1]   - acorn.js:1938 Parser.pp$3.parseMaybeAssign
[1]     [ui]/[acorn]/dist/acorn.js:1938:40
[1]
[1]   - acorn.js:1896 Parser.pp$3.parseExpression
[1]     [ui]/[acorn]/dist/acorn.js:1896:19
[1]
[1]   - acorn.js:946 Parser.pp$1.parseReturnStatement
[1]     [ui]/[acorn]/dist/acorn.js:946:31
[1]
[1]   - acorn.js:781 Parser.pp$1.parseStatement
[1]     [ui]/[acorn]/dist/acorn.js:781:35
[1]
[1]   - acorn.js:1112 Parser.pp$1.parseBlock
[1]     [ui]/[acorn]/dist/acorn.js:1112:23
[1]
[1]   - acorn.js:2599 Parser.pp$3.parseFunctionBody
[1]     [ui]/[acorn]/dist/acorn.js:2599:22
[1]
[1]   - acorn.js:2532 Parser.pp$3.parseMethod
[1]     [ui]/[acorn]/dist/acorn.js:2532:8
[1]
[1]   - acorn.js:2448 Parser.pp$3.parsePropertyValue
[1]     [ui]/[acorn]/dist/acorn.js:2448:23
[1]
[1]   - acorn.js:2433 Parser.pp$3.parseProperty
[1]     [ui]/[acorn]/dist/acorn.js:2433:8
[1]
[1]   - acorn.js:2379 Parser.pp$3.parseObj
[1]     [ui]/[acorn]/dist/acorn.js:2379:23
[1]
[1]   - acorn.js:2179 Parser.pp$3.parseExprAtom
[1]     [ui]/[acorn]/dist/acorn.js:2179:17
[1]
[1]   - acorn.js:2047 Parser.pp$3.parseExprSubscripts
[1]     [ui]/[acorn]/dist/acorn.js:2047:19
[1]
[1]   - acorn.js:2024 Parser.pp$3.parseMaybeUnary
[1]     [ui]/[acorn]/dist/acorn.js:2024:17
[1]
[1]   - acorn.js:1966 Parser.pp$3.parseExprOps
[1]     [ui]/[acorn]/dist/acorn.js:1966:19

I've narrowed it down to nuxt-i18n. If I remove the module everything works, but of course I lose i18n. I've seen other issues that seem related, but none that are specifically this error at start up. Curiously, I have no changes related to i18n since yesterday morning. The server was working all day yesterday.

Please advise, I cannot even start the app anymore.

bencehusi

bencehusi posted a new question

nuxt-i18n • 6 days ago

ERR! code ELIFECYCLE after stopping nuxt

Please help me clarify why am I getting error in the command line after stopping nuxt. What am I missing? It is clearly related to nuxt-i18n since the error shows up immediately after I add the 'nuxt-i18n' module in nuxt.config.js in a fresh nuxt starter project.

Version

6.3.0

What is happening

  1. Using the Nuxt community starter setup a project
  2. Install nuxt-i18n
  3. npm run dev or npm run start -> everything works fine
  4. Stop the process with control + c
  5. Error shows up in the command line

Command line error

npm ERR! code ELIFECYCLE
npm ERR! errno 130
npm ERR! [email protected] dev: nuxt
npm ERR! Exit status 130
npm ERR!
npm ERR! Failed at the [email protected] dev script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR! [path-to-npm-logs]/2018-08-14T212617_051Z-debug.log

debug.log content

0 info it worked if it ends with ok
1 verbose cli [ '/usr/local/bin/node', '/usr/local/bin/npm', 'run', 'dev' ]
2 info using [email protected]
3 info using [email protected]
4 verbose run-script [ 'predev', 'dev', 'postdev' ]
5 info lifecycle [email protected]~predev: [email protected]
6 info lifecycle [email protected]~dev: [email protected]
7 verbose lifecycle [email protected]~dev: unsafe-perm in lifecycle true
8 verbose lifecycle [email protected]~dev: PATH: /usr/local/lib/nodemodules/npm/nodemodules/npm-lifecycle/node-gyp-bin:/Users/bencehusi/DEV/via-jobs/nodemodules/.bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin 9 verbose lifecycle [email protected]~dev: CWD: /Users/bencehusi/DEV/via-jobs 10 silly lifecycle [email protected]~dev: Args: [ '-c', 'nuxt' ] 11 silly lifecycle [email protected]~dev: Returned: code: 130 signal: null 12 info lifecycle [email protected]~dev: Failed to exec dev script 13 verbose stack Error: [email protected] dev: nuxt 13 verbose stack Exit status 130 13 verbose stack at EventEmitter.<anonymous> (/usr/local/lib/nodemodules/npm/nodemodules/npm-lifecycle/index.js:304:16) 13 verbose stack at emitTwo (events.js:125:13) 13 verbose stack at EventEmitter.emit (events.js:213:7) 13 verbose stack at ChildProcess.<anonymous> (/usr/local/lib/nodemodules/npm/nodemodules/npm-lifecycle/lib/spawn.js:55:14) 13 verbose stack at emitTwo (events.js:125:13) 13 verbose stack at ChildProcess.emit (events.js:213:7) 13 verbose stack at maybeClose (internal/childprocess.js:927:16)
13 verbose stack at Process.ChildProcess.handle.onexit (internal/childprocess.js:211:5)
14 verbose pkgid [email protected]
15 verbose cwd /Users/bencehusi/DEV/via-jobs
16 verbose Darwin 17.7.0
17 verbose argv "/usr/local/bin/node" "/usr/local/bin/npm" "run" "dev"
18 verbose node v8.6.0
19 verbose npm v6.3.0
20 error code ELIFECYCLE
21 error errno 130
22 error [email protected] dev: nuxt
22 error Exit status 130
23 error Failed at the [email protected] dev script.
23 error This is probably not a problem with npm. There is likely additional logging output above.
24 verbose exit [ 130, true ]

related part of nuxt.config

modules: [
    ['nuxt-i18n', {
      locales: [
        { code: 'hu', iso: 'hu-HU', file: 'hu.js' },
        { code: 'sr', iso: 'sr-RS', file: 'sr.js' },
      ],
      lazy: true,
      langDir: 'locales/',
      defaultLocale: 'hu',
      strategy: 'prefix_except_default',
      vueI18n: {
        fallbackLocale: 'hu'
      }
    }]
  ]

locales/hu.js

export default {
  welcome: 'Üdvözöllek'
}
redijedi

redijedi posted a new question

nuxt-i18n • 6 days ago

How to use dateFormats with nuxt-i18n?

I've tried to add short/long formatting to my locales similar to how they are described here: https://kazupon.github.io/vue-i18n/guide/datetime.html. Unfortunately, when attempting to use it vi a {{ $d(new Date(), 'long') }} it displays nothing.

My locale files are in a locale directory separated by lang sub directories (en, de, etc.). Each subdirectory contains am index.js that pulls together various independent language files like so:

import * as global from './global.json';
import * as auth from './auth.json';
import * as navbar from './navbar.json';
import * as login from './login.json';

export default {
  global,
  auth,
  navbar,
  login,
  dateTimeFormats: {
    short: {
      year: 'numeric', month: 'short', day: 'numeric',
    },
    long: {
      year: 'numeric',
      month: 'short',
      day: 'numeric',
      weekday: 'short',
      hour: 'numeric',
      minute: 'numeric',
    },
  },
};

I've tried adding dateTimeFormats as shown above, adding them in the json files themselves, adding them to the default export without the dateTimeFormats container, but nothing works. Please advise.

paulgv

paulgv fixed the bug report #c101 in v5.0.3

nuxt-i18n • 8 days ago

bug Headers already sent
nghiepit

nghiepit resolved the question #c28

nuxt-i18n • 9 days ago

Reload of JSON language files

using lazy-load-translations to reload the translations.

 [ 'nuxt-i18n',
      {
        locales: [
          {
            code: 'en',
            name: 'English',
            file: 'en-US.js',
          },
        ],
        lazy: true,
        langDir: 'locales/',
      }
]
// locales/en-US.js
export default require('./en.json')
paulgv

paulgv posted a new bug report

nuxt-i18n • 9 days ago

bug Default locale & browser language detection confusion

Version

v5.0.3

Reproduction link

https://github.com/nuxt-community/nuxt-i18n

Steps to reproduce

Quoting @mapeal2
https://cmty.app/nuxt/nuxt-i18n/issues/c96

Given 2 locales ('en', 'fr'), default locale is 'en' and the preferred browser language is 'fr', with the 'prefixexceptdefault' option, the steps to reproduce it would be:
Visit home page '/' --> browser language is detected and redirected to '/fr', which is correct.
Close the browser.
Open a new browser and enter the home page ('/') again 

What is expected ?

I would expect that, when opening the home page again, the application would be redirected to '/fr' instead of staying in '/'.

What is actually happening?

 'en' locale is chosen, ignoring cookie.
paulgv

paulgv resolved the question #c104

nuxt-i18n • 9 days ago

Seo plugin doesn't add fully-qualified URL for hreflang

Implemented in v5.0.0

paulgv

paulgv resolved the question #c109

nuxt-i18n • 9 days ago

Locale ISO code is required to generate alternate link

Hi @sergiocastrovale
As specified in the doc, you need to add an iso key for each language your app supports: https://nuxt-community.github.io/nuxt-i18n/seo.html

paulgv

paulgv fixed the bug report #c95 in v5.0.2

nuxt-i18n • 9 days ago

bug Cannot read property 'pages' of undefined
haexhub

haexhub resolved the question #c89

nuxt-i18n • 9 days ago

Access nuxt-i18n in vuex

I got it. You can access i18n module in vuex mutations and actions (not in getters).
this.app.i18n.t(translate-something) and you are good to go. :)

paulgv

paulgv fixed the bug report #c83 in v4.0.0

nuxt-i18n • 9 days ago

bug this.$i18n.locales is undefined

4.0.0 (2018-06-07)

Bug Fixes

  • Rename in-component options key from i18n to nuxtI18n (5ff618d), closes #94 #67

BREAKING CHANGES

  • Pages using i18n key need to be updated to use nuxtI18n key instead
paulgv

paulgv fixed the bug report #c75 in v3.2.2

nuxt-i18n • 9 days ago

bug Cannot read property 'iso' of undefined
paulgv

paulgv resolved the question #c61

nuxt-i18n • 9 days ago

why is route.name favored over route.path

Hi @Syffs
Sorry for answering this late, I just noticed your question!
localePath() uses route.name because it's more reliable since every locale version of a route has the same base name whereas path might have been customized which would force the module to perform additional resolving.
Naming this method localePath makes sense in my opinion since it returns a path.

paulgv

paulgv fixed the bug report #c57

nuxt-i18n • 9 days ago

bug [BUG Report] getRouteBaseName and detectBrowserLanguage error

Fixed in v2.9.2