GitXplorerGitXplorer
t

i18node

public
65 stars
1 forks
0 issues

Commits

List of commits on branch master.
Unverified
107570d3308fd31d5c9d77d067d3e00e7d2cd17d

Change codestyle and update dependencies

ttalyssonoc committed 10 years ago
Unverified
a38800f091c447714b374213fb7eb47b60922588

Misspelling in code.

ttalyssonoc committed 11 years ago
Unverified
1913b5c07dbc253564d3b3546c669d3fc48083a7

Added the API to README and improved to lookup for the term.

ttalyssonoc committed 11 years ago
Unverified
d8e373c3acfa8dbd841e7734cc9ae8a977aab190

Added hasLocale() method.

ttalyssonoc committed 11 years ago
Unverified
ff6741ef3443dc4990299d3b003be970d21fe08a

When doesn't find the required locale, uses the default one.

ttalyssonoc committed 11 years ago
Unverified
dcdc0124aedc03130718e1f3f2186140cefbf57f

First commit

ttalyssonoc committed 11 years ago

README

The README file for this repository.

I18node

TL;DR: It's an i18n package for Node.js, with support to plurals and genders

Build Status Dependency manager Coverage Status

	$ npm install i18node

Usage:

	var I18Node = require('i18node');
	
	var options = {
		locales: ['en', 'pt'],
		defaultLocale: 'en',
		defaultGender: 'masc',
		path: './locales'
	};

	var i18n = new I18Node(options);

	i18n.i18n('person'); //person
	i18n.i18n('person', 2); //couple
	i18n.i18n('person', 3); //people
	i18n.i18n('person', { num: 2 }); //couple
	i18n.i18n('hello world', { num: 2, greeting: 'hi'}); //hi worlds
	i18n.i18n('hello world', { greeting: 'olá', locale: 'pt'}); //olá mundo
	i18n.i18n('nidorino', { num: 2 }); //nidorinos
	i18n.i18n('nidorino', { gender: 'masc' }); //nidorino
	i18n.i18n('nidorino', { num: 2, gender: 'fem' }); //nidorinas
	i18n.i18n('none', { gender: 'neutral', locale: 'pt' }); //nenhum

And let's say that, inside ./locales folder we have the files:

en.json:

	{
		"person": {
			"1": "person",
			"2": "couple",
			"n": "people"
		},
		"hello word": {
			"1": "{{greeting}} world",
			"n": "{{greeting}} worlds"
		},
		"nidorino": {
			"1" : {
				"masc": "nidorino",
				"fem": "nidorina"
			},
			"n" : {
				"masc": "nidorinos",
				"fem": "nidorinas"
			}
		},
		"none": "none"
	}

pt.json:

	{
		"person": {
			"1": "pessoa",
			"2": "casal",
			"n": "pessoas"
		},
		"hello word": {
			"1": "{{greeting}} mundo",
			"n": "{{greeting}} mundos"
		},
		"none": {
			"neutral": "nenhum",
			"fem": "nenhuma"
		}
	}

Options

  • locales: Array of locale names. Default: ['en'])
  • defaultLocale: Default: 'en'
  • defaultGender: Default: 'neutral'
  • path: Path for the locales folder. Default: './locals'

API

  • setLocale(locale): Set the default locale
  • getLocale(): Return the current default locale
  • setGender(gender): Set the default gender
  • getGender(): Return the current default gender
  • hasLocale(locale): Return if the passed locale is supported
  • i18n(term, data): Return the internationalized term, using the given data