forked from sealninja/react-i18nify
-
Notifications
You must be signed in to change notification settings - Fork 0
/
example.js
64 lines (57 loc) · 1.69 KB
/
example.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
var React = require('react');
var ReactDOM = require('react-dom/server');
var I18n = require('react-i18nify').I18n;
var Translate = require('react-i18nify').Translate;
var Localize = require('react-i18nify').Localize;
I18n.setTranslations({
en: {
application: {
title: 'Awesome app with i18n!',
hello: 'Hello, %{name}!'
},
date: {
long: 'MMMM Do, YYYY'
},
export: 'Export %{count} items',
export_0: 'Nothing to export',
export_1: 'Export %{count} item'
},
nl: {
application: {
title: 'Toffe app met i18n!',
hello: 'Hallo, %{name}!'
},
date: {
long: 'D MMMM YYYY'
},
export: 'Exporteer %{count} dingen',
export_0: 'Niks te exporteren',
export_1: 'Exporteer %{count} ding'
}
});
I18n.setLocale('nl');
console.log(I18n.t('application.title'));
console.log(I18n.t('application.hello', {name: 'Aad'}));
console.log(I18n.t('export', {count: 0}));
console.log(I18n.t('application.weird_key'));
console.log(I18n.t('application', {name: 'Aad'}));
console.log(I18n.l(1385856000000, { dateFormat: 'date.long' }));
console.log(I18n.l(Math.PI, { maximumFractionDigits: 2 }));
function AwesomeComponent() {
return (
<div>
<Translate value="application.title" />
<br />
<Translate value="application.hello" name="Aad" />
<br />
<Localize value="2015-09-03" dateFormat="date.long" />
<br />
<Localize value={10/3} options={{style: 'currency', currency: 'EUR', minimumFractionDigits: 2, maximumFractionDigits: 2}} />
<br />
<Translate value="export" count={1} />
<br />
<Translate value="export" count={2} />
</div>
);
}
ReactDOM.renderToString(<AwesomeComponent/>);