Basic js micro library for i18n, with support for placeholders and multiple plural forms.
~1.8kb
Installation
$ npm install micro-i18n
Usage
Just import it:
If you are using it directly in the browser, you can access it with the i18n global.
Api
We have just two static methods: i18n.setLan(lang : Object)
and i18n.t(key : string, placeholders? : Object)
const enUS = EASY: 'easy' HATE_SOMETHING: 'I hate {{something}}!' REALLY_HATE_SOMETHING: 'I hate {{something}}! I really hate {{something}}!' HATE_SOMETHING_LIKE_THING: 'I hate {{something}}! But I like {{thing}}!' QUANTITY: 0: 'no {{what}}' 1: '1 {{what}}' n: '{{n}} {{what}}' MESSAGES: 0: 'messages' 1: 'message' n: 'messages' const ptBR = EASY: 'fácil' HATE_SOMETHING: 'Eu odeio {{something}}!' REALLY_HATE_SOMETHING: 'Eu odeio {{something}}! Eu realmente odeio {{something}}!' HATE_SOMETHING_LIKE_THING: 'Eu odeio {{something}}! Mas eu gosto de {{thing}}!' QUANTITY: 0: 'nenhum {{what}}' 1: '1 {{what}}' n: '{{n}} {{what}}' MESSAGES: 0: 'mensagens' 1: 'mensagem' n: 'mensagens' i18ni18n //easy
Placeholders
i18n //I hate haters!i18n //I hate haters! I really hate haters!i18n //I hate haters! But I like pizza!
Plural
i18n //messagesi18n //messagei18n //messages
Placeholders + plural
i18n //no ducksi18n //1 ducki18n //10 ducksi18n //10 messages
Setting the lang
i18ni18n //easyi18ni18n //fácil
Fallback
If a key is undefined it will be returned as fallback