topbuzz-i18n-webpack-plugin

1.1.2 • Public • Published

i18n Plugin

i18n (localization) plugin for Webpack.

Install

npm i -D topbuzz-i18n-webpack-plugin

Usage

This plugin will extract all text items for i18n into different files, classify with different js packages. example:

{
  "js/pgc/signin": {
    "PasswordLengthWrong": "パスワードは、6文字以上が必要です",
    "PasswordSpaceWrong": "パスワードの最初と最後にスペースを使うことはできませんが、それ以外の場所には使うことができます",
    "SignMethodEmail": "Emailで無料会員登録する"
  },
  "js/pgc/fault": {
    "ErrorWhoops": "...あれ?...",
    "Error404": "該当するページは見つかりませんでした。",
    "Error500": "エラーが発生しました。再度お試しください。",
    "GoHome": "ホームへ"
  }
}

the package name is the some as webpack entry file

Options

plugins: [
  ...
  new I18nPlugin(languageConfig, optionsObj)
],
  • optionsObj.objectName: the default value is __, you can change it to other function name.
  • optionsObj.devPath: the default value is ./, which defalut path to write files, when start in webpack dev server.
  • optionsObj.outputPath: the default value is output path in webpack config, which defalut path to write files.
  • optionsObj.fileMap: the default value is {}, which will map the text items in different files into the same one.

objectName is different when you use import(es6 commonjs) or require; require i18n file just set modules name,

example

  new I18nPlugin(localization, {
    devPath: './output_source',
    objectName: '_localization2.default',
    fileMap: {
      'js/pgc/earning-setting': 'js/pgc/revenue',
      'js/pgc/earning-billing': 'js/pgc/revenue',
      'js/pgc/earning-contract': 'js/pgc/revenue',
      'js/pgc/earning-overview': 'js/pgc/revenue',
      'js/pgc/stats-summary': 'js/pgc/statistics',
      'js/pgc/stats-video-analysis': 'js/pgc/statistics',
      'js/pgc/stats-content-detail': 'js/pgc/statistics'
    }
  })

Maintainers


dlutwuwei

Dependents (0)

Package Sidebar

Install

npm i topbuzz-i18n-webpack-plugin

Weekly Downloads

2

Version

1.1.2

License

MIT

Last publish

Collaborators

  • dlutwuwei