forked from linonetwo/CDDA-Kenan-Modpack-Chinese
-
Notifications
You must be signed in to change notification settings - Fork 0
/
导入主游戏PO汉化.js
90 lines (86 loc) · 3.11 KB
/
导入主游戏PO汉化.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
const PO = require('pofile');
const fs = require('fs-jetpack');
const path = require('path');
const _ = require('lodash');
const translationsToImportInDir = 'imports';
const OFPOFilePath = path.join(
__dirname,
translationsToImportInDir,
'for_use_cataclysm-dda_0f-cataclysm-dda_zh_CN.po'
);
const ODPOFilePath = path.join(__dirname, translationsToImportInDir, '0.D汉化文件.po');
const OBPOFilePath = path.join(__dirname, translationsToImportInDir, 'for_use_cataclysm-dda_old-cataclysm-dda_zh_CN.po');
const OEPOFilePath = path.join(__dirname, translationsToImportInDir, 'for_use_cataclysm-dda_master-cataclysm-dda_zh_CN.po');
const experimentalPOFilePath = path.join(__dirname, translationsToImportInDir, 'for_use_cataclysm-dda_0e-cataclysm-dda_zh_CN.po');
/**
* 共享所有Mod翻译的成果,加速翻译,但之后每个mod自己还是存一份
*/
let sharedTranslationCache = {};
const translateCacheDirName = `中文翻译`;
const sharedName = '共享';
/**
* 在启动时调用,加载之前翻译过的内容,无需使用 paratranz 格式,以加速导入
*/
function loadSharedTranslationCache() {
console.log('加载缓存的翻译');
let count = 1;
const sharedPath = path.join(__dirname, translateCacheDirName, `${sharedName}.json`);
console.log(`加载${sharedName}的翻译 ${sharedPath}`);
sharedTranslationCache = JSON.parse(fs.read(sharedPath, 'utf8'));
}
function storeSharedTranslationCache() {
console.log('储存共享的翻译');
const sharedTranslationCacheFilePath = path.join(__dirname, translateCacheDirName, `${sharedName}.json`);
fs.write(sharedTranslationCacheFilePath, JSON.stringify(sharedTranslationCache, undefined, ' '));
}
PO.load(OBPOFilePath, function (err, po) {
po.items.forEach((item) => {
sharedTranslationCache[item.msgid] = item.msgstr[0];
if (!item.msgstr[0]) {
// DEBUG: console
console.log(item);
process.exit(0);
}
});
PO.load(ODPOFilePath, function (err, po) {
po.items.forEach((item) => {
sharedTranslationCache[item.msgid] = item.msgstr[0];
if (!item.msgstr[0]) {
// DEBUG: console
console.log(item);
process.exit(0);
}
});
PO.load(OEPOFilePath, function (err, po) {
po.items.forEach((item) => {
sharedTranslationCache[item.msgid] = item.msgstr[0];
if (!item.msgstr[0]) {
// DEBUG: console
console.log(item);
process.exit(0);
}
});
PO.load(OFPOFilePath, function (err, po) {
po.items.forEach((item) => {
sharedTranslationCache[item.msgid] = item.msgstr[0];
if (!item.msgstr[0]) {
// DEBUG: console
console.log(item);
process.exit(0);
}
});
PO.load(experimentalPOFilePath, function (err, po) {
po.items.forEach((item) => {
sharedTranslationCache[item.msgid] = item.msgstr[0];
if (!item.msgstr[0]) {
// DEBUG: console
console.log(item);
process.exit(0);
}
});
storeSharedTranslationCache();
});
});
});
});
});