Giter VIP home page Giter VIP logo

vue-cli-plugin-i18n's Introduction

🌏 vue-cli-plugin-i18n

npm npm Test vue-cli-plugin-i18n Dev Token

Vue CLI plugin to add vue-i18n to your Vue Project

🌟 Features

  • vue-i18n basic scaffolding
  • Locale messages in Single File components with vue-i18n-loader
  • Locale messages missing & unused reporting (experimental)
  • Env Variables

πŸš€ Getting Started

If yon don't have a project created with Vue CLI:

vue create my-vue-app

Install the plugin into your project:

cd my-vue-app
vue add i18n

πŸ”¨ Injected Commands

  • vue-cli-service i18n:report (experimental)

    Report the missing locale message keys and unused keys.

NOTE: limitation vue-cli-service i18n:report cannot detect missing and unused keys from local messages of i18n custom blocks.

πŸ“‹ Env variables

When vue-i18n code files had been scaffolded into your project, the following env variables generate into .env:

  • VUE_APP_I18N_LOCALE

    The locale of project localization, default en.

  • VUE_APP_I18N_FALLBACK_LOCALE

    The locale of project fallback localization, default en.

These env variables are read in src/i18n.(js|ts).

πŸ”§ Configurations

vue-cli-plugin-i18n have some plugin options in vue.config.js:

module.exports = {
  pluginOptions: {
    i18n: {
      locale: 'ja',
      fallbackLocale: 'en',
      localeDir: 'locales',
      enableInSFC: false,
      enableLegacy: false
    }
  }
}

locale

  • Type: string

  • Default in prompt: en

    The locale of project localization.

fallbackLocale

  • Type: string

  • Default in prompt: en

    The fallback locale of project localization.

localeDir

  • Type: string

  • Default in prompt: locales

    The directory where store localization messages of project. The specified directory will start from the src directory.

enableInSFC

  • Type: boolean

  • Default in prompt: false

  • Support project Vue version: Vue 2 only

    Whether enable locale messages in Single file components. Default No in prompt, for Vue 2 and Vue I18n v8.x only.

enableLegacy

  • Type: boolean

  • Default in prompt: false

  • Support project Vue version: Vue 3 only

    Whether use legacy mode API in Vue I18n. Default No in prompt, for Vue 3 and Vue I18n v9 or later.

enableBridge

  • Type: boolean

  • Default in prompt: false

  • Support project Vue version: Vue 2 only

    Whether to set up a bridge to migrate to [email protected] from [email protected], Default No in prompt.

    ⚠️ NOTE: If you use the Composition API with vue-i18n-bridge in bridge mode, you need to install @vue/composition-api.

includeLocales

  • Type: boolean

  • Default in prompt: false

  • Support project Vue version: Vue 2 only

    When enableBridge is true, i.e. in bridge mode, whether localization messages placed in localeDir option should be pre-compiled by message compiler or not.

    If you use Composition API in bridge mode, this option must be true because all localization messages are bundled during production build.

runtimeOnly

  • Type: boolean

  • Default(No Prompt): false

  • Support project Vue version: Vue 3 only

    Whether or not to use Vue I18n runtime-only, set in the vue-i18n field of webpack resolve.alias option. default Vue I18n (vue-i18n) package.json module field will be used. If true is specified, Vue I18n (vue-i18n) will use node_modules/vue-i18n/dist/vue-i18n.runtime.esm-bundler.js.

    For more details, See here

compositionOnly

  • Type: boolean

  • Default(No Prompt): if enableLegacy set false, true else then false

  • Support project Vue version: Vue 3 only

    Whether to make vue-i18n's API only composition API. By default the legacy API is tree-shaken.

    For more details, See here

fullInstall

  • Type: boolean

  • Default(No Prompt): true

  • Support project Vue version: Vue 3 only

    Whether to install the full set of APIs, components, etc. provided by Vue I18n. By default, all of them will be installed.

    If false is specified, build-in components and directive will not be installed in vue and will be tree-shaken.

    For more details, See here

πŸ“œ Changelog

Details changes for each release are documented in the CHANGELOG.md.

❗ Issues

Please make sure to read the Issue Reporting Checklist before opening an issue. Issues not conforming to the guidelines may be closed immediately.

βœ… TODO

Managed with GitHub Projects

πŸ’ͺ Contribution

Please make sure to read the Contributing Guide before making a pull request.

©️ License

MIT

vue-cli-plugin-i18n's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

vue-cli-plugin-i18n's Issues

Cannot translate the value of keypath

Hi there.

I'm trying to use this plugin without success. I'm getting the following warning and the translations is not applied to the component.

[vue-i18n] Cannot translate the value of keypath 'download-bar.better-visualized'. Use the value of keypath as default.

My vue.config.js is with the default value and I've created a second locale, setting it to default (pt-BR).

Am I missing something here?

vue.config.js

module.exports = { chainWebpack: config => { config.module .rule('vue') .use('vue-loader') .loader('vue-loader') .tap(options => { options["transformAssetUrls"] = { 'img': 'src', 'image': 'xlink:href', 'b-img': 'src', 'b-img-lazy': ['src', 'blank-src'], 'b-card': 'img-src', 'b-card-img': 'img-src', 'b-carousel-slide': 'img-src', 'b-embed': 'src' } return options } ) }, pluginOptions: { i18n: { locale: 'pt-BR', fallbackLocale: 'pt-BR', localeDir: 'locales', enableInSFC: false } } }

pt-BR.json

{ "download-bar": { "better-visualized": "Melhor visualizado com Google Chrome ou Mozilla Firefox" } }

Double configuration for `locale`, `fallbackLocale` & `localeDir`

The locale, the fallbackLocale and the localeDir is defined in i18n.js as well as in the pluginOptions of vue.config.js. How come? What's the benefit?

I've now removed those properties from vue.config.js and it still works as expected. I generated the project with SFC enabled.

Fix initialization on ui

Hello,
When we load UI i don't have locales.

I have investigate on this error and this is because the currentProject and currentConfig.
This is caused because when start vue ui the plugin is not reloaded.

And now i have fix that with write next code in onProjectOpen

const rawConfig = require(`${project.path}/vue.config`)
const config = (rawConfig.pluginOptions && rawConfig.pluginOptions.i18n)
  ? rawConfig.pluginOptions.i18n
  : { localeDir: 'locales' }
if (!config.localeDir) { config.localeDir = 'locales' }
debug('onProjectOpen : load vue.config', config)
setupAddon(project.path, config)
currentProject = project
currentConfig = config

Thanks.

πŸ“’ Notice: transfer of repository

vue-cli-plugin-i18n will soon be transferred to intlify organaization. After that, it will be developed and maintained on intlify.

The vue-cli-plugin-i18n that has been released on npm will be released as @intlify/vue-cli-plugin-i18n in near future.

Intlify is a new i18n project kickoff by @kazupon. πŸ˜‰

Add support for path definition

I'm trying to use it with nativescript and it is using different folder: app instead of src
It would be good to be able to specify source files folder, because ui of the plugin crashes:

(node:2124) UnhandledPromiseRejectionWarning: Error: ENOENT: no such file or directory, scandir 'C:\xxx\yyy\native-app/src/locales'

"Error: Line 15: Unexpected token :" when invoking plugin

While invoking the plugin (both from the UI and through vue invoke), with defaults kept as is, the Vue CLI crashes with the following stacktrace:

Error: Line 15: Unexpected token :
    at ErrorHandler.constructError (/home/solarliner/.nvm/versions/node/v10.9.0/lib/node_modules/@vue/cli/node_modules/esprima/dist/esprima.js:5012:22)
    at ErrorHandler.createError (/home/solarliner/.nvm/versions/node/v10.9.0/lib/node_modules/@vue/cli/node_modules/esprima/dist/esprima.js:5028:27)
    at Parser.unexpectedTokenError (/home/solarliner/.nvm/versions/node/v10.9.0/lib/node_modules/@vue/cli/node_modules/esprima/dist/esprima.js:1985:39)
    at Parser.throwUnexpectedToken (/home/solarliner/.nvm/versions/node/v10.9.0/lib/node_modules/@vue/cli/node_modules/esprima/dist/esprima.js:1995:21)
    at Parser.expect (/home/solarliner/.nvm/versions/node/v10.9.0/lib/node_modules/@vue/cli/node_modules/esprima/dist/esprima.js:2168:19)
    at Parser.parseGroupExpression (/home/solarliner/.nvm/versions/node/v10.9.0/lib/node_modules/@vue/cli/node_modules/esprima/dist/esprima.js:2764:27)
    at Parser.inheritCoverGrammar (/home/solarliner/.nvm/versions/node/v10.9.0/lib/node_modules/@vue/cli/node_modules/esprima/dist/esprima.js:2285:37)
    at Parser.parsePrimaryExpression (/home/solarliner/.nvm/versions/node/v10.9.0/lib/node_modules/@vue/cli/node_modules/esprima/dist/esprima.js:2348:38)
    at Parser.inheritCoverGrammar (/home/solarliner/.nvm/versions/node/v10.9.0/lib/node_modules/@vue/cli/node_modules/esprima/dist/esprima.js:2285:37)
    at Parser.parseLeftHandSideExpressionAllowCall (/home/solarliner/.nvm/versions/node/v10.9.0/lib/node_modules/@vue/cli/node_modules/esprima/dist/esprima.js:2899:26)

Localization service integration

Spec

to support continuous translation in translation service, vue-cli-plugin-i18n provides the following commands:

Commands:

vue-cli-service i18n:set

set the main locale message to localization service

vue-cli-service i18n:update

sync the main locale messages to localization service

vue-cli-service i18n:status

show the status of the localization service.

  • --progress: show the current translation progress at localization service
  • --locales: show the current translation languages

vue-cli-service i18n:pull

pull the locale messages on localization service. default all locales on localization service.

  • --locale: pull the target locale

Configrations

  • VUE_APP_I18N_LOCALIZATION_ID: API user id of localization service
  • VUE_APP_I18N_LOCALIZATION_TOKEN: API token of localization service

CLI UI getLocales problem when Locales dir contains non json files

If the Locales directory contains non json files (for example an index.js file), getLocales retrieves it as a locale and then getLocaleMessages fails to find the file with '.json' appended (fails to find 'index.js.json'.
As a result, the Localizations UI doesn't work.

Shouldn't getLocales look only for .json files or sub-directories ?

Thanks.

Invoking generator for vue-cli-plugin-i18n error (esprima)

Hi,

I cannot install and invoke vue-cli-plugin-i18n neither with Vue-cli (3.rc3) and not with VueUI.
Tested on two computers (both: win10 home x64, node 8.10.0, npm 6.1.0, yarn 1.7.0).

Steps to reproduce
vue add i18n

What is expected?

πŸ“¦  Installing vue-cli-plugin-i18n...

yarn add v1.7.0
[1/5] Validating package.json...
[2/5] , [3/5] Fetching packages..., [4/5] ..., [5/5] Building fresh packages...
.......... truncated
info All dependencies
β”œβ”€ [email protected]
β”œβ”€ [email protected]
└─ [email protected]
Done in 34.04s.

βœ”  Successfully installed plugin: vue-cli-plugin-i18n

? The locale of project localization. en
? The locale of project fallback localization. en
? Enable locale messages in Single file components ? No

πŸš€  Invoking generator for vue-cli-plugin-i18n...

What is actually happening?
After invoking I get error:

πŸš€  Invoking generator for vue-cli-plugin-i18n...
 ERROR  Error: Line 31: Unexpected token ...
Error: Line 31: Unexpected token ...
    at ErrorHandler.constructError (C:\Users\davor\AppData\Roaming\npm\node_modules\@vue\cli\node_modules\esprima\dist\esprima.js:5004:22)
    at ErrorHandler.createError (C:\Users\davor\AppData\Roaming\npm\node_modules\@vue\cli\node_modules\esprima\dist\esprima.js:5020:27)
    at JSXParser.Parser.unexpectedTokenError (C:\Users\davor\AppData\Roaming\npm\node_modules\@vue\cli\node_modules\esprima\dist\esprima.js:1985:39)
    at JSXParser.Parser.throwUnexpectedToken (C:\Users\davor\AppData\Roaming\npm\node_modules\@vue\cli\node_modules\esprima\dist\esprima.js:1995:21)
    at JSXParser.Parser.parseObjectPropertyKey (C:\Users\davor\AppData\Roaming\npm\node_modules\@vue\cli\node_modules\esprima\dist\esprima.js:2492:33)
    at JSXParser.Parser.parseObjectProperty (C:\Users\davor\AppData\Roaming\npm\node_modules\@vue\cli\node_modules\esprima\dist\esprima.js:2527:25)
    at JSXParser.Parser.parseObjectInitializer (C:\Users\davor\AppData\Roaming\npm\node_modules\@vue\cli\node_modules\esprima\dist\esprima.js:2595:35)
    at JSXParser.Parser.inheritCoverGrammar (C:\Users\davor\AppData\Roaming\npm\node_modules\@vue\cli\node_modules\esprima\dist\esprima.js:2278:37)
    at JSXParser.Parser.parsePrimaryExpression (C:\Users\davor\AppData\Roaming\npm\node_modules\@vue\cli\node_modules\esprima\dist\esprima.js:2347:38)
    at JSXParser.parsePrimaryExpression (C:\Users\davor\AppData\Roaming\npm\node_modules\@vue\cli\node_modules\esprima\dist\esprima.js:466:97)

Maybe will help: same thing is happening with vue-cli-plugin-django but vue-cli-plugin-vuex-module-generator works fine when invoked

Vue Cli3 initialization fails "unexpected identifier"

vue & vue-i18n version

Vue: ^2.5.17
i18n: latest

Steps to reproduce

execute "vue add i18n" on a vue project

What is Expected?

i18n should install, fire the plugin generator and finished installation afterwards.

What is actually happening?

i18n installs fine,
launches the plugin generator which also works fine until you hit enter after selecting
an option for "Enable locale messages in Single file components". Afterwards an Error is thrown

ERROR Error: Line 17: Unexpected identifier Error: Line 17: Unexpected identifier at ErrorHandler.constructError (C:\Users\janja\AppData\Roaming\npm\node_modules\@vue\cli\node_modules\esprima\dist\esprima. js:5012:22) at ErrorHandler.createError (C:\Users\janja\AppData\Roaming\npm\node_modules\@vue\cli\node_modules\esprima\dist\esprima.js: 5028:27) at Parser.unexpectedTokenError (C:\Users\janja\AppData\Roaming\npm\node_modules\@vue\cli\node_modules\esprima\dist\esprima. js:1985:39) at Parser.throwUnexpectedToken (C:\Users\janja\AppData\Roaming\npm\node_modules\@vue\cli\node_modules\esprima\dist\esprima. js:1995:21) at Parser.expect (C:\Users\janja\AppData\Roaming\npm\node_modules\@vue\cli\node_modules\esprima\dist\esprima.js:2168:19) at Parser.parseGroupExpression (C:\Users\janja\AppData\Roaming\npm\node_modules\@vue\cli\node_modules\esprima\dist\esprima. js:2764:27) at Parser.inheritCoverGrammar (C:\Users\janja\AppData\Roaming\npm\node_modules\@vue\cli\node_modules\esprima\dist\esprima.j s:2285:37) at Parser.parsePrimaryExpression (C:\Users\janja\AppData\Roaming\npm\node_modules\@vue\cli\node_modules\esprima\dist\esprim a.js:2348:38) at Parser.inheritCoverGrammar (C:\Users\janja\AppData\Roaming\npm\node_modules\@vue\cli\node_modules\esprima\dist\esprima.j s:2285:37) at Parser.parseLeftHandSideExpressionAllowCall (C:\Users\janja\AppData\Roaming\npm\node_modules\@vue\cli\node_modules\espri ma\dist\esprima.js:2899:26)

Browser freeze with 7kb json lang file.

I try use localizations tab in new vue cli UI (/addon/org.kazupon.vue-i18n/)
After putting my project lang file in locales dir, i click localizations tab , my browser freeze for 20 sec before i see my keys and translations.

ua.zip

Some Question In ui.js set localeDir path

When I modified the project entry in vue.config.js with Vue-cli 3.0 like:

 configureWebpack: {
    resolve: {
      alias:{'@' : resolve('examples')},
    }
  },
  chainWebpack: config => {
    const appsetting = config.entry('app');
    appsetting.clear();
    appsetting.add('./examples/main.ts');
  },

project tree like:

+Root
    + examples
            +assets 
            +components
            +locales
            +views
            App.vue
            i18n.ts
            main.ts
            ......
    +node_modules
    +packages
    ......
    vue.config.js

then I run the vue service command: "vue ui" and view the plugin in the browser, throw an error:

Error: ENOENT: no such file or directory, scandir 'd:\vscode\crucian\crucian-vue-ui/src/locales'
at Object.readdirSync (fs.js:750:3)
at getLocales (d:\vscode\crucian\crucian-vue-ui\node_modules\vue-cli-plugin-i18n\ui.js:47:13)
at setupAddon (d:\vscode\crucian\crucian-vue-ui\node_modules\vue-cli-plugin-i18n\ui.js:94:21)
at api.onPluginReload.project (d:\vscode\crucian\crucian-vue-ui\node_modules\vue-cli-plugin-i18n\ui.js:117:7)
at fns.forEach.fn (C:\Users\jkiwen\AppData\Roaming\npm\node_modules@vue\cli\node_modules_@[email protected]@@VUE\cli-ui\apollo-server\connectors\plugins.js:255:21)
at Array.forEach ()
at callHook (C:\Users\jkiwen\AppData\Roaming\npm\node_modules@vue\cli\node_modules_@[email protected]@@VUE\cli-ui\apollo-server\connectors\plugins.js:255:7)
at Timeout.setTimeout [as _onTimeout] (C:\Users\jkiwen\AppData\Roaming\npm\node_modules@vue\cli\node_modules_@[email protected]@@VUE\cli-ui\apollo-server\connectors\plugins.js:201:9)
at ontimeout (timers.js:424:11)
at tryOnTimeout (timers.js:288:5)

then I saw the code of ui.js the code set the "localeDir" as absolute path "src"

function setupAddon (path, options) {
debug(setupAddon: path -> ${path}, options -> ${options})
const localeDir = options.localeDir
setSharedData('order', 'asc')
const env = readEnv(${path}/.env)
const current = env['VUE_APP_I18N_LOCALE'] || 'en'
const defaultLocale = env['VUE_APP_I18N_FALLBACK_LOCALE'] || 'en'
setSharedData('current', defaultLocale)
setSharedData('defaultLocale', defaultLocale)
debug(setupAddon: current -> ${current}, defaultLocale -> ${defaultLocale})
const locales = getLocales(${path}/src/${localeDir})
setSharedData('locales', locales)
const messages = getLocaleMessages(${path}/src/${localeDir}, locales)
setSharedData('localeMessages', messages)
setSharedData('localePaths', getLocalePaths(messages))
}
const localePath = ${currentProject.path}/src/${currentConfig.localeDir}

So, the path 'src' can be used relative path ??
Or, How can I use the relative path in the project?

Plugin options namespaced doesn't works with enableInSFC

Can you add enableInSFC support inside i18n: {} options?
I guess that this option dont recognize inside i18n options object. To solve I go back to outside, like this in my vue.config.js:

module.exports = {
  // ...
  pluginOptions: {
    i18n: {
      locale: 'en', 
      fallbackLocale: 'en', 
      localeDir: 'i18n/locales/messages',
      enableInSFC: true // This Doesn't works!
    },
    enableInSFC: true // This Works!
  }
}

Scroll issue on vue i18n service in vue ui

vue-i18n, vue-cli-plugin-i18n version

ex: 8.11.2, 0.6.0

Steps to reproduce

Run vue ui go to Localizations tab create some item until to the end of the page you can see the page doesn't scroll

For a fix, add overflow: auto to class project-localizations router-view

@kazupon

Installation fails if tsconfig.json contains comment

Since tsconfig.json allows comments (and trailing commas), some tsconfig.json cannot be parsed by JSON.parse().
https://github.com/kazupon/vue-cli-plugin-i18n/blob/master/generator/index.js#L136-L141

I found some libraries which can parse JSON with comments, but I'm not sure which one is suitable.

Vue UI Project Localizations some problems

Hey, I found Project Localizations on the vue ui page.
It is very convenient.
However, there are some problems.

First:
Click the "Add Path" button, I can type project.name, but change it to project.otherName and it will not be saved.

the second:
When I changed from path1 to path2, the other language file did not change. I don't know if this is in line with expectations.

The third:
Editing will cause the list order to change. I think this will interfere with the experience of continuous editing.

'vue)'' is not recognized as an internal or external command

System

  • vuecli 4.1.2
  • yarn 1.21.1
  • OS Windows 10

Steps to reproduce

  1. vue create -d -n repro

  2. cd repro

  3. vue add i18n

  4. Setup with

    • locale: en,
    • fallback: en,
    • localization directory: locales,
    • enable locale on single file component: yes
  5. yarn run i18n:report

Expected behavior

Scan files and report missing / unused localization

Actual Behavior

$ vue-cli-service i18n:report --src './src/**/*.?(js|vue)' --locales './src/locales/**/*.json'
'vue)'' is not recognized as an internal or external command,
operable program or batch file.
error Command failed with exit code 255.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.

Error installing plugin with message 'Error: Line 16: Unexpected token let'

I've read other issues and believe this error is similar but sufficiently different from other reported cases, including this one here: #9,

Running vue add i18n fails to complete (the generator???) on a real project that I am building. If I generate just a blank project with minimal options as the default then the plugin installs OK; however, this isn't my reality becuase I am working on a Production app. The real noteworthy differences I can discern between an empty project and mine, is that my real project has a few other components such as vuex, vuetify, and typescript and completed vue components -- that I need to localize.

Hope you can help.
package.txt

I've attached my package.json (as package.txt since package.json was blocked) in case it helps pinpoint the versions of other plugins I am using. I'd appreciate your input on what I am doing wrong or a fix.

My environment: OSX Mojave, Node 10.3.0,
Error log:

$ vue add i18n

πŸ“¦  Installing vue-cli-plugin-i18n...

+ [email protected]
added 5 packages from 3 contributors and audited 40202 packages in 15.011s
found 6 vulnerabilities (1 low, 4 high, 1 critical)
  run `npm audit fix` to fix them, or `npm audit` for details
βœ”  Successfully installed plugin: vue-cli-plugin-i18n

? The locale of project localization. en
? The fallback locale of project localization. en
? The directory where store localization messages of project. It's stored under `src` directory. locales
? Enable locale messages in Single file components ? No

πŸš€  Invoking generator for vue-cli-plugin-i18n...
 ERROR  Error: Line 16: Unexpected token let
Error: Line 16: Unexpected token let
    at ErrorHandler.constructError (/Users/calvinnguyen/.nvm/versions/node/v10.3.0/lib/node_modules/@vue/cli/node_modules/esprima/dist/esprima.js:5012:22)
    at ErrorHandler.createError (/Users/calvinnguyen/.nvm/versions/node/v10.3.0/lib/node_modules/@vue/cli/node_modules/esprima/dist/esprima.js:5028:27)
    at Parser.unexpectedTokenError (/Users/calvinnguyen/.nvm/versions/node/v10.3.0/lib/node_modules/@vue/cli/node_modules/esprima/dist/esprima.js:1985:39)
    at Parser.throwUnexpectedToken (/Users/calvinnguyen/.nvm/versions/node/v10.3.0/lib/node_modules/@vue/cli/node_modules/esprima/dist/esprima.js:1995:21)
    at Parser.consumeSemicolon (/Users/calvinnguyen/.nvm/versions/node/v10.3.0/lib/node_modules/@vue/cli/node_modules/esprima/dist/esprima.js:2297:23)
    at Parser.parseLabelledStatement (/Users/calvinnguyen/.nvm/versions/node/v10.3.0/lib/node_modules/@vue/cli/node_modules/esprima/dist/esprima.js:4029:19)
    at Parser.parseStatement (/Users/calvinnguyen/.nvm/versions/node/v10.3.0/lib/node_modules/@vue/cli/node_modules/esprima/dist/esprima.js:4122:97)
    at Parser.parseStatementListItem (/Users/calvinnguyen/.nvm/versions/node/v10.3.0/lib/node_modules/@vue/cli/node_modules/esprima/dist/esprima.js:3393:31)
    at Parser.parseScript (/Users/calvinnguyen/.nvm/versions/node/v10.3.0/lib/node_modules/@vue/cli/node_modules/esprima/dist/esprima.js:4723:29)
    at Object.parse (/Users/calvinnguyen/.nvm/versions/node/v10.3.0/lib/node_modules/@vue/cli/node_modules/esprima/dist/esprima.js:122:61)

Please update vue-i18n-extract

Please update the vue-i18n-extract dependency to 1.0.2 or higher.
The new version has some fixes which makes the i18n report more reliable.

vue-cli-plugin-i18n should not rely on vue.config.js

Description of Problem

If vue-clie-plugin-i18n is installed and you move all of your configuration to package.json, the following error is thrown when you run vue ui.

(node:10494) UnhandledPromiseRejectionWarning: Error: Cannot find module '/apps/vue-sr-interview/vue.config'
    at Function.Module._resolveFilename (internal/modules/cjs/loader.js:582:15)
    at Function.Module._load (internal/modules/cjs/loader.js:508:25)
    at Module.require (internal/modules/cjs/loader.js:637:17)
    at require (internal/modules/cjs/helpers.js:22:18)
    at api.onPluginReload.project (/apps/vue-sr-interview/node_modules/vue-cli-plugin-i18n/ui.js:111:25)
    at fns.forEach.fn (/Users/idoub/.nvm/versions/node/v10.15.3/lib/node_modules/@vue/cli/node_modules/@vue/cli-ui/apollo-server/connectors/
plugins.js:282:21)
    at Array.forEach (<anonymous>)
    at callHook (/Users/idoub/.nvm/versions/node/v10.15.3/lib/node_modules/@vue/cli/node_modules/@vue/cli-ui/apollo-server/connectors/plugin
s.js:282:7)
    at Timeout.setTimeout [as _onTimeout] (/Users/idoub/.nvm/versions/node/v10.15.3/lib/node_modules/@vue/cli/node_modules/@vue/cli-ui/apoll
o-server/connectors/plugins.js:212:9)
    at process._tickCallback (internal/process/next_tick.js:68:7)
(node:10494) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async func
tion without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 1)
(node:10494) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handl
ed will terminate the Node.js process with a non-zero exit code.

From the documentation, the "vue" field in package.json is valid configuration.

Steps to Reproduce

  1. Create a new simple vue-cli project.
  2. Open vue ui, install and configure vue-clie-plugin-i18n.
  3. Delete vue.config.js and add the following to package.json
  "vue": {
    "i18n": {
      "locale": "en",
      "fallbackLocale": "en",
      "localeDir": "locales",
      "enableInSFC": false
    }
  }
  1. Restart vue ui and go to "Plugins". Error will print to console and page will fail to load.

Temporary Fix

Add a blank vue.config.js file (it does not need any content).

not work enalbeInSFC

vue-cli 3.0 beta 10

vue inspect:

{
  context: '/home/squall/projects/mod',
  mode: 'development',
  devtool: 'cheap-module-eval-source-map',
  node: {
    setImmediate: false,
    process: 'mock',
    dgram: 'empty',
    fs: 'empty',
    net: 'empty',
    tls: 'empty',
    child_process: 'empty'
  },
  output: {
    path: '/home/squall/projects/mod/dist',
    filename: '[name].js',
    publicPath: '/'
  },
  resolve: {
    symlinks: true,
    alias: {
      '@': '/home/squall/projects/mod/src',
      vue$: 'vue/dist/vue.runtime.esm.js'
    },
    extensions: [
      '.js',
      '.jsx',
      '.vue',
      '.json'
    ],
    modules: [
      'node_modules',
      '/home/squall/projects/mod/node_modules',
      '/home/squall/projects/mod/node_modules/@vue/cli-service/node_modules'
    ]
  },
  resolveLoader: {
    modules: [
      'node_modules',
      '/home/squall/projects/mod/node_modules',
      '/home/squall/projects/mod/node_modules/@vue/cli-service/node_modules'
    ],
    symlinks: true
  },
  module: {
    noParse: /^(vue|vue-router|vuex|vuex-router-sync)$/,
    rules: [
      {
        test: /\.vue$/,
        use: [
          {
            loader: 'vue-loader',
            options: {
              compilerOpitons: {
                preserveWhitespace: false
              },
              loaders: {
                i18n: '@kazupon/vue-i18n-loader'
              }
            }
          }
        ]
      },
      {
        test: /\.(png|jpe?g|gif)(\?.*)?$/,
        use: [
          {
            loader: 'url-loader',
            options: {
              limit: 10000,
              name: 'img/[name].[hash:8].[ext]'
            }
          }
        ]
      },
      {
        test: /\.(svg)(\?.*)?$/,
        use: [
          {
            loader: 'file-loader',
            options: {
              name: 'img/[name].[hash:8].[ext]'
            }
          }
        ]
      },
      {
        test: /\.(mp4|webm|ogg|mp3|wav|flac|aac)(\?.*)?$/,
        use: [
          {
            loader: 'url-loader',
            options: {
              limit: 10000,
              name: 'media/[name].[hash:8].[ext]'
            }
          }
        ]
      },
      {
        test: /\.(woff2?|eot|ttf|otf)(\?.*)?$/i,
        use: [
          {
            loader: 'url-loader',
            options: {
              limit: 10000,
              name: 'fonts/[name].[hash:8].[ext]'
            }
          }
        ]
      },
      {
        test: /\.pug$/,
        use: [
          {
            loader: 'pug-plain-loader'
          }
        ]
      },
      {
        test: /\.css$/,
        oneOf: [
          {
            resourceQuery: /module/,
            use: [
              {
                loader: 'vue-style-loader',
                options: {
                  sourceMap: false,
                  shadowMode: false
                }
              },
              {
                loader: 'css-loader',
                options: {
                  minimize: false,
                  sourceMap: false,
                  importLoaders: 1,
                  modules: true,
                  localIdentName: '[name]_[local]_[hash:base64:5]'
                }
              },
              {
                loader: 'postcss-loader',
                options: {
                  sourceMap: false
                }
              }
            ]
          },
          {
            use: [
              {
                loader: 'vue-style-loader',
                options: {
                  sourceMap: false,
                  shadowMode: false
                }
              },
              {
                loader: 'css-loader',
                options: {
                  minimize: false,
                  sourceMap: false,
                  importLoaders: 1
                }
              },
              {
                loader: 'postcss-loader',
                options: {
                  sourceMap: false
                }
              }
            ]
          }
        ]
      },
      {
        test: /\.scss$/,
        oneOf: [
          {
            resourceQuery: /module/,
            use: [
              {
                loader: 'vue-style-loader',
                options: {
                  sourceMap: false,
                  shadowMode: false
                }
              },
              {
                loader: 'css-loader',
                options: {
                  minimize: false,
                  sourceMap: false,
                  importLoaders: 2,
                  modules: true,
                  localIdentName: '[name]_[local]_[hash:base64:5]'
                }
              },
              {
                loader: 'postcss-loader',
                options: {
                  sourceMap: false
                }
              },
              {
                loader: 'sass-loader',
                options: {
                  sourceMap: false
                }
              }
            ]
          },
          {
            use: [
              {
                loader: 'vue-style-loader',
                options: {
                  sourceMap: false,
                  shadowMode: false
                }
              },
              {
                loader: 'css-loader',
                options: {
                  minimize: false,
                  sourceMap: false,
                  importLoaders: 2
                }
              },
              {
                loader: 'postcss-loader',
                options: {
                  sourceMap: false
                }
              },
              {
                loader: 'sass-loader',
                options: {
                  sourceMap: false
                }
              }
            ]
          }
        ]
      },
      {
        test: /\.sass$/,
        oneOf: [
          {
            resourceQuery: /module/,
            use: [
              {
                loader: 'vue-style-loader',
                options: {
                  sourceMap: false,
                  shadowMode: false
                }
              },
              {
                loader: 'css-loader',
                options: {
                  minimize: false,
                  sourceMap: false,
                  importLoaders: 2,
                  modules: true,
                  localIdentName: '[name]_[local]_[hash:base64:5]'
                }
              },
              {
                loader: 'postcss-loader',
                options: {
                  sourceMap: false
                }
              },
              {
                loader: 'sass-loader',
                options: {
                  sourceMap: false,
                  indentedSyntax: true
                }
              }
            ]
          },
          {
            use: [
              {
                loader: 'vue-style-loader',
                options: {
                  sourceMap: false,
                  shadowMode: false
                }
              },
              {
                loader: 'css-loader',
                options: {
                  minimize: false,
                  sourceMap: false,
                  importLoaders: 2
                }
              },
              {
                loader: 'postcss-loader',
                options: {
                  sourceMap: false
                }
              },
              {
                loader: 'sass-loader',
                options: {
                  sourceMap: false,
                  indentedSyntax: true
                }
              }
            ]
          }
        ]
      },
      {
        test: /\.less$/,
        oneOf: [
          {
            resourceQuery: /module/,
            use: [
              {
                loader: 'vue-style-loader',
                options: {
                  sourceMap: false,
                  shadowMode: false
                }
              },
              {
                loader: 'css-loader',
                options: {
                  minimize: false,
                  sourceMap: false,
                  importLoaders: 2,
                  modules: true,
                  localIdentName: '[name]_[local]_[hash:base64:5]'
                }
              },
              {
                loader: 'postcss-loader',
                options: {
                  sourceMap: false
                }
              },
              {
                loader: 'less-loader',
                options: {
                  sourceMap: false
                }
              }
            ]
          },
          {
            use: [
              {
                loader: 'vue-style-loader',
                options: {
                  sourceMap: false,
                  shadowMode: false
                }
              },
              {
                loader: 'css-loader',
                options: {
                  minimize: false,
                  sourceMap: false,
                  importLoaders: 2
                }
              },
              {
                loader: 'postcss-loader',
                options: {
                  sourceMap: false
                }
              },
              {
                loader: 'less-loader',
                options: {
                  sourceMap: false
                }
              }
            ]
          }
        ]
      },
      {
        test: /\.styl(us)?$/,
        oneOf: [
          {
            resourceQuery: /module/,
            use: [
              {
                loader: 'vue-style-loader',
                options: {
                  sourceMap: false,
                  shadowMode: false
                }
              },
              {
                loader: 'css-loader',
                options: {
                  minimize: false,
                  sourceMap: false,
                  importLoaders: 2,
                  modules: true,
                  localIdentName: '[name]_[local]_[hash:base64:5]'
                }
              },
              {
                loader: 'postcss-loader',
                options: {
                  sourceMap: false
                }
              },
              {
                loader: 'stylus-loader',
                options: {
                  sourceMap: false,
                  preferPathResolver: 'webpack'
                }
              }
            ]
          },
          {
            use: [
              {
                loader: 'vue-style-loader',
                options: {
                  sourceMap: false,
                  shadowMode: false
                }
              },
              {
                loader: 'css-loader',
                options: {
                  minimize: false,
                  sourceMap: false,
                  importLoaders: 2
                }
              },
              {
                loader: 'postcss-loader',
                options: {
                  sourceMap: false
                }
              },
              {
                loader: 'stylus-loader',
                options: {
                  sourceMap: false,
                  preferPathResolver: 'webpack'
                }
              }
            ]
          }
        ]
      },
      {
        test: /\.jsx?$/,
        exclude: [
          function () { /* omitted long function */ }
        ],
        use: [
          {
            loader: 'cache-loader',
            options: {
              cacheDirectory: '/home/squall/projects/mod/node_modules/.cache/cache-loader'
            }
          },
          {
            loader: 'babel-loader'
          }
        ]
      },
      {
        enforce: 'pre',
        test: /\.(vue|(j|t)sx?)$/,
        exclude: [
          /node_modules/,
          '/home/squall/projects/mod/node_modules/@vue/cli-service/lib'
        ],
        use: [
          {
            loader: 'eslint-loader',
            options: {
              extensions: [
                '.js',
                '.vue'
              ],
              envs: [
                'node'
              ],
              rules: {
                'no-console': 'off',
                'no-debugger': 'off'
              },
              parserOptions: {
                parser: '/home/squall/projects/mod/node_modules/babel-eslint/lib/index.js'
              },
              emitWarning: true,
              formatter: function () { /* omitted long function */ }
            }
          }
        ]
      }
    ]
  },
  plugins: [
    /* VueLoaderPlugin */ {},
    /* DefinePlugin */ {
      definitions: {
        'process.env': {
          NODE_ENV: '"development"',
          BASE_URL: '"/"'
        }
      }
    },
    /* CaseSensitivePathsPlugin */ {
      options: {},
      pathCache: {},
      fsOperations: 0,
      primed: false
    },
    /* FriendlyErrorsWebpackPlugin */ {
      compilationSuccessInfo: {},
      onErrors: undefined,
      shouldClearConsole: true,
      formatters: [
        function () { /* omitted long function */ },
        function () { /* omitted long function */ },
        function () { /* omitted long function */ },
        function () { /* omitted long function */ }
      ],
      transformers: [
        function () { /* omitted long function */ },
        function () { /* omitted long function */ },
        function () { /* omitted long function */ },
        function () { /* omitted long function */ }
      ]
    },
    /* HotModuleReplacementPlugin */ {
      options: {},
      multiStep: undefined,
      fullBuildTimeout: 200,
      requestTimeout: 10000
    },
    /* NamedModulesPlugin */ {
      options: {}
    },
    /* NoEmitOnErrorsPlugin */ {},
    /* ProgressPlugin */ {
      profile: undefined,
      handler: undefined
    },
    /* HtmlWebpackPlugin */ {
      options: {
        template: '/home/squall/projects/mod/public/index.html',
        templateParameters: function () { /* omitted long function */ },
        filename: 'index.html',
        hash: false,
        inject: true,
        compile: true,
        favicon: false,
        minify: false,
        cache: true,
        showErrors: true,
        chunks: 'all',
        excludeChunks: [],
        chunksSortMode: 'auto',
        meta: {},
        title: 'Webpack App',
        xhtml: false
      }
    },
    /* PreloadPlugin */ {
      options: {
        rel: 'preload',
        include: 'initial',
        excludeHtmlNames: [],
        fileBlacklist: [
          /\.map$/,
          /hot-update\.js$/
        ]
      }
    },
    /* PreloadPlugin */ {
      options: {
        rel: 'prefetch',
        include: 'asyncChunks',
        excludeHtmlNames: [],
        fileBlacklist: [
          /\.map/
        ]
      }
    },
    {
      apply: function () { /* omitted long function */ }
    }
  ],
  entry: {
    app: [
      './src/main.js'
    ]
  }
}

Error:

 error  in ./src/patch/name.json?vue&type=custom&index=0&blockType=i18n

Module parse failed: Unexpected token i in JSON at position 0

Missing translation CI

The library is already warning on the console about missing translations.

This is great, but I would like to setup a check on GitLab CI.

Is it planned to have a CLI checker?

Thanks.

Exit code if there are missing or unused keys

Would be nice if vue-cli-service i18n:report command would have non-zero exit code if there are missing or unused keys. And also option to check only fallback locale (or specific locale) so that it would be possible to reuse this command in CI

How can I using yaml format in locale files instead of json format?

I use the yml format instead of the json format in the locale file because it is very simple to write.

// i18n.js
function loadLocaleMessages () {
  const locales = require.context('./locales', true, /[a-z0-9]+\.yml$/i)
  // ...
}

But I got these warnings when I load yml format file

image

Can you give me some advice? Thanks :)

Allow fallback of keys when value is empty.

When you add a new key It will add on the others locales with the same key and an empty string value, this behavior is good for development, but production you want allow to fallback to the fallbackLocale.

I think the default value should be null,

https://github.com/kazupon/vue-cli-plugin-i18n/blob/dev/ui.js#L136

additional[path] = null // set default

or in the file i18n.ts

messages[locale] = process.env.NODE_ENV !== 'production' &&  locales(key) || removeEmpty(locales(key));


// ....
// simple recursive remove keys with empty value
const removeEmpty = (obj: object | any): object =>
  Object.keys(obj)
    .filter((k: string) => obj[k] !== null && obj[k] !== undefined && obj[k] !== '') // Remove undef. and null and empty.string.
    .reduce(
      (newObj, k) =>
        typeof obj[k] === 'object'
          ? Object.assign(newObj, { [k]: removeEmpty(obj[k]) }) // Recurse.
          : Object.assign(newObj, { [k]: obj[k] }), // Copy value.
      {},
    );

I can do a PR if agreed

How can I configure vue loader in addition to cssLoaders

In my webpack, vue loader is already configured as follows:

//In webpack.base.conf.js
const vueLoaderConfig = require('./vue-loader.conf')
module.exports = {
module: {
rules: [
...(config.dev.useEslint ? [createLintingRule()] : []),
{
test: /.vue$/,
loader: 'vue-loader',
options: vueLoaderConfig
},}
]}

//In vue-loader.conf.js
module.exports = {
loaders: utils.cssLoaders({
sourceMap: sourceMapEnabled,
extract: isProduction,
})
}

Now the problem is: how can I change the configuration to include
i18n: '@kazupon/vue-i18n-loader' to webpack.base.conf.js without removing vueLoaderConfig?

Please can someone help? Thanks.

vue-i18n-service

Hi @kazupon,

First of all great plugin! Keep up good work!

Our translation team wants "one file" to translate all the documents. And making them all global is not manageable, my global translation file becomes a mess.

So I made an extension to extract all the <i18n> tags into a file, and after bulk edit in one file, distribute them back to the .vue files. It's named vue-i18n-service (https://github.com/f/vue-i18n-service)

It uses Vue's template compiler to parse .vue files and extract <i18n> tags.

cd /my/vue/project
npx vue-i18n-service export > translations.json

generates an output like:

{
  "src/components/Hello.vue": {
    "en": {
      "hello": "Hello"
    },
    "tr": {
      "hello": "Merhaba"
    }
  },
  "src/views/World.vue": {
    "en": {
      "world": "World"
    },
    "tr": {
      "world": "DΓΌnya"
    }
  }
}

And after editing this file, you can simply change all the files by running

npx vue-i18n-service import < translations.json

And TA-DA! Done. All of your files were updated :)

I'm asking if the plugin interface would support this by opening a code editor and saving it?

Localization route - overflow-y is not scrollable

Version

3.2.1

Steps to reproduce

Create a demo project
install i18n (https://kazupon.github.io/vue-i18n/)
go to http://localhost:8000/addon/org.kazupon.vue-i18n/
create enough messages to fill your screen height
try to scroll

What is expected?

The window should be scrollable

What is actually happening?

The window is not scrollable


It is fixable by adding overflow-y: scroll; to element
<div data-v-7ba5bd90="" data-v-2a0d3bdd="" class="project-localizations router-view">

.json files can't be editied manually?

Maybe it's a mistake on my part but when I try to add translation strings (e.g. in en.json or de.json) and save the file I get a module not found exception. If I add a string in the vue ui however, it works. For me that's not practical however. Am I missing something? :)

Working example

Could you please show me how to use this plugin? I added it to my project using vue-cli (ui). Everything seems to be setup OK, i for the live of me, I can't figure out how to use and i cant find any docs.
In my main.js:
new Vue({ router, i18n, render: h => h(App) }).$mount('#app');

In my App, it doesnt know i18n.
Property or method "i18n" is not defined on the instance but referenced during render.
(I think I should use i18n.messages...?)
Is there any example somewhere?

Option for longer columns

We have hundreds of language keys and some of them are relatively long
This leads to a report like this:

...
β”‚ 1… β”‚ en         β”‚ /src/views/**************/Overview/Ov… β”‚ 9      β”‚ ***************.overview.cr… β”‚
...

(* = censored)

Can we define an option to define longer columns?

Generator error

Hello!

Thanks for awesome library. Unfortunately, I can't use it with vue-cli, because of the following error. I'm getting this when running: vue add i18n:

 ERROR  Error: Line 81: Unexpected reserved word
Error: Line 81: Unexpected reserved word
    at ErrorHandler.constructError (/Users/findutnyy/.node/11.6.0/lib/node_modules/@vue/cli/node_modules/esprima/dist/esprima.js:5012:22)
    at ErrorHandler.createError (/Users/findutnyy/.node/11.6.0/lib/node_modules/@vue/cli/node_modules/esprima/dist/esprima.js:5028:27)
    at Parser.unexpectedTokenError (/Users/findutnyy/.node/11.6.0/lib/node_modules/@vue/cli/node_modules/esprima/dist/esprima.js:1985:39)
    at Parser.throwUnexpectedToken (/Users/findutnyy/.node/11.6.0/lib/node_modules/@vue/cli/node_modules/esprima/dist/esprima.js:1995:21)
    at Parser.parsePrimaryExpression (/Users/findutnyy/.node/11.6.0/lib/node_modules/@vue/cli/node_modules/esprima/dist/esprima.js:2390:38)
    at Parser.inheritCoverGrammar (/Users/findutnyy/.node/11.6.0/lib/node_modules/@vue/cli/node_modules/esprima/dist/esprima.js:2285:37)
    at Parser.parseLeftHandSideExpressionAllowCall (/Users/findutnyy/.node/11.6.0/lib/node_modules/@vue/cli/node_modules/esprima/dist/esprima.js:2899:26)
    at Parser.inheritCoverGrammar (/Users/findutnyy/.node/11.6.0/lib/node_modules/@vue/cli/node_modules/esprima/dist/esprima.js:2285:37)
    at Parser.parseUpdateExpression (/Users/findutnyy/.node/11.6.0/lib/node_modules/@vue/cli/node_modules/esprima/dist/esprima.js:3004:26)
    at Parser.parseUnaryExpression (/Users/findutnyy/.node/11.6.0/lib/node_modules/@vue/cli/node_modules/esprima/dist/esprima.js:3048:26)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.