Last active
August 29, 2015 14:15
-
-
Save narqo/1d6efe84a60ee48a99dc to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 })); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Привет, Ограрий! | |
У вас вообще камней нет. | |
У вас один камень. | |
У вас два камня. | |
У вас <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