i18n-ini-loader

0.2.2 • Public • Published

i18n-ini-loader

Webpack I18n loader based on .ini files.

Installation

npm install i18n-ini-loader

Quickstart

Input:

messages.ini

[hello]
en=Hello, ${name}!
de=Hallo, ${name}!
 
[niceDay]
en=Have a nice day.
de=Hab einen schönen Tag.

Config:

webpack.config.js

module.exports = {
  module: {
    rules: [
      {
        test: /\.ini$/,
        use: [
          {
            loader: 'i18n-ini-loader',
            options: {
              language: 'de',
              failOnMissingTranslation: true
            }
          }
        ]
      }
    ]
  }
}
 
// Note: Since the output of the `i18n-ini-loader` uses ES6 template strings
// and arrow functions (see below), you may want to chain the `babel-loader`
// for ES5 support.
// Check out the `/example` directory for a simple example config.

Output:

module.exports = {
  hello: (name) => `Hallo, ${name}!`,
  niceDay: 'Hab einen schönen Tag.'
}

Usage:

Welcome.jsx

import { hello, niceDay } from './messages.ini'
 
export default function Welcome({ name }) {
  return (
    <div>
      <h1>{hello(name)}</h1>
      <span>{niceDay}</span>
    </div>
  )
}
 
// <div>
//   <h1>Hallo, Mark!</h1>
//   <span>Hab einen schönen Tag.</span>
// </div>

Options

  • language: the language key used for translation (default: en)
  • failOnMissingTranslation: whether an Error should be thrown if missing translations are found (default: true); if false, missing translations will be handled gracefully by returning an empty String ('')

License

WTFPL – Do What the F*ck You Want to Public License.

Made with ❤️ by @MarkTiedemann.

Package Sidebar

Install

npm i i18n-ini-loader

Weekly Downloads

2

Version

0.2.2

License

WTFPL

Last publish

Collaborators

  • marktiedemann