Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/venuu/i18n-js-webpack-plugin
webpack companion plugin for i18n-js to include only used translations
https://github.com/venuu/i18n-js-webpack-plugin
i18n i18n-js rails ruby-on-rails webpack
Last synced: 3 months ago
JSON representation
webpack companion plugin for i18n-js to include only used translations
- Host: GitHub
- URL: https://github.com/venuu/i18n-js-webpack-plugin
- Owner: venuu
- License: mit
- Created: 2018-07-03T12:42:35.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2023-03-02T01:56:15.000Z (almost 2 years ago)
- Last Synced: 2024-09-28T12:04:18.110Z (3 months ago)
- Topics: i18n, i18n-js, rails, ruby-on-rails, webpack
- Language: JavaScript
- Homepage:
- Size: 263 KB
- Stars: 3
- Watchers: 1
- Forks: 0
- Open Issues: 6
-
Metadata Files:
- Readme: README.md
- License: LICENSE.txt
Awesome Lists containing this project
README
# @venuu/i18n-js-webpack-plugin
A webpack companion plugin for [`i18n-js`](https://github.com/fnando/i18n-js/). Output only the translations your code is actually using to your bundle.
[![Build Status][build-badge]][build]
## Installation
This module is distributed via [npm][npm] which is bundled with [node][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
```javascript
// webpack.config.jsconst { 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"
})
]
};
``````javascript
// 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.
```javascript
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
[npm]: https://www.npmjs.com/
[node]: https://nodejs.org
[build-badge]: https://travis-ci.org/venuu/i18n-js-webpack-plugin.svg?branch=master
[build]: https://travis-ci.org/venuu/i18n-js-webpack-plugin