Skip to content

Instantly share code, notes, and snippets.

@narqo
Last active August 29, 2015 14:15
Show Gist options
  • Save narqo/1d6efe84a60ee48a99dc to your computer and use it in GitHub Desktop.
Save narqo/1d6efe84a60ee48a99dc to your computer and use it in GitHub Desktop.
if(global.Intl) {
global.Intl = require('intl');
}
var IntlMessageFormat = require('intl-messageformat');
var formats = {
number : {
rur : {
style : 'currency',
currency : 'RUR'
}
}
};
var messages = {
'ru-RU' : {
STONES : 'У вас {num, plural, ' +
'=0 {вообще камней нет.} ' +
'=1 {один камень.} ' +
'=2 {два камня.} ' +
'other {<a href="http://yandex.ru">#</a> новых камней.}}',
EXCH_RATE : 'Биржевой курс камня: {rate, number, rur}'
}
};
var msg = new IntlMessageFormat('Привет, {name}', 'ru-RU');
console.log(msg.format({ name : 'Ограрий!' }));
msg = new IntlMessageFormat(messages['ru-RU'].STONES, 'ru-RU');
console.log(msg.format({ num : 0 }));
console.log(msg.format({ num : 1 }));
console.log(msg.format({ num : 2 }));
console.log(msg.format({ num : 5 }));
console.log(msg.format({ num : 1025 }));
msg = new IntlMessageFormat(messages['ru-RU'].EXCH_RATE, 'en-UK');
console.log(msg.format({ rate : 1078.34 }));
msg = new IntlMessageFormat(messages['ru-RU'].EXCH_RATE, 'ru-RU', formats);
console.log(msg.format({ rate : 3091.12 }));
Привет, Ограрий!
У вас вообще камней нет.
У вас один камень.
У вас два камня.
У вас <a href="http://yandex.ru">5</a> новых камней.
У вас <a href="http://yandex.ru">1 025</a> новых камней.
Биржевой курс камня: 1,078.34
Биржевой курс камня: 3 091,12 р.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment