UNPKG

5.48 kBJavaScriptView Raw
1"use strict";
2
3Object.defineProperty(exports, "__esModule", {
4 value: true
5});
6exports.createAddLangsMacro = createAddLangsMacro;
7exports.addCustomMessageFileInclude = exports.LangConfigurator = void 0;
8
9function _bluebirdLst() {
10 const data = require("bluebird-lst");
11
12 _bluebirdLst = function () {
13 return data;
14 };
15
16 return data;
17}
18
19function _builderUtil() {
20 const data = require("builder-util");
21
22 _builderUtil = function () {
23 return data;
24 };
25
26 return data;
27}
28
29function _langs() {
30 const data = require("builder-util/out/langs");
31
32 _langs = function () {
33 return data;
34 };
35
36 return data;
37}
38
39var _debug2 = _interopRequireDefault(require("debug"));
40
41function _fsExtraP() {
42 const data = require("fs-extra-p");
43
44 _fsExtraP = function () {
45 return data;
46 };
47
48 return data;
49}
50
51function _jsYaml() {
52 const data = require("js-yaml");
53
54 _jsYaml = function () {
55 return data;
56 };
57
58 return data;
59}
60
61var path = _interopRequireWildcard(require("path"));
62
63function _nsisUtil() {
64 const data = require("./nsisUtil");
65
66 _nsisUtil = function () {
67 return data;
68 };
69
70 return data;
71}
72
73let writeCustomLangFile = (() => {
74 var _ref = (0, _bluebirdLst().coroutine)(function* (data, packager) {
75 const file = yield packager.getTempFile("messages.nsh");
76 yield (0, _fsExtraP().outputFile)(file, data);
77 return file;
78 });
79
80 return function writeCustomLangFile(_x, _x2) {
81 return _ref.apply(this, arguments);
82 };
83})();
84
85function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = Object.defineProperty && Object.getOwnPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : {}; if (desc.get || desc.set) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } } newObj.default = obj; return newObj; } }
86
87function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
88
89const debug = (0, _debug2.default)("electron-builder:nsis");
90
91class LangConfigurator {
92 constructor(options) {
93 const rawList = options.installerLanguages;
94
95 if (options.unicode === false || rawList === null || Array.isArray(rawList) && rawList.length === 0) {
96 this.isMultiLang = false;
97 } else {
98 this.isMultiLang = options.multiLanguageInstaller !== false;
99 }
100
101 if (this.isMultiLang) {
102 this.langs = rawList == null ? _langs().bundledLanguages.slice() : (0, _builderUtil().asArray)(rawList).map(it => (0, _langs().toLangWithRegion)(it.replace("-", "_")));
103 } else {
104 this.langs = ["en_US"];
105 }
106 }
107
108}
109
110exports.LangConfigurator = LangConfigurator;
111
112function createAddLangsMacro(scriptGenerator, langConfigurator) {
113 const result = [];
114
115 for (const langWithRegion of langConfigurator.langs) {
116 let name;
117
118 if (langWithRegion === "zh_CN") {
119 name = "SimpChinese";
120 } else if (langWithRegion === "zh_TW") {
121 name = "TradChinese";
122 } else if (langWithRegion === "nb_NO") {
123 name = "Norwegian";
124 } else if (langWithRegion === "pt_BR") {
125 name = "PortugueseBR";
126 } else {
127 const lang = langWithRegion.substring(0, langWithRegion.indexOf("_"));
128 name = _langs().langIdToName[lang];
129
130 if (name == null) {
131 throw new Error(`Language name is unknown for ${lang}`);
132 }
133
134 if (name === "Spanish") {
135 name = "SpanishInternational";
136 }
137 }
138
139 result.push(`!insertmacro MUI_LANGUAGE "${name}"`);
140 }
141
142 scriptGenerator.macro("addLangs", result);
143}
144
145let addCustomMessageFileInclude = (() => {
146 var _ref2 = (0, _bluebirdLst().coroutine)(function* (input, packager, scriptGenerator, langConfigurator) {
147 const data = (0, _jsYaml().safeLoad)((yield (0, _fsExtraP().readFile)(path.join(_nsisUtil().nsisTemplatesDir, input), "utf-8")));
148 const instructions = computeCustomMessageTranslations(data, langConfigurator).join("\n");
149 debug(instructions);
150 scriptGenerator.include((yield writeCustomLangFile(instructions, packager)));
151 });
152
153 return function addCustomMessageFileInclude(_x3, _x4, _x5, _x6) {
154 return _ref2.apply(this, arguments);
155 };
156})();
157
158exports.addCustomMessageFileInclude = addCustomMessageFileInclude;
159
160function computeCustomMessageTranslations(messages, langConfigurator) {
161 const result = [];
162 const includedLangs = new Set(langConfigurator.langs);
163
164 for (const messageId of Object.keys(messages)) {
165 const langToTranslations = messages[messageId];
166 const unspecifiedLangs = new Set(langConfigurator.langs);
167
168 for (const lang of Object.keys(langToTranslations)) {
169 const langWithRegion = (0, _langs().toLangWithRegion)(lang);
170
171 if (!includedLangs.has(langWithRegion)) {
172 continue;
173 }
174
175 const value = langToTranslations[lang];
176
177 if (value == null) {
178 throw new Error(`${messageId} not specified for ${lang}`);
179 }
180
181 result.push(`LangString ${messageId} ${_langs().lcid[langWithRegion]} "${value.replace(/\n/g, "$\\r$\\n")}"`);
182 unspecifiedLangs.delete(langWithRegion);
183 }
184
185 if (langConfigurator.isMultiLang) {
186 const defaultTranslation = langToTranslations.en.replace(/\n/g, "$\\r$\\n");
187
188 for (const langWithRegion of unspecifiedLangs) {
189 result.push(`LangString ${messageId} ${_langs().lcid[langWithRegion]} "${defaultTranslation}"`);
190 }
191 }
192 }
193
194 return result;
195}
196//# sourceMappingURL=nsisLang.js.map
\No newline at end of file