1.0.6 • Published 8 years ago

i18n-browser v1.0.6

Weekly downloads
2
License
MIT
Repository
github
Last release
8 years ago

Node.js: i18n-2-browser

Designed to work with webtranslateit.com API.

Initialization

var I18n = require('i18n');
var englishTranslator = new I18n({
  "Hello": "Hallo {{name}}, wie geht es dir heute?"
  "cats": {
    "one": "{{count}} Katze",
    "other": "{{count}} Katzen"
  },
  "dog": {
    "puppy": "Hündchen"  
  } // 1 Katze
});

Basic Translation

var HelloPerson = englishTranslator.__('Hello', {name: "Marcus"});
console.log(HelloPerson); // Hallo Marcus, wie geht es dir heute?

Else Fallback

This is a good practice as it makes sure that at least one version of text will appear.

var HelloPerson = englishTranslator.__(
  'Not a key?',
  {name: "Marcus"}
).else("Hallo {{name}}, wie geht es dir heute?") ;
console.log(HelloPerson); // Hallo Marcus, wie geht es dir heute?

Keys are evaluated

var puppy = englishTranslator.__('dog.puppy');
console.log(puppy); // Hündchen

Plurals

Plurals will be automatically evaluated if the object has keys one and other.

Then it determines the plural based on the count variable passed to it.

Example data:

"cats": {
  "one": "{{count}} Katze",
  "other": "{{count}} Katzen"
}

and the usage:

var one = englishTranslator.__('cats', {count: 1});
var other = englishTranslator.__('cats', {count: 2});
console.log(one); // 1 Katze
console.log(other); // 2 Katzen
1.0.6

8 years ago

1.0.5

8 years ago

1.0.4

8 years ago

1.0.3

8 years ago

1.0.2

8 years ago

1.0.1

8 years ago

1.0.0

8 years ago