-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathi18n.js
More file actions
38 lines (37 loc) · 2.33 KB
/
Copy pathi18n.js
File metadata and controls
38 lines (37 loc) · 2.33 KB
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
export default function () {
const i18n = {
en: {
won: 'won',
total: 'total',
averageLength: 'average length',
tooHard: 'too difficult?<br>type <code>skip</code>',
rule0: 'Find a <b>valid</b> JavaScript expression',
rule1: 'whose value is <b>(Number)24</b>.',
rule2: 'Each of the four given numerical digits <b>must appear once</b>, and <b>no other</b> digits are allowed.',
rule3: 'Besides digits, <b>only</b> these operators are allowed: <code>+</code> <code>-</code> <code>*</code> <code>/</code> <code>%</code> <code>~</code> <code>&</code> <code>|</code> <code>^</code> <code><<</code> <code>>></code> <code>(</code> <code>)</code> and <code>x</code> <code>o</code>(after a given <code>0</code>).<br><small>* Can you do it like a boss? Try not to use parentheses <code>(</code> <code>)</code>.</small>',
boss: '',
rule4: 'In additional, to avoid <code>-~</code> from appearing continuously, <code>-</code> is <b>not allowed</b> to be used as a unary operator.',
},
zh: {
won: '已获胜',
total: '总局数',
averageLength: '平均长度',
tooHard: '太难了?<br>输入 <code>skip</code>',
rule0: '求一个<b>合法的</b> JavaScript 表达式,',
rule1: '其值为<b>整数 24</b>。',
rule2: '四个给定的数字<b>恰好</b>在表达式中出现一次,未给定数字<b>不允许</b>出现。',
rule3: '除数字外,表达式中<b>仅允许</b>包含下列运算符:<code>+</code> <code>-</code> <code>*</code> <code>/</code> <code>%</code> <code>~</code> <code>&</code> <code>|</code> <code>^</code> <code><<</code> <code>>></code> <code>(</code> <code>)</code> 以及 <code>x</code> <code>o</code>(在给定的 <code>0</code> 后面)。<br><small>* 挑战自己!试着不使用小括号 <code>(</code> <code>)</code>。</small>',
rule4: '另外,为了防止 <code>-~</code> 连续出现,<b>不允许</b>将 <code>-</code> 用作一元运算符。',
},
}
let language = 'en'
for (let i = 0; i < navigator.languages.length; i += 1) {
const lang = navigator.languages[i].toLowerCase()
if (lang in i18n) {
language = lang
break
}
}
document.body.innerHTML =
document.body.innerHTML.replace(/\{\{.*?\}\}/g, match => i18n[language][match.slice(2, -2)])
}