1.0.2 • Published 7 years ago

i18n-json-loader v1.0.2

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

npm node

i18n-json-loader for Webpack

The i18n-json-loader folk from translate-loader. This loader can resolve like color.en-US.json,color.zh-CN.json, they are not need at folder **en_US/,**zh-CN/.

Install

npm install --save-dev i18n-json-loader

Usage

The i18n-json-loader enables you to import/require translation modules that are "aliased" during runtime to specific files, based on browser's locale.

helloworld.js

import labels from "labels_nls.json";

console.debug(`${labels.helloWorld} (${labels.localeName})`);

labels_nls.json

{
    "localeName": "Default",
    "helloWorld": "Hello World"
}

labels_nls.en-GB.json**

{
    "localeName": "English",
    "helloWorld": "Hello World"
}

labels_nls.en-US.json**

{
    "localeName": "English US",
    "helloWorld": "Hello World"
}

labels_nls.es.json**

{
    "localeName": "Español",
    "helloWorld": "Hola Mundo"
}

labels_nls.pt.json**

{
    "localeName": "Português",
    "helloWorld": "Olá Mundo"
}

webpack.config.js

module.exports = {
    module: {
        rules: [{
            test: /_nls\.json$/,
            use: "i18n-json-loader?locales=en;en-US;es;pt"
        }]
    }
};

or

webpack.config.js

module.exports = {
    module: {
        rules: [{
            test: /_nls\.json$/,
            use: [
                {
                    loader: "i18n-json-loader",
                    options: {
                        locales: [ "en", "en-US", "es", "pt" ]
                    }
                }
            ]
        }]
    }
};

Maintainers

| Clay Wang |