potojs-loader

1.0.3 • Public • Published

POtoJS Loader

Transform a .po file to a Javascript Object

Install

npm install --save-dev potojs-loader

Usage

require('./languages/it_IT.po');
 
console.log(__it('Test to translate'));
// Test da tradurre
 
// or (if you have more language ==> alldir = true)
console.log(__('Test to translate', 'it', 'default traduction'))

The function __(testToTranslate, [lang, [default text]]). If the traduction is not defined and the default text is not defined return the "testToTranslate" string

 {
  test: /\.po$/,
  use: [
    {
      loader: 'potojs-loader',
      options: {
        'alldir': false,
        'setName': function (filename) {
          ...
          return language // ex: en | it | es ...
        }
      }
    }
  ],
 }

If the alldir option is set to true, the parser scan all directory of the po file looking for all other po file in the same directory and merge all the translates in only one big javascript object.

You can pass a function for generate a custom "lang" param for every po file with the setName option. By default the "lang" param is the first two character in the language code present in the name of file; example: if the file's name is wp-theme-en_US.po the "lang" param is en

Dependencies (1)

Dev Dependencies (1)

Package Sidebar

Install

npm i potojs-loader

Weekly Downloads

0

Version

1.0.3

License

MIT

Last publish

Collaborators

  • sidmonta