@theia/localization-manager 1.23.0-next.2 → 1.23.0-next.24
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +39 -2
- package/lib/common.d.ts +19 -0
- package/lib/common.d.ts.map +1 -0
- package/lib/common.js +18 -0
- package/lib/common.js.map +1 -0
- package/lib/deepl-api.d.ts +42 -0
- package/lib/deepl-api.d.ts.map +1 -0
- package/lib/deepl-api.js +66 -0
- package/lib/deepl-api.js.map +1 -0
- package/lib/index.d.ts +2 -0
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +3 -1
- package/lib/index.js.map +1 -1
- package/lib/localization-extractor.d.ts +1 -3
- package/lib/localization-extractor.d.ts.map +1 -1
- package/lib/localization-extractor.js +1 -1
- package/lib/localization-extractor.js.map +1 -1
- package/lib/localization-extractor.spec.js +11 -11
- package/lib/localization-extractor.spec.js.map +1 -1
- package/lib/localization-manager.d.ts +38 -0
- package/lib/localization-manager.d.ts.map +1 -0
- package/lib/localization-manager.js +137 -0
- package/lib/localization-manager.js.map +1 -0
- package/lib/localization-manager.spec.d.ts +17 -0
- package/lib/localization-manager.spec.d.ts.map +1 -0
- package/lib/localization-manager.spec.js +75 -0
- package/lib/localization-manager.spec.js.map +1 -0
- package/package.json +6 -3
- package/src/common.ts +19 -0
- package/src/deepl-api.ts +122 -0
- package/src/index.ts +2 -0
- package/src/localization-extractor.ts +1 -4
- package/src/localization-manager.spec.ts +80 -0
- package/src/localization-manager.ts +147 -0
package/README.md
CHANGED
|
@@ -12,8 +12,45 @@
|
|
|
12
12
|
|
|
13
13
|
## Description
|
|
14
14
|
|
|
15
|
-
The `@theia/localization-manager` package is used easily create localizations of Theia and Theia extensions for different languages.
|
|
16
|
-
|
|
15
|
+
The `@theia/localization-manager` package is used easily create localizations of Theia and Theia extensions for different languages. It has two main use cases.
|
|
16
|
+
|
|
17
|
+
First, it allows to extract localization keys and default values from `nls.localize` calls within the codebase using the `nls-extract` Theia-CLI command. Take this code for example:
|
|
18
|
+
|
|
19
|
+
```ts
|
|
20
|
+
const hi = nls.localize('greetings/hi', 'Hello');
|
|
21
|
+
const bye = nls.localize('greetings/bye', 'Bye');
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
It will be converted into this JSON file (`nls.json`):
|
|
25
|
+
|
|
26
|
+
```json
|
|
27
|
+
{
|
|
28
|
+
"greetings": {
|
|
29
|
+
"hi": "Hello",
|
|
30
|
+
"bye": "Bye"
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
Afterwards, any manual or automatic translation approach can be used to translate this file into other languages. These JSON files are supposed to be picked up by `LocalizationContribution`s.
|
|
36
|
+
|
|
37
|
+
Additionally, Theia provides a simple way to translate the generated JSON files out of the box using the [DeepL API](https://www.deepl.com/docs-api). For this, a [DeepL free or pro account](https://www.deepl.com/pro) is needed. Using the `nls-localize` command of the Theia-CLI, a target file can be translated into different languages. For example, when calling the command using the previous JSON file with the `fr` (french) language, the following `nls.fr.json` file will be created in the same directory as the translation source:
|
|
38
|
+
|
|
39
|
+
```json
|
|
40
|
+
{
|
|
41
|
+
"greetings": {
|
|
42
|
+
"hi": "Bonjour",
|
|
43
|
+
"bye": "Au revoir"
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
Only JSON entries without corresponding translations are translated using DeepL. This ensures that manual changes to the translated files aren't overwritten and only new translation entries are actually sent to DeepL.
|
|
50
|
+
|
|
51
|
+
Use `theia nls-localize --help` for more information on how to use the command and supply DeepL API keys.
|
|
52
|
+
|
|
53
|
+
For more information, see the [internationalization documentation](https://theia-ide.org/docs/i18n/).
|
|
17
54
|
|
|
18
55
|
## Additional Information
|
|
19
56
|
|
package/lib/common.d.ts
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/********************************************************************************
|
|
2
|
+
* Copyright (C) 2021 TypeFox and others.
|
|
3
|
+
*
|
|
4
|
+
* This program and the accompanying materials are made available under the
|
|
5
|
+
* terms of the Eclipse Public License v. 2.0 which is available at
|
|
6
|
+
* http://www.eclipse.org/legal/epl-2.0.
|
|
7
|
+
*
|
|
8
|
+
* This Source Code may also be made available under the following Secondary
|
|
9
|
+
* Licenses when the conditions for such availability set forth in the Eclipse
|
|
10
|
+
* Public License v. 2.0 are satisfied: GNU General Public License, version 2
|
|
11
|
+
* with the GNU Classpath Exception which is available at
|
|
12
|
+
* https://www.gnu.org/software/classpath/license.html.
|
|
13
|
+
*
|
|
14
|
+
* SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
|
|
15
|
+
********************************************************************************/
|
|
16
|
+
export interface Localization {
|
|
17
|
+
[key: string]: string | Localization;
|
|
18
|
+
}
|
|
19
|
+
//# sourceMappingURL=common.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"common.d.ts","sourceRoot":"","sources":["../src/common.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;kFAckF;AAElF,MAAM,WAAW,YAAY;IACzB,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,GAAG,YAAY,CAAA;CACvC"}
|
package/lib/common.js
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/********************************************************************************
|
|
3
|
+
* Copyright (C) 2021 TypeFox and others.
|
|
4
|
+
*
|
|
5
|
+
* This program and the accompanying materials are made available under the
|
|
6
|
+
* terms of the Eclipse Public License v. 2.0 which is available at
|
|
7
|
+
* http://www.eclipse.org/legal/epl-2.0.
|
|
8
|
+
*
|
|
9
|
+
* This Source Code may also be made available under the following Secondary
|
|
10
|
+
* Licenses when the conditions for such availability set forth in the Eclipse
|
|
11
|
+
* Public License v. 2.0 are satisfied: GNU General Public License, version 2
|
|
12
|
+
* with the GNU Classpath Exception which is available at
|
|
13
|
+
* https://www.gnu.org/software/classpath/license.html.
|
|
14
|
+
*
|
|
15
|
+
* SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
|
|
16
|
+
********************************************************************************/
|
|
17
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
|
+
//# sourceMappingURL=common.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"common.js","sourceRoot":"","sources":["../src/common.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;kFAckF"}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
/********************************************************************************
|
|
2
|
+
* Copyright (C) 2021 TypeFox and others.
|
|
3
|
+
*
|
|
4
|
+
* This program and the accompanying materials are made available under the
|
|
5
|
+
* terms of the Eclipse Public License v. 2.0 which is available at
|
|
6
|
+
* http://www.eclipse.org/legal/epl-2.0.
|
|
7
|
+
*
|
|
8
|
+
* This Source Code may also be made available under the following Secondary
|
|
9
|
+
* Licenses when the conditions for such availability set forth in the Eclipse
|
|
10
|
+
* Public License v. 2.0 are satisfied: GNU General Public License, version 2
|
|
11
|
+
* with the GNU Classpath Exception which is available at
|
|
12
|
+
* https://www.gnu.org/software/classpath/license.html.
|
|
13
|
+
*
|
|
14
|
+
* SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
|
|
15
|
+
********************************************************************************/
|
|
16
|
+
export declare function deepl(parameters: DeeplParameters): Promise<DeeplResponse>;
|
|
17
|
+
export declare type DeeplLanguage = 'BG' | 'CS' | 'DA' | 'DE' | 'EL' | 'EN-GB' | 'EN-US' | 'EN' | 'ES' | 'ET' | 'FI' | 'FR' | 'HU' | 'IT' | 'JA' | 'LT' | 'LV' | 'NL' | 'PL' | 'PT-PT' | 'PT-BR' | 'PT' | 'RO' | 'RU' | 'SK' | 'SL' | 'SV' | 'ZH';
|
|
18
|
+
export declare const supportedLanguages: string[];
|
|
19
|
+
export declare function isSupportedLanguage(language: string): language is DeeplLanguage;
|
|
20
|
+
export interface DeeplParameters {
|
|
21
|
+
free_api: Boolean;
|
|
22
|
+
auth_key: string;
|
|
23
|
+
text: string[];
|
|
24
|
+
source_lang?: DeeplLanguage;
|
|
25
|
+
target_lang: DeeplLanguage;
|
|
26
|
+
split_sentences?: '0' | '1' | 'nonewlines';
|
|
27
|
+
preserve_formatting?: '0' | '1';
|
|
28
|
+
formality?: 'default' | 'more' | 'less';
|
|
29
|
+
tag_handling?: string[];
|
|
30
|
+
non_splitting_tags?: string[];
|
|
31
|
+
outline_detection?: string;
|
|
32
|
+
splitting_tags?: string[];
|
|
33
|
+
ignore_tags?: string[];
|
|
34
|
+
}
|
|
35
|
+
export interface DeeplResponse {
|
|
36
|
+
translations: DeeplTranslation[];
|
|
37
|
+
}
|
|
38
|
+
export interface DeeplTranslation {
|
|
39
|
+
detected_source_language: string;
|
|
40
|
+
text: string;
|
|
41
|
+
}
|
|
42
|
+
//# sourceMappingURL=deepl-api.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"deepl-api.d.ts","sourceRoot":"","sources":["../src/deepl-api.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;kFAckF;AAQlF,wBAAsB,KAAK,CACvB,UAAU,EAAE,eAAe,GAC5B,OAAO,CAAC,aAAa,CAAC,CAmBxB;AAgBD,oBAAY,aAAa,GACnB,IAAI,GACJ,IAAI,GACJ,IAAI,GACJ,IAAI,GACJ,IAAI,GACJ,OAAO,GACP,OAAO,GACP,IAAI,GACJ,IAAI,GACJ,IAAI,GACJ,IAAI,GACJ,IAAI,GACJ,IAAI,GACJ,IAAI,GACJ,IAAI,GACJ,IAAI,GACJ,IAAI,GACJ,IAAI,GACJ,IAAI,GACJ,OAAO,GACP,OAAO,GACP,IAAI,GACJ,IAAI,GACJ,IAAI,GACJ,IAAI,GACJ,IAAI,GACJ,IAAI,GACJ,IAAI,CAAC;AAEX,eAAO,MAAM,kBAAkB,UAG9B,CAAC;AAEF,wBAAgB,mBAAmB,CAAC,QAAQ,EAAE,MAAM,GAAG,QAAQ,IAAI,aAAa,CAE/E;AAED,MAAM,WAAW,eAAe;IAC5B,QAAQ,EAAE,OAAO,CAAA;IACjB,QAAQ,EAAE,MAAM,CAAA;IAChB,IAAI,EAAE,MAAM,EAAE,CAAA;IACd,WAAW,CAAC,EAAE,aAAa,CAAA;IAC3B,WAAW,EAAE,aAAa,CAAA;IAC1B,eAAe,CAAC,EAAE,GAAG,GAAG,GAAG,GAAG,YAAY,CAAA;IAC1C,mBAAmB,CAAC,EAAE,GAAG,GAAG,GAAG,CAAA;IAC/B,SAAS,CAAC,EAAE,SAAS,GAAG,MAAM,GAAG,MAAM,CAAA;IACvC,YAAY,CAAC,EAAE,MAAM,EAAE,CAAA;IACvB,kBAAkB,CAAC,EAAE,MAAM,EAAE,CAAA;IAC7B,iBAAiB,CAAC,EAAE,MAAM,CAAA;IAC1B,cAAc,CAAC,EAAE,MAAM,EAAE,CAAA;IACzB,WAAW,CAAC,EAAE,MAAM,EAAE,CAAA;CACzB;AAED,MAAM,WAAW,aAAa;IAC1B,YAAY,EAAE,gBAAgB,EAAE,CAAA;CACnC;AAED,MAAM,WAAW,gBAAgB;IAC7B,wBAAwB,EAAE,MAAM,CAAA;IAChC,IAAI,EAAE,MAAM,CAAA;CACf"}
|
package/lib/deepl-api.js
ADDED
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/********************************************************************************
|
|
3
|
+
* Copyright (C) 2021 TypeFox and others.
|
|
4
|
+
*
|
|
5
|
+
* This program and the accompanying materials are made available under the
|
|
6
|
+
* terms of the Eclipse Public License v. 2.0 which is available at
|
|
7
|
+
* http://www.eclipse.org/legal/epl-2.0.
|
|
8
|
+
*
|
|
9
|
+
* This Source Code may also be made available under the following Secondary
|
|
10
|
+
* Licenses when the conditions for such availability set forth in the Eclipse
|
|
11
|
+
* Public License v. 2.0 are satisfied: GNU General Public License, version 2
|
|
12
|
+
* with the GNU Classpath Exception which is available at
|
|
13
|
+
* https://www.gnu.org/software/classpath/license.html.
|
|
14
|
+
*
|
|
15
|
+
* SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
|
|
16
|
+
********************************************************************************/
|
|
17
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
|
+
exports.isSupportedLanguage = exports.supportedLanguages = exports.deepl = void 0;
|
|
19
|
+
const bent = require("bent");
|
|
20
|
+
const post = bent('POST', 'json', 200);
|
|
21
|
+
// 50 is the maximum amount of translations per request
|
|
22
|
+
const deeplLimit = 50;
|
|
23
|
+
async function deepl(parameters) {
|
|
24
|
+
const sub_domain = parameters.free_api ? 'api-free' : 'api';
|
|
25
|
+
const textChunks = [];
|
|
26
|
+
const textArray = [...parameters.text];
|
|
27
|
+
while (textArray.length > 0) {
|
|
28
|
+
textChunks.push(textArray.splice(0, deeplLimit));
|
|
29
|
+
}
|
|
30
|
+
const responses = await Promise.all(textChunks.map(chunk => {
|
|
31
|
+
const parameterCopy = Object.assign(Object.assign({}, parameters), { text: chunk });
|
|
32
|
+
return post(`https://${sub_domain}.deepl.com/v2/translate`, Buffer.from(toFormData(parameterCopy)), {
|
|
33
|
+
'Content-Type': 'application/x-www-form-urlencoded',
|
|
34
|
+
'User-Agent': 'Theia-Localization-Manager'
|
|
35
|
+
});
|
|
36
|
+
}));
|
|
37
|
+
const mergedResponse = { translations: [] };
|
|
38
|
+
for (const response of responses) {
|
|
39
|
+
mergedResponse.translations.push(...response.translations);
|
|
40
|
+
}
|
|
41
|
+
return mergedResponse;
|
|
42
|
+
}
|
|
43
|
+
exports.deepl = deepl;
|
|
44
|
+
function toFormData(parameters) {
|
|
45
|
+
const str = [];
|
|
46
|
+
for (const [key, value] of Object.entries(parameters)) {
|
|
47
|
+
if (typeof value === 'string') {
|
|
48
|
+
str.push(encodeURIComponent(key) + '=' + encodeURIComponent(value.toString()));
|
|
49
|
+
}
|
|
50
|
+
else if (Array.isArray(value)) {
|
|
51
|
+
for (const item of value) {
|
|
52
|
+
str.push(encodeURIComponent(key) + '=' + encodeURIComponent(item.toString()));
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
return str.join('&');
|
|
57
|
+
}
|
|
58
|
+
exports.supportedLanguages = [
|
|
59
|
+
'BG', 'CD', 'DA', 'DE', 'EL', 'EN-GB', 'EN-US', 'EN', 'ES', 'ET', 'FI', 'FR', 'HU', 'IT',
|
|
60
|
+
'JA', 'LT', 'LV', 'NL', 'PL', 'PT-PT', 'PT-BR', 'PT', 'RO', 'RU', 'SK', 'SL', 'SV', 'ZH'
|
|
61
|
+
];
|
|
62
|
+
function isSupportedLanguage(language) {
|
|
63
|
+
return exports.supportedLanguages.includes(language.toUpperCase());
|
|
64
|
+
}
|
|
65
|
+
exports.isSupportedLanguage = isSupportedLanguage;
|
|
66
|
+
//# sourceMappingURL=deepl-api.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"deepl-api.js","sourceRoot":"","sources":["../src/deepl-api.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;kFAckF;;;AAElF,6BAA6B;AAE7B,MAAM,IAAI,GAAG,IAAI,CAAC,MAAM,EAAE,MAAM,EAAE,GAAG,CAAC,CAAC;AACvC,uDAAuD;AACvD,MAAM,UAAU,GAAG,EAAE,CAAC;AAEf,KAAK,UAAU,KAAK,CACvB,UAA2B;IAE3B,MAAM,UAAU,GAAG,UAAU,CAAC,QAAQ,CAAC,CAAC,CAAC,UAAU,CAAC,CAAC,CAAC,KAAK,CAAC;IAC5D,MAAM,UAAU,GAAe,EAAE,CAAC;IAClC,MAAM,SAAS,GAAG,CAAC,GAAG,UAAU,CAAC,IAAI,CAAC,CAAC;IACvC,OAAO,SAAS,CAAC,MAAM,GAAG,CAAC,EAAE;QACzB,UAAU,CAAC,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,CAAC,EAAE,UAAU,CAAC,CAAC,CAAC;KACpD;IACD,MAAM,SAAS,GAAoB,MAAM,OAAO,CAAC,GAA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AC;AAgCY,QAAA,kBAAkB,GAAG;IAC9B,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI;IACxF,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI;CAC3F,CAAC;AAEF,SAAgB,mBAAmB,CAAC,QAAgB;IAChD,OAAO,0BAAkB,CAAC,QAAQ,CAAC,QAAQ,CAAC,WAAW,EAAE,CAAC,CAAC;AAC/D,CAAC;AAFD,kDAEC"}
|
package/lib/index.d.ts
CHANGED
|
@@ -13,5 +13,7 @@
|
|
|
13
13
|
*
|
|
14
14
|
* SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
|
|
15
15
|
********************************************************************************/
|
|
16
|
+
export * from './common';
|
|
16
17
|
export * from './localization-extractor';
|
|
18
|
+
export * from './localization-manager';
|
|
17
19
|
//# sourceMappingURL=index.d.ts.map
|
package/lib/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;kFAckF;AAElF,cAAc,0BAA0B,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;kFAckF;AAElF,cAAc,UAAU,CAAC;AACzB,cAAc,0BAA0B,CAAC;AACzC,cAAc,wBAAwB,CAAC"}
|
package/lib/index.js
CHANGED
|
@@ -22,8 +22,10 @@ var __createBinding = (this && this.__createBinding) || (Object.create ? (functi
|
|
|
22
22
|
o[k2] = m[k];
|
|
23
23
|
}));
|
|
24
24
|
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
25
|
-
for (var p in m) if (p !== "default" && !
|
|
25
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
26
26
|
};
|
|
27
27
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
28
|
+
__exportStar(require("./common"), exports);
|
|
28
29
|
__exportStar(require("./localization-extractor"), exports);
|
|
30
|
+
__exportStar(require("./localization-manager"), exports);
|
|
29
31
|
//# sourceMappingURL=index.js.map
|
package/lib/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;kFAckF;;;;;;;;;;;;AAElF,2DAAyC"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;kFAckF;;;;;;;;;;;;AAElF,2CAAyB;AACzB,2DAAyC;AACzC,yDAAuC"}
|
|
@@ -13,9 +13,7 @@
|
|
|
13
13
|
*
|
|
14
14
|
* SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
|
|
15
15
|
********************************************************************************/
|
|
16
|
-
|
|
17
|
-
[key: string]: string | Localization;
|
|
18
|
-
}
|
|
16
|
+
import { Localization } from './common';
|
|
19
17
|
export interface ExtractionOptions {
|
|
20
18
|
root: string;
|
|
21
19
|
output: string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"localization-extractor.d.ts","sourceRoot":"","sources":["../src/localization-extractor.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;kFAckF;
|
|
1
|
+
{"version":3,"file":"localization-extractor.d.ts","sourceRoot":"","sources":["../src/localization-extractor.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;kFAckF;AASlF,OAAO,EAAE,YAAY,EAAE,MAAM,UAAU,CAAC;AAIxC,MAAM,WAAW,iBAAiB;IAC9B,IAAI,EAAE,MAAM,CAAA;IACZ,MAAM,EAAE,MAAM,CAAA;IACd,OAAO,CAAC,EAAE,MAAM,CAAA;IAChB,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,wDAAwD;IACxD,KAAK,CAAC,EAAE,MAAM,EAAE,CAAA;IAChB,KAAK,EAAE,OAAO,CAAA;CACjB;AAqCD,wBAAsB,OAAO,CAAC,OAAO,EAAE,iBAAiB,GAAG,OAAO,CAAC,IAAI,CAAC,CAyBvE;AAED,wBAAsB,eAAe,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,MAAM,EAAE,EAAE,OAAO,CAAC,EAAE,iBAAiB,GAAG,OAAO,CAAC,YAAY,CAAC,CAqC1I"}
|
|
@@ -23,7 +23,7 @@ const path = require("path");
|
|
|
23
23
|
const glob_1 = require("glob");
|
|
24
24
|
const util_1 = require("util");
|
|
25
25
|
const deepmerge = require("deepmerge");
|
|
26
|
-
const globPromise = util_1.promisify(glob_1.glob);
|
|
26
|
+
const globPromise = (0, util_1.promisify)(glob_1.glob);
|
|
27
27
|
class SingleFileServiceHost {
|
|
28
28
|
constructor(options, filename, contents) {
|
|
29
29
|
this.options = options;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"localization-extractor.js","sourceRoot":"","sources":["../src/localization-extractor.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;kFAckF;;;AAElF,+BAA+B;AAC/B,iCAAiC;AACjC,yBAAyB;AACzB,6BAA6B;AAC7B,+BAA4B;AAC5B,+BAAiC;AACjC,uCAAwC;AAExC,MAAM,WAAW,GAAG,gBAAS,CAAC,WAAI,CAAC,CAAC;AAgBpC,MAAM,qBAAqB;IAKvB,YAAoB,OAA2B,EAAU,QAAgB,EAAE,QAAgB;QAAvE,YAAO,GAAP,OAAO,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,IAAI,CAAC,EAAE;QAC5B,OAAO,KAAK,CAAC;KAChB;IAED,OAAO,IAAI,CAAC,UAAU,CAAC,OAAO,EAAE,KAAK,4BAA4B,CAAC;AACtE,CAAC;AAED,MAAM,WAAW,GAA2B;IACxC,IAAI,EAAE,IAAI;IACV,GAAG,EAAE,GAAG;IACR,IAAI,EAAE,IAAI;IACV,GAAG,EAAE,IAAI;IACT,GAAG,EAAE,IAAI;IACT,GAAG,EAAE,IAAI;IACT,GAAG,EAAE,IAAI;IACT,GAAG,EAAE,IAAI;CACZ,CAAC;AAEF,SAAS,cAAc,CAAC,GAAW;IAC/B,MAAM,MAAM,GAAa,EAAE,CAAC;IAC5B,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,GAAG,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE;QACjC,MAAM,EAAE,GAAG,GAAG,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC;QACzB,IAAI,EAAE,KAAK,IAAI,EAAE;YACb,IAAI,CAAC,GAAG,CAAC,GAAG,GAAG,CAAC,MAAM,EAAE;gBACpB,MAAM,OAAO,GAAG,WAAW,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;gBAC/C,IAAI,OAAO,KAAK,SAAS,EAAE;oBACvB,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;oBACrB,CAAC,EAAE,CAAC;oBACJ,SAAS;iBACZ;aACJ;SACJ;QACD,MAAM,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;KACnB;IACD,OAAO,MAAM,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;AAC3B,CAAC"}
|
|
@@ -21,13 +21,13 @@ const TEST_FILE = 'test.ts';
|
|
|
21
21
|
describe('correctly extracts from file content', () => {
|
|
22
22
|
it('should extract from simple nls.localize() call', async () => {
|
|
23
23
|
const content = 'nls.localize("key", "value")';
|
|
24
|
-
assert.deepStrictEqual(await localization_extractor_1.extractFromFile(TEST_FILE, content), {
|
|
24
|
+
assert.deepStrictEqual(await (0, localization_extractor_1.extractFromFile)(TEST_FILE, content), {
|
|
25
25
|
'key': 'value'
|
|
26
26
|
});
|
|
27
27
|
});
|
|
28
28
|
it('should extract from nested nls.localize() call', async () => {
|
|
29
29
|
const content = 'nls.localize("nested/key", "value")';
|
|
30
|
-
assert.deepStrictEqual(await localization_extractor_1.extractFromFile(TEST_FILE, content), {
|
|
30
|
+
assert.deepStrictEqual(await (0, localization_extractor_1.extractFromFile)(TEST_FILE, content), {
|
|
31
31
|
'nested': {
|
|
32
32
|
'key': 'value'
|
|
33
33
|
}
|
|
@@ -44,7 +44,7 @@ describe('correctly extracts from file content', () => {
|
|
|
44
44
|
label: 'command-label2'
|
|
45
45
|
}, 'command-key');
|
|
46
46
|
`;
|
|
47
|
-
assert.deepStrictEqual(await localization_extractor_1.extractFromFile(TEST_FILE, content), {
|
|
47
|
+
assert.deepStrictEqual(await (0, localization_extractor_1.extractFromFile)(TEST_FILE, content), {
|
|
48
48
|
'command-id1': 'command-label1',
|
|
49
49
|
'command-key': 'command-label2'
|
|
50
50
|
});
|
|
@@ -56,7 +56,7 @@ describe('correctly extracts from file content', () => {
|
|
|
56
56
|
label: 'label',
|
|
57
57
|
category: 'category'
|
|
58
58
|
}, undefined, 'category-key');`;
|
|
59
|
-
assert.deepStrictEqual(await localization_extractor_1.extractFromFile(TEST_FILE, content), {
|
|
59
|
+
assert.deepStrictEqual(await (0, localization_extractor_1.extractFromFile)(TEST_FILE, content), {
|
|
60
60
|
'id': 'label',
|
|
61
61
|
'category-key': 'category'
|
|
62
62
|
});
|
|
@@ -66,7 +66,7 @@ describe('correctly extracts from file content', () => {
|
|
|
66
66
|
nls.localize('nested/key1', 'value1');
|
|
67
67
|
nls.localize('nested/key2', 'value2');
|
|
68
68
|
`;
|
|
69
|
-
assert.deepStrictEqual(await localization_extractor_1.extractFromFile(TEST_FILE, content), {
|
|
69
|
+
assert.deepStrictEqual(await (0, localization_extractor_1.extractFromFile)(TEST_FILE, content), {
|
|
70
70
|
'nested': {
|
|
71
71
|
'key1': 'value1',
|
|
72
72
|
'key2': 'value2'
|
|
@@ -78,14 +78,14 @@ describe('correctly extracts from file content', () => {
|
|
|
78
78
|
const a = 'key';
|
|
79
79
|
nls.localize(a, 'value');
|
|
80
80
|
`;
|
|
81
|
-
assert.deepStrictEqual(await localization_extractor_1.extractFromFile(TEST_FILE, content), {
|
|
81
|
+
assert.deepStrictEqual(await (0, localization_extractor_1.extractFromFile)(TEST_FILE, content), {
|
|
82
82
|
'key': 'value'
|
|
83
83
|
});
|
|
84
84
|
});
|
|
85
85
|
it('should return an error when resolving is not successful', async () => {
|
|
86
86
|
const content = "nls.localize(a, 'value')";
|
|
87
87
|
const errors = [];
|
|
88
|
-
assert.deepStrictEqual(await localization_extractor_1.extractFromFile(TEST_FILE, content, errors), {});
|
|
88
|
+
assert.deepStrictEqual(await (0, localization_extractor_1.extractFromFile)(TEST_FILE, content, errors), {});
|
|
89
89
|
assert.deepStrictEqual(errors, [
|
|
90
90
|
"test.ts(1,14): Could not resolve reference to 'a'"
|
|
91
91
|
]);
|
|
@@ -93,7 +93,7 @@ describe('correctly extracts from file content', () => {
|
|
|
93
93
|
it('should return an error when resolving from an expression', async () => {
|
|
94
94
|
const content = "nls.localize(test.value, 'value');";
|
|
95
95
|
const errors = [];
|
|
96
|
-
assert.deepStrictEqual(await localization_extractor_1.extractFromFile(TEST_FILE, content, errors), {});
|
|
96
|
+
assert.deepStrictEqual(await (0, localization_extractor_1.extractFromFile)(TEST_FILE, content, errors), {});
|
|
97
97
|
assert.deepStrictEqual(errors, [
|
|
98
98
|
"test.ts(1,14): 'test.value' is not a string constant"
|
|
99
99
|
]);
|
|
@@ -104,7 +104,7 @@ describe('correctly extracts from file content', () => {
|
|
|
104
104
|
nls.localize('key/nested', 'value');
|
|
105
105
|
`.trim();
|
|
106
106
|
const errors = [];
|
|
107
|
-
assert.deepStrictEqual(await localization_extractor_1.extractFromFile(TEST_FILE, content, errors), {
|
|
107
|
+
assert.deepStrictEqual(await (0, localization_extractor_1.extractFromFile)(TEST_FILE, content, errors), {
|
|
108
108
|
'key': 'value'
|
|
109
109
|
});
|
|
110
110
|
assert.deepStrictEqual(errors, [
|
|
@@ -117,7 +117,7 @@ describe('correctly extracts from file content', () => {
|
|
|
117
117
|
nls.localize('key', 'value');
|
|
118
118
|
`.trim();
|
|
119
119
|
const errors = [];
|
|
120
|
-
assert.deepStrictEqual(await localization_extractor_1.extractFromFile(TEST_FILE, content, errors), {
|
|
120
|
+
assert.deepStrictEqual(await (0, localization_extractor_1.extractFromFile)(TEST_FILE, content, errors), {
|
|
121
121
|
'key': {
|
|
122
122
|
'nested': 'value'
|
|
123
123
|
}
|
|
@@ -129,7 +129,7 @@ describe('correctly extracts from file content', () => {
|
|
|
129
129
|
it('should show error for template literals', async () => {
|
|
130
130
|
const content = 'nls.localize("key", `template literal value`)';
|
|
131
131
|
const errors = [];
|
|
132
|
-
assert.deepStrictEqual(await localization_extractor_1.extractFromFile(TEST_FILE, content, errors), {});
|
|
132
|
+
assert.deepStrictEqual(await (0, localization_extractor_1.extractFromFile)(TEST_FILE, content, errors), {});
|
|
133
133
|
assert.deepStrictEqual(errors, [
|
|
134
134
|
"test.ts(1,20): Template literals are not supported for localization. Please use the additional arguments of the 'nls.localize' function to format strings"
|
|
135
135
|
]);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"localization-extractor.spec.js","sourceRoot":"","sources":["../src/localization-extractor.spec.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;kFAckF;;AAElF,iCAAiC;AACjC,qEAA2D;AAE3D,MAAM,SAAS,GAAG,SAAS,CAAC;AAE5B,QAAQ,CAAC,sCAAsC,EAAE,GAAG,EAAE;IAElD,EAAE,CAAC,gDAAgD,EAAE,KAAK,IAAI,EAAE;QAC5D,MAAM,OAAO,GAAG,8BAA8B,CAAC;QAC/C,MAAM,CAAC,eAAe,CAAC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@@
|
|
|
1
|
+
/********************************************************************************
|
|
2
|
+
* Copyright (C) 2021 TypeFox and others.
|
|
3
|
+
*
|
|
4
|
+
* This program and the accompanying materials are made available under the
|
|
5
|
+
* terms of the Eclipse Public License v. 2.0 which is available at
|
|
6
|
+
* http://www.eclipse.org/legal/epl-2.0.
|
|
7
|
+
*
|
|
8
|
+
* This Source Code may also be made available under the following Secondary
|
|
9
|
+
* Licenses when the conditions for such availability set forth in the Eclipse
|
|
10
|
+
* Public License v. 2.0 are satisfied: GNU General Public License, version 2
|
|
11
|
+
* with the GNU Classpath Exception which is available at
|
|
12
|
+
* https://www.gnu.org/software/classpath/license.html.
|
|
13
|
+
*
|
|
14
|
+
* SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
|
|
15
|
+
********************************************************************************/
|
|
16
|
+
import { Localization } from './common';
|
|
17
|
+
import { deepl, DeeplParameters } from './deepl-api';
|
|
18
|
+
export interface LocalizationOptions {
|
|
19
|
+
freeApi: Boolean;
|
|
20
|
+
authKey: string;
|
|
21
|
+
sourceFile: string;
|
|
22
|
+
sourceLanguage?: string;
|
|
23
|
+
targetLanguages: string[];
|
|
24
|
+
}
|
|
25
|
+
export declare type LocalizationFunction = (parameters: DeeplParameters) => Promise<string[]>;
|
|
26
|
+
export declare class LocalizationManager {
|
|
27
|
+
private localizationFn;
|
|
28
|
+
constructor(localizationFn?: typeof deepl);
|
|
29
|
+
localize(options: LocalizationOptions): Promise<void>;
|
|
30
|
+
protected translationFileName(original: string, language: string): string;
|
|
31
|
+
translateLanguage(source: Localization, target: Localization, targetLanguage: string, options: LocalizationOptions): Promise<void>;
|
|
32
|
+
protected buildLocalizationMap(source: Localization, target: Localization): LocalizationMap;
|
|
33
|
+
}
|
|
34
|
+
export interface LocalizationMap {
|
|
35
|
+
text: string[];
|
|
36
|
+
localize: (index: number, value: string) => void;
|
|
37
|
+
}
|
|
38
|
+
//# sourceMappingURL=localization-manager.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"localization-manager.d.ts","sourceRoot":"","sources":["../src/localization-manager.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;kFAckF;AAKlF,OAAO,EAAE,YAAY,EAAE,MAAM,UAAU,CAAC;AACxC,OAAO,EAAE,KAAK,EAAiB,eAAe,EAA2C,MAAM,aAAa,CAAC;AAE7G,MAAM,WAAW,mBAAmB;IAChC,OAAO,EAAE,OAAO,CAAA;IAChB,OAAO,EAAE,MAAM,CAAA;IACf,UAAU,EAAE,MAAM,CAAA;IAClB,cAAc,CAAC,EAAE,MAAM,CAAA;IACvB,eAAe,EAAE,MAAM,EAAE,CAAA;CAC5B;AAED,oBAAY,oBAAoB,GAAG,CAAC,UAAU,EAAE,eAAe,KAAK,OAAO,CAAC,MAAM,EAAE,CAAC,CAAC;AAEtF,qBAAa,mBAAmB;IAEhB,OAAO,CAAC,cAAc;gBAAd,cAAc,eAAQ;IAEpC,QAAQ,CAAC,OAAO,EAAE,mBAAmB,GAAG,OAAO,CAAC,IAAI,CAAC;IAwC3D,SAAS,CAAC,mBAAmB,CAAC,QAAQ,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAG,MAAM;IAMnE,iBAAiB,CAAC,MAAM,EAAE,YAAY,EAAE,MAAM,EAAE,YAAY,EAAE,cAAc,EAAE,MAAM,EAAE,OAAO,EAAE,mBAAmB,GAAG,OAAO,CAAC,IAAI,CAAC;IAuBxI,SAAS,CAAC,oBAAoB,CAAC,MAAM,EAAE,YAAY,EAAE,MAAM,EAAE,YAAY,GAAG,eAAe;CAoC9F;AAED,MAAM,WAAW,eAAe;IAC5B,IAAI,EAAE,MAAM,EAAE,CAAA;IACd,QAAQ,EAAE,CAAC,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,KAAK,IAAI,CAAA;CACnD"}
|
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/********************************************************************************
|
|
3
|
+
* Copyright (C) 2021 TypeFox and others.
|
|
4
|
+
*
|
|
5
|
+
* This program and the accompanying materials are made available under the
|
|
6
|
+
* terms of the Eclipse Public License v. 2.0 which is available at
|
|
7
|
+
* http://www.eclipse.org/legal/epl-2.0.
|
|
8
|
+
*
|
|
9
|
+
* This Source Code may also be made available under the following Secondary
|
|
10
|
+
* Licenses when the conditions for such availability set forth in the Eclipse
|
|
11
|
+
* Public License v. 2.0 are satisfied: GNU General Public License, version 2
|
|
12
|
+
* with the GNU Classpath Exception which is available at
|
|
13
|
+
* https://www.gnu.org/software/classpath/license.html.
|
|
14
|
+
*
|
|
15
|
+
* SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
|
|
16
|
+
********************************************************************************/
|
|
17
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
|
+
exports.LocalizationManager = void 0;
|
|
19
|
+
const chalk = require("chalk");
|
|
20
|
+
const fs = require("fs-extra");
|
|
21
|
+
const path = require("path");
|
|
22
|
+
const deepl_api_1 = require("./deepl-api");
|
|
23
|
+
class LocalizationManager {
|
|
24
|
+
constructor(localizationFn = deepl_api_1.deepl) {
|
|
25
|
+
this.localizationFn = localizationFn;
|
|
26
|
+
}
|
|
27
|
+
async localize(options) {
|
|
28
|
+
let source = {};
|
|
29
|
+
try {
|
|
30
|
+
source = await fs.readJson(options.sourceFile);
|
|
31
|
+
}
|
|
32
|
+
catch (_a) {
|
|
33
|
+
console.log(chalk.red(`Could not read file "${options.sourceFile}"`));
|
|
34
|
+
process.exit(1);
|
|
35
|
+
}
|
|
36
|
+
const languages = [];
|
|
37
|
+
for (const targetLanguage of options.targetLanguages) {
|
|
38
|
+
if (!(0, deepl_api_1.isSupportedLanguage)(targetLanguage)) {
|
|
39
|
+
console.log(chalk.yellow(`Language "${targetLanguage}" is not supported for automatic localization`));
|
|
40
|
+
}
|
|
41
|
+
else {
|
|
42
|
+
languages.push(targetLanguage);
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
if (languages.length !== options.targetLanguages.length) {
|
|
46
|
+
console.log('Supported languages: ' + deepl_api_1.supportedLanguages.join(', '));
|
|
47
|
+
}
|
|
48
|
+
const existingTranslations = new Map();
|
|
49
|
+
for (const targetLanguage of languages) {
|
|
50
|
+
try {
|
|
51
|
+
const targetPath = this.translationFileName(options.sourceFile, targetLanguage);
|
|
52
|
+
existingTranslations.set(targetLanguage, await fs.readJson(targetPath));
|
|
53
|
+
}
|
|
54
|
+
catch (_b) {
|
|
55
|
+
existingTranslations.set(targetLanguage, {});
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
await Promise.all(languages.map(language => this.translateLanguage(source, existingTranslations.get(language), language, options)));
|
|
59
|
+
for (const targetLanguage of languages) {
|
|
60
|
+
const targetPath = this.translationFileName(options.sourceFile, targetLanguage);
|
|
61
|
+
try {
|
|
62
|
+
await fs.writeFile(targetPath, JSON.stringify(existingTranslations.get(targetLanguage), undefined, 4));
|
|
63
|
+
}
|
|
64
|
+
catch (_c) {
|
|
65
|
+
console.error(chalk.red(`Error writing translated file to '${targetPath}'`));
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
translationFileName(original, language) {
|
|
70
|
+
const directory = path.dirname(original);
|
|
71
|
+
const fileName = path.basename(original, '.json');
|
|
72
|
+
return path.join(directory, `${fileName}.${language.toLowerCase()}.json`);
|
|
73
|
+
}
|
|
74
|
+
async translateLanguage(source, target, targetLanguage, options) {
|
|
75
|
+
var _a;
|
|
76
|
+
const map = this.buildLocalizationMap(source, target);
|
|
77
|
+
if (map.text.length > 0) {
|
|
78
|
+
try {
|
|
79
|
+
const translationResponse = await this.localizationFn({
|
|
80
|
+
auth_key: options.authKey,
|
|
81
|
+
free_api: options.freeApi,
|
|
82
|
+
target_lang: targetLanguage.toUpperCase(),
|
|
83
|
+
source_lang: (_a = options.sourceLanguage) === null || _a === void 0 ? void 0 : _a.toUpperCase(),
|
|
84
|
+
text: map.text
|
|
85
|
+
});
|
|
86
|
+
translationResponse.translations.forEach(({ text }, i) => {
|
|
87
|
+
map.localize(i, text);
|
|
88
|
+
});
|
|
89
|
+
console.log(chalk.green(`Successfully translated ${map.text.length} value${map.text.length > 1 ? 's' : ''} for language "${targetLanguage}"`));
|
|
90
|
+
}
|
|
91
|
+
catch (e) {
|
|
92
|
+
console.log(chalk.red(`Could not translate into language "${targetLanguage}"`), e);
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
else {
|
|
96
|
+
console.log(`No translation necessary for language "${targetLanguage}"`);
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
buildLocalizationMap(source, target) {
|
|
100
|
+
const functionMap = new Map();
|
|
101
|
+
const text = [];
|
|
102
|
+
const process = (s, t) => {
|
|
103
|
+
// Delete all extra keys in the target translation first
|
|
104
|
+
for (const key of Object.keys(t)) {
|
|
105
|
+
if (!(key in s)) {
|
|
106
|
+
delete t[key];
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
for (const [key, value] of Object.entries(s)) {
|
|
110
|
+
if (!(key in t)) {
|
|
111
|
+
if (typeof value === 'string') {
|
|
112
|
+
functionMap.set(text.length, translation => t[key] = translation);
|
|
113
|
+
text.push(value);
|
|
114
|
+
}
|
|
115
|
+
else {
|
|
116
|
+
const newLocalization = {};
|
|
117
|
+
t[key] = newLocalization;
|
|
118
|
+
process(value, newLocalization);
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
else if (typeof value === 'object') {
|
|
122
|
+
if (typeof t[key] === 'string') {
|
|
123
|
+
t[key] = {};
|
|
124
|
+
}
|
|
125
|
+
process(value, t[key]);
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
};
|
|
129
|
+
process(source, target);
|
|
130
|
+
return {
|
|
131
|
+
text,
|
|
132
|
+
localize: (index, value) => functionMap.get(index)(value)
|
|
133
|
+
};
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
exports.LocalizationManager = LocalizationManager;
|
|
137
|
+
//# sourceMappingURL=localization-manager.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"localization-manager.js","sourceRoot":"","sources":["../src/localization-manager.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;kFAckF;;;AAElF,+BAA+B;AAC/B,+BAA+B;AAC/B,6BAA6B;AAE7B,2CAA6G;AAY7G,MAAa,mBAAmB;IAE5B,YAAoB,iBAAiB,iBAAK;QAAtB,mBAAc,GAAd,cAAc,CAAQ;IAAI,CAAC;IAE/C,KAAK,CAAC,QAAQ,CAAC,OAA4B;QACvC,IAAI,MAAM,GAAiB,EAAE,CAAC;QAC9B,IAAI;YACA,MAAM,GAAG,MAAM,EAAE,CAAC,QAAQ,CAAC,OAAO,CAAC,UAAU,CAAC,CAAC;SAClD;QAAC,WAAM;YACJ,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,GAAG,CAAC,wBAAwB,OAAO,CAAC,UAAU,GAAG,CAAC,CAAC,CAAC;YACtE,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;SACnB;QACD,MAAM,SAAS,GAAa,EAAE,CAAC;QAC/B,KAAK,MAAM,cAAc,IAAI,OAAO,CAAC,eAAe,EAAE;YAClD,IAAI,CAAC,IAAA,+BAAmB,EAAC,cAAc,CAAC,EAAE;gBACtC,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,MAAM,CAAC,aAAa,cAAc,+CAA+C,CAAC,CAAC,CAAC;aACzG;iBAAM;gBACH,SAAS,CAAC,IAAI,CAAC,cAAc,CAAC,CAAC;aAClC;SACJ;QACD,IAAI,SAAS,CAAC,MAAM,KAAK,OAAO,CAAC,eAAe,CAAC,MAAM,EAAE;YACrD,OAAO,CAAC,GAAG,CAAC,uBAAuB,GAAG,8BAAkB,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC;SACxE;QACD,MAAM,oBAAoB,GAA8B,IAAI,GAAG,EAAE,CAAC;QAClE,KAAK,MAAM,cAAc,IAA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;YACH,IAAI;YACJ,QAAQ,EAAE,CAAC,KAAK,EAAE,KAAK,EAAE,EAAE,CAAC,WAAW,CAAC,GAAG,CAAC,KAAK,CAAE,CAAC,KAAK,CAAC;SAC7D,CAAC;IACN,CAAC;CACJ;AA7GD,kDA6GC"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/********************************************************************************
|
|
2
|
+
* Copyright (C) 2021 TypeFox and others.
|
|
3
|
+
*
|
|
4
|
+
* This program and the accompanying materials are made available under the
|
|
5
|
+
* terms of the Eclipse Public License v. 2.0 which is available at
|
|
6
|
+
* http://www.eclipse.org/legal/epl-2.0.
|
|
7
|
+
*
|
|
8
|
+
* This Source Code may also be made available under the following Secondary
|
|
9
|
+
* Licenses when the conditions for such availability set forth in the Eclipse
|
|
10
|
+
* Public License v. 2.0 are satisfied: GNU General Public License, version 2
|
|
11
|
+
* with the GNU Classpath Exception which is available at
|
|
12
|
+
* https://www.gnu.org/software/classpath/license.html.
|
|
13
|
+
*
|
|
14
|
+
* SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
|
|
15
|
+
********************************************************************************/
|
|
16
|
+
export {};
|
|
17
|
+
//# sourceMappingURL=localization-manager.spec.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"localization-manager.spec.d.ts","sourceRoot":"","sources":["../src/localization-manager.spec.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;kFAckF"}
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/********************************************************************************
|
|
3
|
+
* Copyright (C) 2021 TypeFox and others.
|
|
4
|
+
*
|
|
5
|
+
* This program and the accompanying materials are made available under the
|
|
6
|
+
* terms of the Eclipse Public License v. 2.0 which is available at
|
|
7
|
+
* http://www.eclipse.org/legal/epl-2.0.
|
|
8
|
+
*
|
|
9
|
+
* This Source Code may also be made available under the following Secondary
|
|
10
|
+
* Licenses when the conditions for such availability set forth in the Eclipse
|
|
11
|
+
* Public License v. 2.0 are satisfied: GNU General Public License, version 2
|
|
12
|
+
* with the GNU Classpath Exception which is available at
|
|
13
|
+
* https://www.gnu.org/software/classpath/license.html.
|
|
14
|
+
*
|
|
15
|
+
* SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
|
|
16
|
+
********************************************************************************/
|
|
17
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
|
+
const assert = require("assert");
|
|
19
|
+
const localization_manager_1 = require("./localization-manager");
|
|
20
|
+
describe('localization-manager#translateLanguage', () => {
|
|
21
|
+
async function mockLocalization(parameters) {
|
|
22
|
+
return {
|
|
23
|
+
translations: parameters.text.map(value => ({
|
|
24
|
+
detected_source_language: '',
|
|
25
|
+
text: `[${value}]`
|
|
26
|
+
}))
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
const manager = new localization_manager_1.LocalizationManager(mockLocalization);
|
|
30
|
+
const defaultOptions = {
|
|
31
|
+
authKey: '',
|
|
32
|
+
freeApi: false,
|
|
33
|
+
sourceFile: '',
|
|
34
|
+
targetLanguages: ['EN']
|
|
35
|
+
};
|
|
36
|
+
it('should translate a single value', async () => {
|
|
37
|
+
const input = {
|
|
38
|
+
key: 'value'
|
|
39
|
+
};
|
|
40
|
+
const target = {};
|
|
41
|
+
await manager.translateLanguage(input, target, 'EN', defaultOptions);
|
|
42
|
+
assert.deepStrictEqual(target, {
|
|
43
|
+
key: '[value]'
|
|
44
|
+
});
|
|
45
|
+
});
|
|
46
|
+
it('should translate nested values', async () => {
|
|
47
|
+
const input = {
|
|
48
|
+
a: {
|
|
49
|
+
b: 'b'
|
|
50
|
+
},
|
|
51
|
+
c: 'c'
|
|
52
|
+
};
|
|
53
|
+
const target = {};
|
|
54
|
+
await manager.translateLanguage(input, target, 'EN', defaultOptions);
|
|
55
|
+
assert.deepStrictEqual(target, {
|
|
56
|
+
a: {
|
|
57
|
+
b: '[b]'
|
|
58
|
+
},
|
|
59
|
+
c: '[c]'
|
|
60
|
+
});
|
|
61
|
+
});
|
|
62
|
+
it('should not override existing targets', async () => {
|
|
63
|
+
const input = {
|
|
64
|
+
a: 'a'
|
|
65
|
+
};
|
|
66
|
+
const target = {
|
|
67
|
+
a: 'b'
|
|
68
|
+
};
|
|
69
|
+
await manager.translateLanguage(input, target, 'EN', defaultOptions);
|
|
70
|
+
assert.deepStrictEqual(target, {
|
|
71
|
+
a: 'b'
|
|
72
|
+
});
|
|
73
|
+
});
|
|
74
|
+
});
|
|
75
|
+
//# sourceMappingURL=localization-manager.spec.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"localization-manager.spec.js","sourceRoot":"","sources":["../src/localization-manager.spec.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;kFAckF;;AAElF,iCAAiC;AAEjC,iEAAkF;AAElF,QAAQ,CAAC,wCAAwC,EAAE,GAAG,EAAE;IAEpD,KAAK,UAAU,gBAAgB,CAAC,UAA2B;QACvD,OAAO;YACH,YAAY,EAAE,UAAU,CAAC,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC;gBACxC,wBAAwB,EAAE,EAAE;gBAC5B,IAAI,EAAE,IAAI,KAAK,GAAG;aACrB,CAAC,CAAC;SACN,CAAC;IACN,CAAC;IAED,MAAM,OAAO,GAAG,IAAI,0CAAmB,CAAC,gBAAgB,CAAC,CAAC;IAC1D,MAAM,cAAc,GAAwB;QACxC,OAAO,EAAE,EAAE;QACX,OAAO,EAAE,KAAK;QACd,UAAU,EAAE,EAAE;QACd,eAAe,EAAE,CAAC,IAAI,CAAC;KAC1B,CAAC;IAEF,EAAE,CAAC,iCAAiC,EAAE,KAAK,IAAI,EAAE;QAC7C,MAAM,KAAK,GAAG;YACV,GAAG,EAAE,OAAO;SACf,CAAC;QACF,MAAM,MAAM,GAAG,EAAE,CAAC;QAClB,MAAM,OAAO,CAAC,iBAAiB,CAAC,KAAK,EAAE,MAAM,EAAE,IAAI,EAAE,cAAc,CAAC,CAAC;QACrE,MAAM,CAAC,eAAe,CAAC,MAAM,EAAE;YAC3B,GAAG,EAAE,SAAS;SACjB,CAAC,CAAC;IACP,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,gCAAgC,EAAE,KAAK,IAAI,EAAE;QAC5C,MAAM,KAAK,GAAG;YACV,CAAC,EAAE;gBACC,CAAC,EAAE,GAAG;aACT;YACD,CAAC,EAAE,GAAG;SACT,CAAC;QACF,MAAM,MAAM,GAAG,EAAE,CAAC;QAClB,MAAM,OAAO,CAAC,iBAAiB,CAAC,KAAK,EAAE,MAAM,EAAE,IAAI,EAAE,cAAc,CAAC,CAAC;QACrE,MAAM,CAAC,eAAe,CAAC,MAAM,EAAE;YAC3B,CAAC,EAAE;gBACC,CAAC,EAAE,KAAK;aACX;YACD,CAAC,EAAE,KAAK;SACX,CAAC,CAAC;IACP,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,sCAAsC,EAAE,KAAK,IAAI,EAAE;QAClD,MAAM,KAAK,GAAG;YACV,CAAC,EAAE,GAAG;SACT,CAAC;QACF,MAAM,MAAM,GAAG;YACX,CAAC,EAAE,GAAG;SACT,CAAC;QACF,MAAM,OAAO,CAAC,iBAAiB,CAAC,KAAK,EAAE,MAAM,EAAE,IAAI,EAAE,cAAc,CAAC,CAAC;QACrE,MAAM,CAAC,eAAe,CAAC,MAAM,EAAE;YAC3B,CAAC,EAAE,GAAG;SACT,CAAC,CAAC;IACP,CAAC,CAAC,CAAC;AACP,CAAC,CAAC,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@theia/localization-manager",
|
|
3
|
-
"version": "1.23.0-next.
|
|
3
|
+
"version": "1.23.0-next.24+b2d1870e76f",
|
|
4
4
|
"description": "Theia localization manager API.",
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"access": "public"
|
|
@@ -29,11 +29,14 @@
|
|
|
29
29
|
"watch": "theiaext watch"
|
|
30
30
|
},
|
|
31
31
|
"dependencies": {
|
|
32
|
+
"@types/bent": "^7.0.1",
|
|
32
33
|
"@types/fs-extra": "^4.0.2",
|
|
34
|
+
"bent": "^7.1.0",
|
|
35
|
+
"chalk": "4.0.0",
|
|
33
36
|
"deepmerge": "^4.2.2",
|
|
34
37
|
"fs-extra": "^4.0.2",
|
|
35
38
|
"glob": "^7.2.0",
|
|
36
|
-
"typescript": "
|
|
39
|
+
"typescript": "~4.5.5"
|
|
37
40
|
},
|
|
38
41
|
"devDependencies": {
|
|
39
42
|
"@theia/ext-scripts": "1.22.1"
|
|
@@ -41,5 +44,5 @@
|
|
|
41
44
|
"nyc": {
|
|
42
45
|
"extends": "../../configs/nyc.json"
|
|
43
46
|
},
|
|
44
|
-
"gitHead": "
|
|
47
|
+
"gitHead": "b2d1870e76f9d943abfe5c8b38817d95d5a54ee6"
|
|
45
48
|
}
|
package/src/common.ts
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/********************************************************************************
|
|
2
|
+
* Copyright (C) 2021 TypeFox and others.
|
|
3
|
+
*
|
|
4
|
+
* This program and the accompanying materials are made available under the
|
|
5
|
+
* terms of the Eclipse Public License v. 2.0 which is available at
|
|
6
|
+
* http://www.eclipse.org/legal/epl-2.0.
|
|
7
|
+
*
|
|
8
|
+
* This Source Code may also be made available under the following Secondary
|
|
9
|
+
* Licenses when the conditions for such availability set forth in the Eclipse
|
|
10
|
+
* Public License v. 2.0 are satisfied: GNU General Public License, version 2
|
|
11
|
+
* with the GNU Classpath Exception which is available at
|
|
12
|
+
* https://www.gnu.org/software/classpath/license.html.
|
|
13
|
+
*
|
|
14
|
+
* SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
|
|
15
|
+
********************************************************************************/
|
|
16
|
+
|
|
17
|
+
export interface Localization {
|
|
18
|
+
[key: string]: string | Localization
|
|
19
|
+
}
|
package/src/deepl-api.ts
ADDED
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
/********************************************************************************
|
|
2
|
+
* Copyright (C) 2021 TypeFox and others.
|
|
3
|
+
*
|
|
4
|
+
* This program and the accompanying materials are made available under the
|
|
5
|
+
* terms of the Eclipse Public License v. 2.0 which is available at
|
|
6
|
+
* http://www.eclipse.org/legal/epl-2.0.
|
|
7
|
+
*
|
|
8
|
+
* This Source Code may also be made available under the following Secondary
|
|
9
|
+
* Licenses when the conditions for such availability set forth in the Eclipse
|
|
10
|
+
* Public License v. 2.0 are satisfied: GNU General Public License, version 2
|
|
11
|
+
* with the GNU Classpath Exception which is available at
|
|
12
|
+
* https://www.gnu.org/software/classpath/license.html.
|
|
13
|
+
*
|
|
14
|
+
* SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
|
|
15
|
+
********************************************************************************/
|
|
16
|
+
|
|
17
|
+
import * as bent from 'bent';
|
|
18
|
+
|
|
19
|
+
const post = bent('POST', 'json', 200);
|
|
20
|
+
// 50 is the maximum amount of translations per request
|
|
21
|
+
const deeplLimit = 50;
|
|
22
|
+
|
|
23
|
+
export async function deepl(
|
|
24
|
+
parameters: DeeplParameters
|
|
25
|
+
): Promise<DeeplResponse> {
|
|
26
|
+
const sub_domain = parameters.free_api ? 'api-free' : 'api';
|
|
27
|
+
const textChunks: string[][] = [];
|
|
28
|
+
const textArray = [...parameters.text];
|
|
29
|
+
while (textArray.length > 0) {
|
|
30
|
+
textChunks.push(textArray.splice(0, deeplLimit));
|
|
31
|
+
}
|
|
32
|
+
const responses: DeeplResponse[] = await Promise.all(textChunks.map(chunk => {
|
|
33
|
+
const parameterCopy: DeeplParameters = { ...parameters, text: chunk };
|
|
34
|
+
return post(`https://${sub_domain}.deepl.com/v2/translate`, Buffer.from(toFormData(parameterCopy)), {
|
|
35
|
+
'Content-Type': 'application/x-www-form-urlencoded',
|
|
36
|
+
'User-Agent': 'Theia-Localization-Manager'
|
|
37
|
+
});
|
|
38
|
+
}));
|
|
39
|
+
const mergedResponse: DeeplResponse = { translations: [] };
|
|
40
|
+
for (const response of responses) {
|
|
41
|
+
mergedResponse.translations.push(...response.translations);
|
|
42
|
+
}
|
|
43
|
+
return mergedResponse;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
function toFormData(parameters: DeeplParameters): string {
|
|
47
|
+
const str: string[] = [];
|
|
48
|
+
for (const [key, value] of Object.entries(parameters)) {
|
|
49
|
+
if (typeof value === 'string') {
|
|
50
|
+
str.push(encodeURIComponent(key) + '=' + encodeURIComponent(value.toString()));
|
|
51
|
+
} else if (Array.isArray(value)) {
|
|
52
|
+
for (const item of value) {
|
|
53
|
+
str.push(encodeURIComponent(key) + '=' + encodeURIComponent(item.toString()));
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
return str.join('&');
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
export type DeeplLanguage =
|
|
61
|
+
| 'BG'
|
|
62
|
+
| 'CS'
|
|
63
|
+
| 'DA'
|
|
64
|
+
| 'DE'
|
|
65
|
+
| 'EL'
|
|
66
|
+
| 'EN-GB'
|
|
67
|
+
| 'EN-US'
|
|
68
|
+
| 'EN'
|
|
69
|
+
| 'ES'
|
|
70
|
+
| 'ET'
|
|
71
|
+
| 'FI'
|
|
72
|
+
| 'FR'
|
|
73
|
+
| 'HU'
|
|
74
|
+
| 'IT'
|
|
75
|
+
| 'JA'
|
|
76
|
+
| 'LT'
|
|
77
|
+
| 'LV'
|
|
78
|
+
| 'NL'
|
|
79
|
+
| 'PL'
|
|
80
|
+
| 'PT-PT'
|
|
81
|
+
| 'PT-BR'
|
|
82
|
+
| 'PT'
|
|
83
|
+
| 'RO'
|
|
84
|
+
| 'RU'
|
|
85
|
+
| 'SK'
|
|
86
|
+
| 'SL'
|
|
87
|
+
| 'SV'
|
|
88
|
+
| 'ZH';
|
|
89
|
+
|
|
90
|
+
export const supportedLanguages = [
|
|
91
|
+
'BG', 'CD', 'DA', 'DE', 'EL', 'EN-GB', 'EN-US', 'EN', 'ES', 'ET', 'FI', 'FR', 'HU', 'IT',
|
|
92
|
+
'JA', 'LT', 'LV', 'NL', 'PL', 'PT-PT', 'PT-BR', 'PT', 'RO', 'RU', 'SK', 'SL', 'SV', 'ZH'
|
|
93
|
+
];
|
|
94
|
+
|
|
95
|
+
export function isSupportedLanguage(language: string): language is DeeplLanguage {
|
|
96
|
+
return supportedLanguages.includes(language.toUpperCase());
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
export interface DeeplParameters {
|
|
100
|
+
free_api: Boolean
|
|
101
|
+
auth_key: string
|
|
102
|
+
text: string[]
|
|
103
|
+
source_lang?: DeeplLanguage
|
|
104
|
+
target_lang: DeeplLanguage
|
|
105
|
+
split_sentences?: '0' | '1' | 'nonewlines'
|
|
106
|
+
preserve_formatting?: '0' | '1'
|
|
107
|
+
formality?: 'default' | 'more' | 'less'
|
|
108
|
+
tag_handling?: string[]
|
|
109
|
+
non_splitting_tags?: string[]
|
|
110
|
+
outline_detection?: string
|
|
111
|
+
splitting_tags?: string[]
|
|
112
|
+
ignore_tags?: string[]
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
export interface DeeplResponse {
|
|
116
|
+
translations: DeeplTranslation[]
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
export interface DeeplTranslation {
|
|
120
|
+
detected_source_language: string
|
|
121
|
+
text: string
|
|
122
|
+
}
|
package/src/index.ts
CHANGED
|
@@ -14,4 +14,6 @@
|
|
|
14
14
|
* SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
|
|
15
15
|
********************************************************************************/
|
|
16
16
|
|
|
17
|
+
export * from './common';
|
|
17
18
|
export * from './localization-extractor';
|
|
19
|
+
export * from './localization-manager';
|
|
@@ -21,13 +21,10 @@ import * as path from 'path';
|
|
|
21
21
|
import { glob } from 'glob';
|
|
22
22
|
import { promisify } from 'util';
|
|
23
23
|
import deepmerge = require('deepmerge');
|
|
24
|
+
import { Localization } from './common';
|
|
24
25
|
|
|
25
26
|
const globPromise = promisify(glob);
|
|
26
27
|
|
|
27
|
-
export interface Localization {
|
|
28
|
-
[key: string]: string | Localization
|
|
29
|
-
}
|
|
30
|
-
|
|
31
28
|
export interface ExtractionOptions {
|
|
32
29
|
root: string
|
|
33
30
|
output: string
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
/********************************************************************************
|
|
2
|
+
* Copyright (C) 2021 TypeFox and others.
|
|
3
|
+
*
|
|
4
|
+
* This program and the accompanying materials are made available under the
|
|
5
|
+
* terms of the Eclipse Public License v. 2.0 which is available at
|
|
6
|
+
* http://www.eclipse.org/legal/epl-2.0.
|
|
7
|
+
*
|
|
8
|
+
* This Source Code may also be made available under the following Secondary
|
|
9
|
+
* Licenses when the conditions for such availability set forth in the Eclipse
|
|
10
|
+
* Public License v. 2.0 are satisfied: GNU General Public License, version 2
|
|
11
|
+
* with the GNU Classpath Exception which is available at
|
|
12
|
+
* https://www.gnu.org/software/classpath/license.html.
|
|
13
|
+
*
|
|
14
|
+
* SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
|
|
15
|
+
********************************************************************************/
|
|
16
|
+
|
|
17
|
+
import * as assert from 'assert';
|
|
18
|
+
import { DeeplParameters, DeeplResponse } from './deepl-api';
|
|
19
|
+
import { LocalizationManager, LocalizationOptions } from './localization-manager';
|
|
20
|
+
|
|
21
|
+
describe('localization-manager#translateLanguage', () => {
|
|
22
|
+
|
|
23
|
+
async function mockLocalization(parameters: DeeplParameters): Promise<DeeplResponse> {
|
|
24
|
+
return {
|
|
25
|
+
translations: parameters.text.map(value => ({
|
|
26
|
+
detected_source_language: '',
|
|
27
|
+
text: `[${value}]`
|
|
28
|
+
}))
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
const manager = new LocalizationManager(mockLocalization);
|
|
33
|
+
const defaultOptions: LocalizationOptions = {
|
|
34
|
+
authKey: '',
|
|
35
|
+
freeApi: false,
|
|
36
|
+
sourceFile: '',
|
|
37
|
+
targetLanguages: ['EN']
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
it('should translate a single value', async () => {
|
|
41
|
+
const input = {
|
|
42
|
+
key: 'value'
|
|
43
|
+
};
|
|
44
|
+
const target = {};
|
|
45
|
+
await manager.translateLanguage(input, target, 'EN', defaultOptions);
|
|
46
|
+
assert.deepStrictEqual(target, {
|
|
47
|
+
key: '[value]'
|
|
48
|
+
});
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
it('should translate nested values', async () => {
|
|
52
|
+
const input = {
|
|
53
|
+
a: {
|
|
54
|
+
b: 'b'
|
|
55
|
+
},
|
|
56
|
+
c: 'c'
|
|
57
|
+
};
|
|
58
|
+
const target = {};
|
|
59
|
+
await manager.translateLanguage(input, target, 'EN', defaultOptions);
|
|
60
|
+
assert.deepStrictEqual(target, {
|
|
61
|
+
a: {
|
|
62
|
+
b: '[b]'
|
|
63
|
+
},
|
|
64
|
+
c: '[c]'
|
|
65
|
+
});
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
it('should not override existing targets', async () => {
|
|
69
|
+
const input = {
|
|
70
|
+
a: 'a'
|
|
71
|
+
};
|
|
72
|
+
const target = {
|
|
73
|
+
a: 'b'
|
|
74
|
+
};
|
|
75
|
+
await manager.translateLanguage(input, target, 'EN', defaultOptions);
|
|
76
|
+
assert.deepStrictEqual(target, {
|
|
77
|
+
a: 'b'
|
|
78
|
+
});
|
|
79
|
+
});
|
|
80
|
+
});
|
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
/********************************************************************************
|
|
2
|
+
* Copyright (C) 2021 TypeFox and others.
|
|
3
|
+
*
|
|
4
|
+
* This program and the accompanying materials are made available under the
|
|
5
|
+
* terms of the Eclipse Public License v. 2.0 which is available at
|
|
6
|
+
* http://www.eclipse.org/legal/epl-2.0.
|
|
7
|
+
*
|
|
8
|
+
* This Source Code may also be made available under the following Secondary
|
|
9
|
+
* Licenses when the conditions for such availability set forth in the Eclipse
|
|
10
|
+
* Public License v. 2.0 are satisfied: GNU General Public License, version 2
|
|
11
|
+
* with the GNU Classpath Exception which is available at
|
|
12
|
+
* https://www.gnu.org/software/classpath/license.html.
|
|
13
|
+
*
|
|
14
|
+
* SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
|
|
15
|
+
********************************************************************************/
|
|
16
|
+
|
|
17
|
+
import * as chalk from 'chalk';
|
|
18
|
+
import * as fs from 'fs-extra';
|
|
19
|
+
import * as path from 'path';
|
|
20
|
+
import { Localization } from './common';
|
|
21
|
+
import { deepl, DeeplLanguage, DeeplParameters, isSupportedLanguage, supportedLanguages } from './deepl-api';
|
|
22
|
+
|
|
23
|
+
export interface LocalizationOptions {
|
|
24
|
+
freeApi: Boolean
|
|
25
|
+
authKey: string
|
|
26
|
+
sourceFile: string
|
|
27
|
+
sourceLanguage?: string
|
|
28
|
+
targetLanguages: string[]
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export type LocalizationFunction = (parameters: DeeplParameters) => Promise<string[]>;
|
|
32
|
+
|
|
33
|
+
export class LocalizationManager {
|
|
34
|
+
|
|
35
|
+
constructor(private localizationFn = deepl) { }
|
|
36
|
+
|
|
37
|
+
async localize(options: LocalizationOptions): Promise<void> {
|
|
38
|
+
let source: Localization = {};
|
|
39
|
+
try {
|
|
40
|
+
source = await fs.readJson(options.sourceFile);
|
|
41
|
+
} catch {
|
|
42
|
+
console.log(chalk.red(`Could not read file "${options.sourceFile}"`));
|
|
43
|
+
process.exit(1);
|
|
44
|
+
}
|
|
45
|
+
const languages: string[] = [];
|
|
46
|
+
for (const targetLanguage of options.targetLanguages) {
|
|
47
|
+
if (!isSupportedLanguage(targetLanguage)) {
|
|
48
|
+
console.log(chalk.yellow(`Language "${targetLanguage}" is not supported for automatic localization`));
|
|
49
|
+
} else {
|
|
50
|
+
languages.push(targetLanguage);
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
if (languages.length !== options.targetLanguages.length) {
|
|
54
|
+
console.log('Supported languages: ' + supportedLanguages.join(', '));
|
|
55
|
+
}
|
|
56
|
+
const existingTranslations: Map<string, Localization> = new Map();
|
|
57
|
+
for (const targetLanguage of languages) {
|
|
58
|
+
try {
|
|
59
|
+
const targetPath = this.translationFileName(options.sourceFile, targetLanguage);
|
|
60
|
+
existingTranslations.set(targetLanguage, await fs.readJson(targetPath));
|
|
61
|
+
} catch {
|
|
62
|
+
existingTranslations.set(targetLanguage, {});
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
await Promise.all(languages.map(language => this.translateLanguage(source, existingTranslations.get(language)!, language, options)));
|
|
66
|
+
|
|
67
|
+
for (const targetLanguage of languages) {
|
|
68
|
+
const targetPath = this.translationFileName(options.sourceFile, targetLanguage);
|
|
69
|
+
try {
|
|
70
|
+
await fs.writeFile(targetPath, JSON.stringify(existingTranslations.get(targetLanguage)!, undefined, 4));
|
|
71
|
+
} catch {
|
|
72
|
+
console.error(chalk.red(`Error writing translated file to '${targetPath}'`));
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
protected translationFileName(original: string, language: string): string {
|
|
78
|
+
const directory = path.dirname(original);
|
|
79
|
+
const fileName = path.basename(original, '.json');
|
|
80
|
+
return path.join(directory, `${fileName}.${language.toLowerCase()}.json`);
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
async translateLanguage(source: Localization, target: Localization, targetLanguage: string, options: LocalizationOptions): Promise<void> {
|
|
84
|
+
const map = this.buildLocalizationMap(source, target);
|
|
85
|
+
if (map.text.length > 0) {
|
|
86
|
+
try {
|
|
87
|
+
const translationResponse = await this.localizationFn({
|
|
88
|
+
auth_key: options.authKey,
|
|
89
|
+
free_api: options.freeApi,
|
|
90
|
+
target_lang: targetLanguage.toUpperCase() as DeeplLanguage,
|
|
91
|
+
source_lang: options.sourceLanguage?.toUpperCase() as DeeplLanguage,
|
|
92
|
+
text: map.text
|
|
93
|
+
});
|
|
94
|
+
translationResponse.translations.forEach(({ text }, i) => {
|
|
95
|
+
map.localize(i, text);
|
|
96
|
+
});
|
|
97
|
+
console.log(chalk.green(`Successfully translated ${map.text.length} value${map.text.length > 1 ? 's' : ''} for language "${targetLanguage}"`));
|
|
98
|
+
} catch (e) {
|
|
99
|
+
console.log(chalk.red(`Could not translate into language "${targetLanguage}"`), e);
|
|
100
|
+
}
|
|
101
|
+
} else {
|
|
102
|
+
console.log(`No translation necessary for language "${targetLanguage}"`);
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
protected buildLocalizationMap(source: Localization, target: Localization): LocalizationMap {
|
|
107
|
+
const functionMap = new Map<number, (value: string) => void>();
|
|
108
|
+
const text: string[] = [];
|
|
109
|
+
const process = (s: Localization, t: Localization) => {
|
|
110
|
+
// Delete all extra keys in the target translation first
|
|
111
|
+
for (const key of Object.keys(t)) {
|
|
112
|
+
if (!(key in s)) {
|
|
113
|
+
delete t[key];
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
for (const [key, value] of Object.entries(s)) {
|
|
117
|
+
if (!(key in t)) {
|
|
118
|
+
if (typeof value === 'string') {
|
|
119
|
+
functionMap.set(text.length, translation => t[key] = translation);
|
|
120
|
+
text.push(value);
|
|
121
|
+
} else {
|
|
122
|
+
const newLocalization: Localization = {};
|
|
123
|
+
t[key] = newLocalization;
|
|
124
|
+
process(value, newLocalization);
|
|
125
|
+
}
|
|
126
|
+
} else if (typeof value === 'object') {
|
|
127
|
+
if (typeof t[key] === 'string') {
|
|
128
|
+
t[key] = {};
|
|
129
|
+
}
|
|
130
|
+
process(value, t[key] as Localization);
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
};
|
|
134
|
+
|
|
135
|
+
process(source, target);
|
|
136
|
+
|
|
137
|
+
return {
|
|
138
|
+
text,
|
|
139
|
+
localize: (index, value) => functionMap.get(index)!(value)
|
|
140
|
+
};
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
export interface LocalizationMap {
|
|
145
|
+
text: string[]
|
|
146
|
+
localize: (index: number, value: string) => void
|
|
147
|
+
}
|