forked from bschultz/pogo-translations
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathupdate.js
93 lines (86 loc) · 2.66 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
const fs = require('fs')
const Fetch = require('node-fetch')
const path = require('path')
const POGOProtos = require('pogo-protos')
function fetchJson(url) {
return new Promise(resolve => {
Fetch(url)
.then(res => res.json())
.then(json => resolve(json.data))
})
}
((async function createLocales() {
const available = {
de: 'german',
en: 'english',
es: 'spanish',
fr: 'french',
it: 'italian',
jp: 'japanese',
ko: 'korean',
'pt-br': 'brazilianportuguese',
th: 'thai',
'zh-tw': 'chinesetraditional',
ru: 'russian',
}
const remoteFiles = {}
await Promise.all(Object.entries(available).map(async language => {
const [key, value] = language
remoteFiles[key] = await fetchJson(`https://raw.githubusercontent.com/PokeMiners/pogo_assets/master/Texts/Latest%20APK/JSON/i18n_${value}.json`)
}))
const pogoLocalesFolder = path.resolve(__dirname, './static/manual')
fs.readdir(pogoLocalesFolder, (err, files) => {
files.forEach(file => {
const short = path.basename(file, '.json')
const safe = remoteFiles[short] ? short : 'en'
const nativeJson = {}
for (let i = 0; i < remoteFiles[safe].length; i += 2) {
nativeJson[remoteFiles[safe][i]] = remoteFiles[safe][i + 1]
}
const pokemon = {}
Object.values(POGOProtos.Rpc.HoloPokemonId).forEach(id => {
const key = `pokemon_name_${String(id).padStart(4, '0')}`
if (nativeJson[key]) {
if (id) {
pokemon[`poke_${id}`] = nativeJson[key]
}
}
})
const moves = {}
Object.values(POGOProtos.Rpc.HoloPokemonMove).forEach(id => {
const key = `move_name_${String(id).padStart(4, '0')}`
if (nativeJson[key]) {
moves[`move_${id}`] = nativeJson[key]
}
})
const items = {}
Object.entries(POGOProtos.Rpc.Item).forEach(id => {
const [key, value] = id
if (nativeJson[`${key.toLowerCase()}_name`]) {
items[`item_${value}`] = nativeJson[`${key.toLowerCase()}_name`]
}
})
const manualKeys = fs.readFileSync(
path.resolve(pogoLocalesFolder, file),
{ encoding: 'utf8', flag: 'r' },
)
const enBackup = fs.readFileSync(
path.resolve(pogoLocalesFolder, 'en.json'),
{ encoding: 'utf8', flag: 'r' },
)
const final = {
...pokemon,
...moves,
...items,
...JSON.parse(enBackup),
...JSON.parse(manualKeys),
}
fs.writeFile(
path.resolve(path.resolve(__dirname, './static/locales'), file),
JSON.stringify(final, null, 2),
'utf8',
() => { },
)
})
})
})())