polylang
Small library for handling multi language support using JavaScript
Installation
npm install --save polylang
Usage
const Polylang = ; // or if you are using ES6 imports, import Polylang from 'polylang'; const polylang = ; // create a new instancepolylang;polylang; polylang; // welcomepolylang; // test@test.com is not a valid email because it is too short! polylanglang = 'ro'; polylang; // salutarepolylang; // test@test.com nu este un email valid deoarece este prea scurt!
API
new Polylang({defaultLang, accessDelimiter, startInterpolationDelimiter, endInterpolationDelimiter})
Param | Type | Description |
---|---|---|
{defaultLang | string |
the default language that will be used to translate the text |
accessDelimiter | string |
delimiter used to represent levels in the translation object (ex: 'errors.password.too_short') |
startInterpolationDelimiter | string |
delimiter used to interpolate custom string into the translation at the start of the word |
endInterpolationDelimiter} | string |
delimiter used to interpolate custom string into the translation at the start of the word |
Example
polylang = defaultLang: 'en' accessDelimiter: '.' startInterpolationDelimiter: '<<' endInterpolationDelimiter: '>>';
polylang.add(language, data)
Add a translation
Kind: instance method of Polylang
Param | Type | Description |
---|---|---|
language | string |
language |
data | object |
translation object |
Example
polylang;
polylang.remove(language)
Remove a translation
Kind: instance method of Polylang
Param | Type | Description |
---|---|---|
language | string |
language name that wil be removeed |
Example
polylang;
polylang.t(selector, interpolationValues)
Translate
Kind: instance method of Polylang
Param | Type | Description |
---|---|---|
selector | string |
translation path |
interpolationValues | string | object |
value/s to be replaced between interpolation delimiters |
Example
polylang;polylang; //if invalid_email string would be 'The email "<<email>>" is invalid because <<reason>>'
polylang.translate(selector, language, interpolationValues)
Translate in custom language
Kind: instance method of Polylang
Param | Type | Description |
---|---|---|
selector | string |
translation path |
language | string |
translation language |
interpolationValues | string | object |
value/s to be replaced between interpolation delimiters |
Example
polylang;