0.3.9 • Published 2 years ago

webpack-easyi18n v0.3.9

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

webpack-easyi18n

Go from gettext catalog (.po files) to embeded localization in your Webpack bundles.

npm install --save-dev webpack-easyi18n

Designed for use with EasyI18n.

Usage

To localize text in your application, surround your strings with [[ and ]] markup characters to mark them as translatable. We call these snippets 'nuggets':

document.write("[[[Login using]]]");

Make your translations (for example using Poedit) to create the .po files

Add the easy plugin to your Webpack config (notice the 'Locales' variable that indicates language/.po location):

const Path = require("path");
const Webpack = require("webpack");
const EasyI18nPlugin = require("webpack-easyi18n");

var Locales = {
    "en-gb": null, // Your application default language
    "pt-br": "pt-BR/messages.po"
};

module.exports = Object.keys(Locales).map(function(locale) {

    var plugins = [];

    return {
        entry: Path.join(__dirname, "src", "index"),
        devtool: "source-map",
        output: {
            filename: Locales[locale] === null ? "js/[name].[hash].js" : "js/[name].[hash]." + locale + ".js",
            path: Path.join(__dirname, "dist"),
            publicPath: ""
        },
        plugins: plugins.concat([
            new EasyI18nPlugin([locale, Locales[locale]], {
                srcPath: Path.join(__dirname, "./src"),
                localesPath: Path.join(__dirname, "./Locale")
            })
        ])
    };
});

Options

NameTypeDescription
srcPath{String}Directory that should be used to locate your source files with strings for replacement (required)
localesPath{String}Directory containing the po files as referenced by 'Locales' (required)
alwaysRemoveBrackets{Boolean}If alwaysRemoveBrackets is true and a nugget is missing a translation, then the original string is retained but the brackets are removed (default:false)
warnOnMissingTranslations{Boolean}If warnOnMissingTranslations is true a warning will be displayed on build if a nugget is missing a translation (default:true)
excludeUrls{String[]}If a filepath contains any of the strings contained in this array, it will not be processed (default:null)
includeUrls{String[]}If a filepath does not contains any of the strings contained in this array, it will not be processed (default:null)

A 'webpack-easyi18n-temp' directory beneath you locales directory is created on each Webpack build. There is no need to deploy this directory to production and can be removed, for example using rimraf and the WebpackShellPlugin:

new WebpackShellPlugin({ onBuildStart: ['echo "Webpack Start"'], onBuildEnd: ['rimraf ./locales/webpack-easyi18n-temp'] })
0.3.9

2 years ago

0.3.8

2 years ago

0.3.7

3 years ago

0.3.6

3 years ago

0.3.5

3 years ago

0.3.4

3 years ago

0.3.2

3 years ago

0.3.1

3 years ago

0.3.3

3 years ago

0.1.14

3 years ago

0.1.15

3 years ago

0.3.0

3 years ago

0.2.0

3 years ago

0.1.16

3 years ago

0.1.17

3 years ago

0.1.18

3 years ago

0.1.19

3 years ago

0.1.12

3 years ago

0.1.13

3 years ago

0.1.10

3 years ago

0.1.11

3 years ago

0.1.9

3 years ago