package
i18n with human friendly syntax
npm install babelfishGitHub-flavored package documentation.
Across all versions.
Download trend unavailable.
Runtime metadata.
Tagged topics.
Estimated unpacked size across 2 packages.
184.8 kB
Includes dependencies.
Internationalization with easy syntax for node.js and browser.
Classic solutions use multiple phrases for plurals. Babelfish defines plurals
inline instead - that's more compact, and easy for programmers. Also, phrases
are grouped into nested scopes, like in Ruby.
BabelFish supports all plural rules from unicode CLDR
(via plurals-cldr).
node.js:
$ npm install babelfishbrowser:
$ bower install babelfishUse es5-shim for old browsers compatibility.
#{varname} Echoes value of variable((Singular|Plural1|Plural2)):count Plural formexample:
А у меня в кармане #{nails_count} ((гвоздь|гвоздя|гвоздей)):nails_countYou can also omit anchor variable for plurals, by default it will be count.
Thus following variants are equal:
I have #{count} ((nail|nails))I have #{count} ((nail|nails)):countAlso you can use variables in plural parts:
I have ((#{count} nail|#{count} nails))Need special zero form or overwrite any specific value? No problems:
I have ((=0 no nails|#{count} nail|#{count} nails))If you need #{, ((, | or )) somewhere in text, where it can be considered
as markup part - just escape them with \.
As BabelFish flatten scopes, it's really fun and nice to store translations in YAML files:
---
ru-RU:
profile: Профиль
forums: Форумы
apps:
forums:
new_topic: Новая тема
last_post:
title : Последнее сообщение
by : от
demo:
apples: "На столе лежит #{count} ((яблоко|яблока|яблок))"// Create new instance of BabelFish with default language/locale: 'en-GB'
var BabelFish = require('babelfish');
var i18n = new BabelFish('en-GB');
// Fill in some phrases
i18n.addPhrase('en-GB', 'demo.hello', 'Hello, #{user.name}.');
i18n.addPhrase('en-GB', 'demo.conv.wazup', 'Whats up?');
i18n.addPhrase('en-GB', 'demo.conv.alright', 'Alright, man!');
i18n.addPhrase('en-GB', 'demo.coerce', 'Total: #{count}.');
i18n.addPhrase('ru-RU'
View the LICENSE file (MIT).