potojs-loader
v1.0.3
Published
Convert translate po file into a javascript's dictionary
Downloads
2
Maintainers
Readme
npm install --save-dev potojs-loader
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