nsisLang.js
5.28 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
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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.createAddLangsMacro = createAddLangsMacro;
exports.addCustomMessageFileInclude = addCustomMessageFileInclude;
exports.LangConfigurator = void 0;
function _builderUtil() {
const data = require("builder-util");
_builderUtil = function () {
return data;
};
return data;
}
function _langs() {
const data = require("../../util/langs");
_langs = function () {
return data;
};
return data;
}
var _debug2 = _interopRequireDefault(require("debug"));
function _fsExtra() {
const data = require("fs-extra");
_fsExtra = function () {
return data;
};
return data;
}
function _jsYaml() {
const data = require("js-yaml");
_jsYaml = function () {
return data;
};
return data;
}
var path = _interopRequireWildcard(require("path"));
function _nsisUtil() {
const data = require("./nsisUtil");
_nsisUtil = function () {
return data;
};
return data;
}
function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return null; var cache = new WeakMap(); _getRequireWildcardCache = function () { return cache; }; return cache; }
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
const debug = (0, _debug2.default)("electron-builder:nsis");
class LangConfigurator {
constructor(options) {
const rawList = options.installerLanguages;
if (options.unicode === false || rawList === null || Array.isArray(rawList) && rawList.length === 0) {
this.isMultiLang = false;
} else {
this.isMultiLang = options.multiLanguageInstaller !== false;
}
if (this.isMultiLang) {
this.langs = rawList == null ? _langs().bundledLanguages.slice() : (0, _builderUtil().asArray)(rawList).map(it => (0, _langs().toLangWithRegion)(it.replace("-", "_")));
} else {
this.langs = ["en_US"];
}
}
}
exports.LangConfigurator = LangConfigurator;
function createAddLangsMacro(scriptGenerator, langConfigurator) {
const result = [];
for (const langWithRegion of langConfigurator.langs) {
let name;
if (langWithRegion === "zh_CN") {
name = "SimpChinese";
} else if (langWithRegion === "zh_TW") {
name = "TradChinese";
} else if (langWithRegion === "nb_NO") {
name = "Norwegian";
} else if (langWithRegion === "pt_BR") {
name = "PortugueseBR";
} else {
const lang = langWithRegion.substring(0, langWithRegion.indexOf("_"));
name = _langs().langIdToName[lang];
if (name == null) {
throw new Error(`Language name is unknown for ${lang}`);
}
if (name === "Spanish") {
name = "SpanishInternational";
}
}
result.push(`!insertmacro MUI_LANGUAGE "${name}"`);
}
scriptGenerator.macro("addLangs", result);
}
async function writeCustomLangFile(data, packager) {
const file = await packager.getTempFile("messages.nsh");
await (0, _fsExtra().outputFile)(file, data);
return file;
}
async function addCustomMessageFileInclude(input, packager, scriptGenerator, langConfigurator) {
const data = (0, _jsYaml().load)(await (0, _fsExtra().readFile)(path.join(_nsisUtil().nsisTemplatesDir, input), "utf-8"));
const instructions = computeCustomMessageTranslations(data, langConfigurator).join("\n");
debug(instructions);
scriptGenerator.include(await writeCustomLangFile(instructions, packager));
}
function computeCustomMessageTranslations(messages, langConfigurator) {
const result = [];
const includedLangs = new Set(langConfigurator.langs);
for (const messageId of Object.keys(messages)) {
const langToTranslations = messages[messageId];
const unspecifiedLangs = new Set(langConfigurator.langs);
for (const lang of Object.keys(langToTranslations)) {
const langWithRegion = (0, _langs().toLangWithRegion)(lang);
if (!includedLangs.has(langWithRegion)) {
continue;
}
const value = langToTranslations[lang];
if (value == null) {
throw new Error(`${messageId} not specified for ${lang}`);
}
result.push(`LangString ${messageId} ${_langs().lcid[langWithRegion]} "${value.replace(/\n/g, "$\\r$\\n")}"`);
unspecifiedLangs.delete(langWithRegion);
}
if (langConfigurator.isMultiLang) {
const defaultTranslation = langToTranslations.en.replace(/\n/g, "$\\r$\\n");
for (const langWithRegion of unspecifiedLangs) {
result.push(`LangString ${messageId} ${_langs().lcid[langWithRegion]} "${defaultTranslation}"`);
}
}
}
return result;
}
// __ts-babel@6.0.4
//# sourceMappingURL=nsisLang.js.map