-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest.js
More file actions
36 lines (29 loc) · 781 Bytes
/
test.js
File metadata and controls
36 lines (29 loc) · 781 Bytes
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
const i18n = require('./index');
const zh_cn = {
hello: '你好',
welcome: {
toMe: name=> `欢迎,${name}`
}
};
const en = {
hello: 'Hello',
welcome: {
toMe: name=> `Welcome to me, ${name}`,
toYou: (name1, name2)=> `${name1} is ${name2}`
}
};
console.log(i18n('hello') == 'hello');
i18n.setMapper(locale=> {
switch (locale) {
case 'zh-cn':
return zh_cn;
case 'en':
return en;
}
});
console.log(i18n('hello') == 'Hello');
i18n.setLocale('zh-cn');
console.log(i18n('hello') == '你好');
console.log(i18n('welcome.toMe', 'bob') == '欢迎,bob');
console.log(i18n('welcome.toYou', 'bob', 'alan') == 'bob is alan');
console.log(i18n('welcome.toAll', 'bob') == 'welcome.toAll');