1.0.4 • Published 2 years ago

vite-i18n-plugin v1.0.4

Weekly downloads
1
License
MIT
Repository
github
Last release
2 years ago

vite-i18n-plugin

Installing

Using npm:

npm i -D vite-i18n-plugin

Using yarn:

yarn add -D vite-i18n-plugin

Options

  • languageList

    Language list, default: ['cn', 'en']

  • langType

    Current lang, default: cn

  • useLanguage

    Specify the language type that automatically uses the key as the default translation, default: cn

  • autoWriteAble

    Automatically save translation files, default: true

  • formatSpace

    Number of spaces in the translation file json format, default: 2

  • sourcePath

    Translation file path

  • removeUnUseKeys

    Delete non-existent translation, default: false

  • patten

    Match language tag, default ['__'] -> __('')

Getting Started

  • Dev config
// vite.config.js
const { serverI18nPlugin } = require('vite-i18n-plugin');

export default {
  configureServer: [
    serverI18nPlugin({
      langType: 'cn',
      useLanguage: 'cn',
      languageList: ['cn', 'en'],
      sourcePath: 'src/lang/lang.json'
    })
  ],
  ...
}
  • Build config
// build.js
const { build } = require('vite');
const { buildI18nPlugin } = require('vite-i18n-plugin');

build({
  rollupInputOptions: {
    pluginsPreBuild: [
      buildI18nPlugin({
        langType: 'cn',
        useLanguage: 'cn',
        removeUnUseKeys: true,
        languageList: ['cn', 'en'],
        sourcePath: 'src/lang/lang.json'
      })
    ]
  },
  ...
})
  • Using
// index.js

console.log('__("你好")');

// or app.vue

<template>
  <input placeholder="__('你好')" />
</template>
  • Result (src/lang/lang.json)
{
  "你好": {
    "cn": "你好",
    "en": ""
  }
}
1.0.4

2 years ago

1.0.3

3 years ago

1.0.2

3 years ago

1.0.1

3 years ago

1.0.0

3 years ago