rollup-plugin-i18n

0.3.1 • Public • Published

rollup-plugin-i18n

Embed your localized text into your bundle.

How to use

In your source code, for example if you have a key called 'msg_hello', to translate it use __('msg_hello')

Config

import i18n from 'rollup-plugin-i18n';
 
export default {
  entry: 'index.js',
  plugins: [
    i18n({
      language: {
        'msg_hello': 'Hello',
        'msg_world': 'World!',
      },
    }),
  ],
}
// index.js
 
console.log(__('msg_hello'), __('msg_world'));
 

Output

Hello World!

Options

  • language: {[key:string]: string}: an object that map from a string key to the localized message

Limitations

Currently we are using a regex to replace all instances of __(<msg>) with their translation. In the future if rollup decides to open up access to the AST we can do a better job of replacement.

Package Sidebar

Install

npm i rollup-plugin-i18n

Weekly Downloads

173

Version

0.3.1

License

MIT

Unpacked Size

101 kB

Total Files

12

Last publish

Collaborators

  • phamtm