0.0.2 • Published 6 years ago
i18next-select-postprocessor v0.0.2
Introduction
A i18next plugin enabling select feature similar to ICU.
Getting Started
# npm package
$ npm install i18next-select-postprocessor
# yarn
$ yarn add i18next-select-postprocessor
Usage
We could using Boolean, String, Number, and Null type to check values.
import i18next from 'i18next';
import SelectPostprocessor from 'i18next-select-postprocessor';
i18next
.use(SelectPostprocessor)
.init(i18nextOptions);
const translation = {
example: {
basic: `$s(female,true,She's a lady.);`,
nested: `$s(female,true,She's a $s(name,"alice",lady.););`,
concat: `$s(female,true,She's a );$s(name,"alice",lady.);`,
withOption: `$s(female,true,She's a {{noun}}.);`
}
};
export default translation;
i18next.t(example.basic,{ "female": true, "postProcess": "select" });
i18next.t(example.nested,{ "female": true, "name": "alice", "postProcess": "select" });
i18next.t(example.concat,{ "female": true, "name": "alice", "postProcess": "select" });
i18next.t(example.withOption, { "female": true, "name": "alice", "noun": "lady", "postProcess": "select" });
// => She's a lady
Online Demo
Change Default Options
import i18next from 'i18next';
import SelectPostprocessor from 'i18next-select-postprocessor';
SelectPostprocessor.updateOptions({
// this are the defaults
regex: /\$s\(([a-zA-Z_\$]+),([^,]+),([^;]*)\);/,
maxReplacementCount: 1000,
});
i18next
.use(SelectPostprocessor)
.init(i18nextOptions);