0.1.0 • Published 3 years ago

mini-locales-extract-plugin v0.1.0

Weekly downloads
-
License
MIT
Repository
github
Last release
3 years ago

MINI-LOCALES-EXTRACT-PLUGIN

This plugin extracts Locales with Chinese into separate files. It creates a locales file which contains JSON.

It builds on top of a new webpack v4 feature (module types) and requires webpack 4 to work.

Getting Started

To begin, you'll need to install mini-locales-extract-plugin:

npm install --save-dev mini-locales-extract-plugin

Then add the loader and the plugin to your webpack config. For example:

webpack.config.js

    const MiniCssExtractPlugin = require('mini-css-extract-plugin');
...
 module: {
    rules: [
      {
        test: /\.tsx?$/,
        use: [
          {
            loader: MiniLocalesExtractPlugin.loader,
            options: {
              extractName: 't',
              cachePath: '/',
              output: 'locales',
              localesName: 'Zn-ch',
              common: true,
              filter: (name) => {
                if (!name) return "";
                let t = name.replace("common", "cm");
                t = t.replace("components", "com");
                t = t.replace("containers", "ct");
                t = t.replace(".service", "");
                t = t.replace(".index", "");
                t = t.toLowerCase();
                return t;
              }
            }
          },
        ]
    }
    
...
...

plugins: [
    new MiniLocalesExtractPlugin(),
  ],
.
..

Plugin Options

| Name | Type | Default | Description | | :

NameTypeDefaultDescription
extractNameStringt
cachePathString/:cwd/node_modules/.cache/
outputString/:locales
localesNameStringzh-cn
commonBooleanfalse
filterFunction() => {}

extractName

Type: String Default: t

i18n_function name

cachePath

Type: String Default: /:cwd/node_modules/.cache/

cache path

output

Type: String Default: /:locales

locales path

localesName

Type: String Default: zh-cn

locales file name

common

Type: Boolean Default: false

use compare multiple projects

filter

Type: String Default: zh-cn

Used to filter keywords. The formal parameter is the currently extracted keyname