@venuu/i18n-js-webpack-plugin

2.0.0 • Public • Published

@venuu/i18n-js-webpack-plugin

A webpack companion plugin for i18n-js. Output only the translations your code is actually using to your bundle.


Build Status

Installation

This module is distributed via npm which is bundled with node and should be installed as one of your project's dependencies:

npm install --save @venuu/i18n-js-webpack-plugin

This library has a peerDependencies listing for webpack 4.

Usage

// webpack.config.js

const { I18nRuntimePlugin } = require("@venuu/i18n-js-webpack-plugin");

module.exports = {
  // ...rest of your config
  plugins: [
    // ...any other plugins you might have
    new I18nRuntimePlugin({
      fullTranslations: {
        // Put your entire translations here like below
        en: { hello: { world: "Hello, world!" } },
        fi: { hello: { world: "Hei, maailma!" } },
        sv: { hello: { world: "Och samma på svenska" } }
      },
      // Global calls for I18n translations that will be picked up
      functionNames: ["I18n.t", "I18n.translate"],
      // "Free variable" in your code that will be replaced with object containing all
      // used translations.
      translationPlaceholderConstantName: "I18N_RUNTIME_TRANSLATIONS"
    })
  ]
};
// your-application-entry-point.js

// This assumes you have `I18n` from 'i18n-js' in current scope or available as a global
I18n.translations = I18N_RUNTIME_TRANSLATIONS;

Now, any of your imported modules can call I18n.t or I18n.translate and I18N_RUNTIME_TRANSLATIONS will be replaced with the used translations.

I18n.t("hello.world");
I18n.t("hello.world", { locale: "sv" });
I18n.translate("hello.world");

console.log(I18n.t("hello", { locale: "sv" })); // outputs object: { world: 'Hello, world!' }

LICENSE

MIT

Package Sidebar

Install

npm i @venuu/i18n-js-webpack-plugin

Weekly Downloads

431

Version

2.0.0

License

MIT

Unpacked Size

13.9 kB

Total Files

9

Last publish

Collaborators

  • valscion