This repository has been archived by the owner on Mar 3, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
/
update.js
98 lines (93 loc) · 2.69 KB
/
update.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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
const fs = require('fs')
const path = require('path')
const englishFallback = require('./static/manual/en.json')
module.exports.update = async function update() {
const { generate } = require('pogo-data-generator')
const { translations } = await generate({
template: {
globalOptions: {
includeProtos: true,
},
translations: {
enabled: true,
options: {
prefix: {
pokemon: 'poke_',
forms: 'form_',
costumes: 'costume_',
alignment: 'alignment_',
evolutions: 'evo_',
descriptions: 'desc_',
moves: 'move_',
items: 'item_',
weather: 'weather_',
types: 'poke_type_',
grunts: 'grunt_',
gruntsAlt: 'grunt_a_',
characterCategories: 'character_category_',
lures: 'lure_',
throwTypes: 'throw_type_',
pokemonCategories: 'pokemon_category_',
},
mergeCategories: true,
masterfileLocale: 'en',
},
locales: {
de: true,
en: true,
es: true,
fr: true,
it: true,
ja: true,
ko: true,
'pt-br': true,
ru: true,
th: true,
'zh-tw': true
},
template: {
pokemon: {
names: true,
forms: true,
descriptions: true
},
moves: true,
items: true,
types: true,
characters: true,
weather: true,
misc: true,
pokemonCategories: true,
}
},
}
})
const pogoLocalesFolder = path.resolve(__dirname, './static/manual')
fs.readdir(pogoLocalesFolder, (err, files) => {
files.forEach(file => {
const short = path.basename(file, '.json')
const safe = translations[short] ? short : 'en'
const pogoTranslations = fs.readFileSync(
path.resolve(pogoLocalesFolder, file),
{ encoding: 'utf8', flag: 'r' },
)
const manualKeys = JSON.parse(pogoTranslations.toString())
const sortedObj = {}
const collator = new Intl.Collator(undefined, { numeric: true, sensitivity: 'base' })
const sortedKeys = [...Object.keys(translations[safe]), ...Object.keys(englishFallback)].sort(collator.compare)
sortedKeys.forEach(key => {
sortedObj[key] = translations[safe][key] || englishFallback[key]
})
const final = {
...sortedObj,
...manualKeys,
}
fs.writeFile(
path.resolve(path.resolve(__dirname, './static/locales'), file),
JSON.stringify(final, null, 2),
'utf8',
() => { },
)
})
})
}