Skip to content

Latest commit

 

History

History
101 lines (87 loc) · 2.94 KB

README.md

File metadata and controls

101 lines (87 loc) · 2.94 KB

i18next-scanner-webpack

npm Build Status

This is a simple i18n-scanner webpack-plugin. Based on this package: i18next-parser.

Example webpack.config.js

const path = require('path');
const i18nextWebpackPlugin = require('i18next-scanner-webpack');

module.exports = {
  mode: 'development',
  entry: path.resolve(__dirname, './src/index.js'),
  output: {
    path: path.resolve(__dirname, 'dist'),
    filename: '[name].js'
  },
  plugins: [
    new i18nextWebpackPlugin({
      // src defaults to ./src
      // dest defaults to ./ (project root folder)
      // default ['.js', '.jsx', '.vue']
      extensions: ['.js', '.jsx']
      // See options at https://github.com/i18next/i18next-parser#options
      options: {
        lexers: {
          js: [{
            lexer: 'JavascriptLexer',
            // default ['t']
            functions: ['t', '$t', 'i18next.t', 'i18n.t'],
          }]
        },
        locales: ['en', 'de'],
        // defaults to locales/$LOCALE/$NAMESPACE.json
        output: '$LOCALE/$NAMESPACE.json'
      }
    })
  ]
};

Minimal setup:

const path = require('path');
const i18nextWebpackPlugin = require('i18next-scanner-webpack');

module.exports = {
  mode: 'development',
  entry: path.resolve(__dirname, './src/index.js'),
  output: {
    path: path.resolve(__dirname, 'dist'),
    filename: '[name].js'
  },
  plugins: [
    new i18nextWebpackPlugin({
      options: {
        locales: ['en', 'de']
      }
    })
  ]
};

Faster dev loops:

If async option is true, the plugin will not wait for i18next-scanner to finish before reporting back to webpack. Useful in large projects or when using an expensive transform.

const path = require('path');
const i18nextWebpackPlugin = require('i18next-scanner-webpack');

module.exports = {
  mode: 'development',
  entry: path.resolve(__dirname, './src/index.js'),
  output: {
    path: path.resolve(__dirname, 'dist'),
    filename: '[name].js'
  },
  plugins: [
    new i18nextWebpackPlugin({
      options: {
        locales: ['en', 'de']
      },
      async: true
    })
  ]
};
Name Description default Optional
src source path of files with i18next translations ./src yes
dest destination of translation files ./locales yes
options all options yes
async If true, immediately report back to webpack false yes

Available options: here