@theia/localization-manager 1.45.0 → 1.46.0-next.72
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 +67 -67
- package/lib/common.d.ts +4 -4
- package/lib/common.js +26 -26
- package/lib/deepl-api.d.ts +26 -26
- package/lib/deepl-api.js +93 -93
- package/lib/index.d.ts +3 -3
- package/lib/index.js +30 -30
- package/lib/localization-extractor.d.ts +13 -13
- package/lib/localization-extractor.js +368 -368
- package/lib/localization-extractor.spec.d.ts +1 -1
- package/lib/localization-extractor.spec.js +138 -138
- package/lib/localization-manager.d.ts +24 -24
- package/lib/localization-manager.js +148 -148
- package/lib/localization-manager.spec.d.ts +1 -1
- package/lib/localization-manager.spec.js +84 -84
- package/package.json +3 -3
- package/src/common.ts +27 -27
- package/src/deepl-api.ts +153 -153
- package/src/index.ts +19 -19
- package/src/localization-extractor.spec.ts +151 -151
- package/src/localization-extractor.ts +422 -422
- package/src/localization-manager.spec.ts +91 -91
- package/src/localization-manager.ts +160 -160
|
@@ -1,151 +1,151 @@
|
|
|
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-only WITH Classpath-exception-2.0
|
|
15
|
-
// *****************************************************************************
|
|
16
|
-
|
|
17
|
-
import * as assert from 'assert';
|
|
18
|
-
import { extractFromFile, ExtractionOptions } from './localization-extractor';
|
|
19
|
-
|
|
20
|
-
const TEST_FILE = 'test.ts';
|
|
21
|
-
const quiet: ExtractionOptions = { quiet: true };
|
|
22
|
-
|
|
23
|
-
describe('correctly extracts from file content', () => {
|
|
24
|
-
|
|
25
|
-
it('should extract from simple nls.localize() call', async () => {
|
|
26
|
-
const content = 'nls.localize("key", "value")';
|
|
27
|
-
assert.deepStrictEqual(await extractFromFile(TEST_FILE, content), {
|
|
28
|
-
'key': 'value'
|
|
29
|
-
});
|
|
30
|
-
});
|
|
31
|
-
|
|
32
|
-
it('should extract from nested nls.localize() call', async () => {
|
|
33
|
-
const content = 'nls.localize("nested/key", "value")';
|
|
34
|
-
assert.deepStrictEqual(await extractFromFile(TEST_FILE, content), {
|
|
35
|
-
'nested': {
|
|
36
|
-
'key': 'value'
|
|
37
|
-
}
|
|
38
|
-
});
|
|
39
|
-
});
|
|
40
|
-
|
|
41
|
-
it('should extract IDs from Command.toLocalizedCommand() call', async () => {
|
|
42
|
-
const content = `
|
|
43
|
-
Command.toLocalizedCommand({
|
|
44
|
-
id: 'command-id1',
|
|
45
|
-
label: 'command-label1'
|
|
46
|
-
});
|
|
47
|
-
Command.toLocalizedCommand({
|
|
48
|
-
id: 'command-id2',
|
|
49
|
-
label: 'command-label2'
|
|
50
|
-
}, 'command-key');
|
|
51
|
-
`;
|
|
52
|
-
assert.deepStrictEqual(await extractFromFile(TEST_FILE, content), {
|
|
53
|
-
'command-id1': 'command-label1',
|
|
54
|
-
'command-key': 'command-label2'
|
|
55
|
-
});
|
|
56
|
-
});
|
|
57
|
-
|
|
58
|
-
it('should extract category from Command.toLocalizedCommand() call', async () => {
|
|
59
|
-
const content = `
|
|
60
|
-
Command.toLocalizedCommand({
|
|
61
|
-
id: 'id',
|
|
62
|
-
label: 'label',
|
|
63
|
-
category: 'category'
|
|
64
|
-
}, undefined, 'category-key');`;
|
|
65
|
-
assert.deepStrictEqual(await extractFromFile(TEST_FILE, content), {
|
|
66
|
-
'id': 'label',
|
|
67
|
-
'category-key': 'category'
|
|
68
|
-
});
|
|
69
|
-
});
|
|
70
|
-
|
|
71
|
-
it('should merge different nls.localize() calls', async () => {
|
|
72
|
-
const content = `
|
|
73
|
-
nls.localize('nested/key1', 'value1');
|
|
74
|
-
nls.localize('nested/key2', 'value2');
|
|
75
|
-
`;
|
|
76
|
-
assert.deepStrictEqual(await extractFromFile(TEST_FILE, content), {
|
|
77
|
-
'nested': {
|
|
78
|
-
'key1': 'value1',
|
|
79
|
-
'key2': 'value2'
|
|
80
|
-
}
|
|
81
|
-
});
|
|
82
|
-
});
|
|
83
|
-
|
|
84
|
-
it('should be able to resolve local references', async () => {
|
|
85
|
-
const content = `
|
|
86
|
-
const a = 'key';
|
|
87
|
-
nls.localize(a, 'value');
|
|
88
|
-
`;
|
|
89
|
-
assert.deepStrictEqual(await extractFromFile(TEST_FILE, content), {
|
|
90
|
-
'key': 'value'
|
|
91
|
-
});
|
|
92
|
-
});
|
|
93
|
-
|
|
94
|
-
it('should return an error when resolving is not successful', async () => {
|
|
95
|
-
const content = "nls.localize(a, 'value')";
|
|
96
|
-
const errors: string[] = [];
|
|
97
|
-
assert.deepStrictEqual(await extractFromFile(TEST_FILE, content, errors, quiet), {});
|
|
98
|
-
assert.deepStrictEqual(errors, [
|
|
99
|
-
"test.ts(1,14): Could not resolve reference to 'a'"
|
|
100
|
-
]);
|
|
101
|
-
});
|
|
102
|
-
|
|
103
|
-
it('should return an error when resolving from an expression', async () => {
|
|
104
|
-
const content = "nls.localize(test.value, 'value');";
|
|
105
|
-
const errors: string[] = [];
|
|
106
|
-
assert.deepStrictEqual(await extractFromFile(TEST_FILE, content, errors, quiet), {});
|
|
107
|
-
assert.deepStrictEqual(errors, [
|
|
108
|
-
"test.ts(1,14): 'test.value' is not a string constant"
|
|
109
|
-
]);
|
|
110
|
-
});
|
|
111
|
-
|
|
112
|
-
it('should show error when trying to merge an object and a string', async () => {
|
|
113
|
-
const content = `
|
|
114
|
-
nls.localize('key', 'value');
|
|
115
|
-
nls.localize('key/nested', 'value');
|
|
116
|
-
`.trim();
|
|
117
|
-
const errors: string[] = [];
|
|
118
|
-
assert.deepStrictEqual(await extractFromFile(TEST_FILE, content, errors, quiet), {
|
|
119
|
-
'key': 'value'
|
|
120
|
-
});
|
|
121
|
-
assert.deepStrictEqual(errors, [
|
|
122
|
-
"test.ts(2,35): String entry already exists at 'key'"
|
|
123
|
-
]);
|
|
124
|
-
});
|
|
125
|
-
|
|
126
|
-
it('should show error when trying to merge a string into an object', async () => {
|
|
127
|
-
const content = `
|
|
128
|
-
nls.localize('key/nested', 'value');
|
|
129
|
-
nls.localize('key', 'value');
|
|
130
|
-
`.trim();
|
|
131
|
-
const errors: string[] = [];
|
|
132
|
-
assert.deepStrictEqual(await extractFromFile(TEST_FILE, content, errors, quiet), {
|
|
133
|
-
'key': {
|
|
134
|
-
'nested': 'value'
|
|
135
|
-
}
|
|
136
|
-
});
|
|
137
|
-
assert.deepStrictEqual(errors, [
|
|
138
|
-
"test.ts(2,28): Multiple translation keys already exist at 'key'"
|
|
139
|
-
]);
|
|
140
|
-
});
|
|
141
|
-
|
|
142
|
-
it('should show error for template literals', async () => {
|
|
143
|
-
const content = 'nls.localize("key", `template literal value`)';
|
|
144
|
-
const errors: string[] = [];
|
|
145
|
-
assert.deepStrictEqual(await extractFromFile(TEST_FILE, content, errors, quiet), {});
|
|
146
|
-
assert.deepStrictEqual(errors, [
|
|
147
|
-
"test.ts(1,20): Template literals are not supported for localization. Please use the additional arguments of the 'nls.localize' function to format strings"
|
|
148
|
-
]);
|
|
149
|
-
});
|
|
150
|
-
|
|
151
|
-
});
|
|
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-only WITH Classpath-exception-2.0
|
|
15
|
+
// *****************************************************************************
|
|
16
|
+
|
|
17
|
+
import * as assert from 'assert';
|
|
18
|
+
import { extractFromFile, ExtractionOptions } from './localization-extractor';
|
|
19
|
+
|
|
20
|
+
const TEST_FILE = 'test.ts';
|
|
21
|
+
const quiet: ExtractionOptions = { quiet: true };
|
|
22
|
+
|
|
23
|
+
describe('correctly extracts from file content', () => {
|
|
24
|
+
|
|
25
|
+
it('should extract from simple nls.localize() call', async () => {
|
|
26
|
+
const content = 'nls.localize("key", "value")';
|
|
27
|
+
assert.deepStrictEqual(await extractFromFile(TEST_FILE, content), {
|
|
28
|
+
'key': 'value'
|
|
29
|
+
});
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
it('should extract from nested nls.localize() call', async () => {
|
|
33
|
+
const content = 'nls.localize("nested/key", "value")';
|
|
34
|
+
assert.deepStrictEqual(await extractFromFile(TEST_FILE, content), {
|
|
35
|
+
'nested': {
|
|
36
|
+
'key': 'value'
|
|
37
|
+
}
|
|
38
|
+
});
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
it('should extract IDs from Command.toLocalizedCommand() call', async () => {
|
|
42
|
+
const content = `
|
|
43
|
+
Command.toLocalizedCommand({
|
|
44
|
+
id: 'command-id1',
|
|
45
|
+
label: 'command-label1'
|
|
46
|
+
});
|
|
47
|
+
Command.toLocalizedCommand({
|
|
48
|
+
id: 'command-id2',
|
|
49
|
+
label: 'command-label2'
|
|
50
|
+
}, 'command-key');
|
|
51
|
+
`;
|
|
52
|
+
assert.deepStrictEqual(await extractFromFile(TEST_FILE, content), {
|
|
53
|
+
'command-id1': 'command-label1',
|
|
54
|
+
'command-key': 'command-label2'
|
|
55
|
+
});
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
it('should extract category from Command.toLocalizedCommand() call', async () => {
|
|
59
|
+
const content = `
|
|
60
|
+
Command.toLocalizedCommand({
|
|
61
|
+
id: 'id',
|
|
62
|
+
label: 'label',
|
|
63
|
+
category: 'category'
|
|
64
|
+
}, undefined, 'category-key');`;
|
|
65
|
+
assert.deepStrictEqual(await extractFromFile(TEST_FILE, content), {
|
|
66
|
+
'id': 'label',
|
|
67
|
+
'category-key': 'category'
|
|
68
|
+
});
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
it('should merge different nls.localize() calls', async () => {
|
|
72
|
+
const content = `
|
|
73
|
+
nls.localize('nested/key1', 'value1');
|
|
74
|
+
nls.localize('nested/key2', 'value2');
|
|
75
|
+
`;
|
|
76
|
+
assert.deepStrictEqual(await extractFromFile(TEST_FILE, content), {
|
|
77
|
+
'nested': {
|
|
78
|
+
'key1': 'value1',
|
|
79
|
+
'key2': 'value2'
|
|
80
|
+
}
|
|
81
|
+
});
|
|
82
|
+
});
|
|
83
|
+
|
|
84
|
+
it('should be able to resolve local references', async () => {
|
|
85
|
+
const content = `
|
|
86
|
+
const a = 'key';
|
|
87
|
+
nls.localize(a, 'value');
|
|
88
|
+
`;
|
|
89
|
+
assert.deepStrictEqual(await extractFromFile(TEST_FILE, content), {
|
|
90
|
+
'key': 'value'
|
|
91
|
+
});
|
|
92
|
+
});
|
|
93
|
+
|
|
94
|
+
it('should return an error when resolving is not successful', async () => {
|
|
95
|
+
const content = "nls.localize(a, 'value')";
|
|
96
|
+
const errors: string[] = [];
|
|
97
|
+
assert.deepStrictEqual(await extractFromFile(TEST_FILE, content, errors, quiet), {});
|
|
98
|
+
assert.deepStrictEqual(errors, [
|
|
99
|
+
"test.ts(1,14): Could not resolve reference to 'a'"
|
|
100
|
+
]);
|
|
101
|
+
});
|
|
102
|
+
|
|
103
|
+
it('should return an error when resolving from an expression', async () => {
|
|
104
|
+
const content = "nls.localize(test.value, 'value');";
|
|
105
|
+
const errors: string[] = [];
|
|
106
|
+
assert.deepStrictEqual(await extractFromFile(TEST_FILE, content, errors, quiet), {});
|
|
107
|
+
assert.deepStrictEqual(errors, [
|
|
108
|
+
"test.ts(1,14): 'test.value' is not a string constant"
|
|
109
|
+
]);
|
|
110
|
+
});
|
|
111
|
+
|
|
112
|
+
it('should show error when trying to merge an object and a string', async () => {
|
|
113
|
+
const content = `
|
|
114
|
+
nls.localize('key', 'value');
|
|
115
|
+
nls.localize('key/nested', 'value');
|
|
116
|
+
`.trim();
|
|
117
|
+
const errors: string[] = [];
|
|
118
|
+
assert.deepStrictEqual(await extractFromFile(TEST_FILE, content, errors, quiet), {
|
|
119
|
+
'key': 'value'
|
|
120
|
+
});
|
|
121
|
+
assert.deepStrictEqual(errors, [
|
|
122
|
+
"test.ts(2,35): String entry already exists at 'key'"
|
|
123
|
+
]);
|
|
124
|
+
});
|
|
125
|
+
|
|
126
|
+
it('should show error when trying to merge a string into an object', async () => {
|
|
127
|
+
const content = `
|
|
128
|
+
nls.localize('key/nested', 'value');
|
|
129
|
+
nls.localize('key', 'value');
|
|
130
|
+
`.trim();
|
|
131
|
+
const errors: string[] = [];
|
|
132
|
+
assert.deepStrictEqual(await extractFromFile(TEST_FILE, content, errors, quiet), {
|
|
133
|
+
'key': {
|
|
134
|
+
'nested': 'value'
|
|
135
|
+
}
|
|
136
|
+
});
|
|
137
|
+
assert.deepStrictEqual(errors, [
|
|
138
|
+
"test.ts(2,28): Multiple translation keys already exist at 'key'"
|
|
139
|
+
]);
|
|
140
|
+
});
|
|
141
|
+
|
|
142
|
+
it('should show error for template literals', async () => {
|
|
143
|
+
const content = 'nls.localize("key", `template literal value`)';
|
|
144
|
+
const errors: string[] = [];
|
|
145
|
+
assert.deepStrictEqual(await extractFromFile(TEST_FILE, content, errors, quiet), {});
|
|
146
|
+
assert.deepStrictEqual(errors, [
|
|
147
|
+
"test.ts(1,20): Template literals are not supported for localization. Please use the additional arguments of the 'nls.localize' function to format strings"
|
|
148
|
+
]);
|
|
149
|
+
});
|
|
150
|
+
|
|
151
|
+
});
|