@lingual/i18n-check 0.8.4 → 0.8.6

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.
@@ -1 +0,0 @@
1
- export {};
@@ -1,165 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const errorReporters_1 = require("./errorReporters");
4
- describe('formatTable', () => {
5
- test('single col and row', () => {
6
- expect((0, errorReporters_1.formatTable)([[['lorem ipsum']]])).toEqual(`
7
- ┌─────────────┐
8
- │ lorem ipsum │
9
- └─────────────┘
10
- `.trim());
11
- });
12
- test('single col and two rows', () => {
13
- expect((0, errorReporters_1.formatTable)([[['lorem ipsum'], ['foo bar']]])).toEqual(`
14
- ┌─────────────┐
15
- │ lorem ipsum │
16
- │ foo bar │
17
- └─────────────┘
18
- `.trim());
19
- });
20
- test('with two columns and two row groups', () => {
21
- expect((0, errorReporters_1.formatTable)([
22
- [['col1', 'col2']],
23
- [
24
- ['lorem ipsum dolor', 'foobar'],
25
- ['baz', 'more text'],
26
- ],
27
- ])).toEqual(`
28
- ┌───────────────────┬───────────┐
29
- │ col1 │ col2 │
30
- ├───────────────────┼───────────┤
31
- │ lorem ipsum dolor │ foobar │
32
- │ baz │ more text │
33
- └───────────────────┴───────────┘
34
- `.trim());
35
- });
36
- test('with two columns and three row groups', () => {
37
- expect((0, errorReporters_1.formatTable)([
38
- [['one', 'two']],
39
- [
40
- ['lorem ipsum dolor', 'foobar'],
41
- ['baz', 'more text'],
42
- ],
43
- [['hello world', 'here is more text for testing']],
44
- ])).toEqual(`
45
- ┌───────────────────┬───────────────────────────────┐
46
- │ one │ two │
47
- ├───────────────────┼───────────────────────────────┤
48
- │ lorem ipsum dolor │ foobar │
49
- │ baz │ more text │
50
- ├───────────────────┼───────────────────────────────┤
51
- │ hello world │ here is more text for testing │
52
- └───────────────────┴───────────────────────────────┘
53
- `.trim());
54
- });
55
- });
56
- describe('formatCheckResultTable', () => {
57
- test('with one file and two keys', () => {
58
- expect((0, errorReporters_1.formatCheckResultTable)({
59
- 'some/file.json': ['key.one', 'key.two'],
60
- })).toEqual(`
61
- ┌────────────────┬─────────┐
62
- │ file │ key │
63
- ├────────────────┼─────────┤
64
- │ some/file.json │ key.one │
65
- │ some/file.json │ key.two │
66
- └────────────────┴─────────┘
67
- `.trim());
68
- });
69
- test('with two files and three keys', () => {
70
- expect((0, errorReporters_1.formatCheckResultTable)({
71
- 'some/de.json': ['key.one', 'key.two'],
72
- 'some/en.json': ['key.three'],
73
- })).toEqual(`
74
- ┌──────────────┬───────────┐
75
- │ file │ key │
76
- ├──────────────┼───────────┤
77
- │ some/de.json │ key.one │
78
- │ some/de.json │ key.two │
79
- │ some/en.json │ key.three │
80
- └──────────────┴───────────┘
81
- `.trim());
82
- });
83
- });
84
- describe('formatInvalidTranslationsResultTable', () => {
85
- test('with one file and one key', () => {
86
- expect((0, errorReporters_1.formatInvalidTranslationsResultTable)({
87
- 'some/en.json': [{ key: 'key.one', msg: 'key one error msg' }],
88
- })).toEqual(`
89
- ┌──────┬───────────────────┐
90
- │ info │ result │
91
- ├──────┼───────────────────┤
92
- │ file │ some/en.json │
93
- │ key │ key.one │
94
- │ msg │ key one error msg │
95
- └──────┴───────────────────┘
96
- `.trim());
97
- });
98
- test('with two files and three keys', () => {
99
- expect((0, errorReporters_1.formatInvalidTranslationsResultTable)({
100
- 'some/en-US.json': [
101
- { key: 'key.one', msg: 'key one error msg' },
102
- { key: 'key.two', msg: 'another msg' },
103
- ],
104
- 'some/de.json': [{ key: 'key.three', msg: 'key three msg' }],
105
- })).toEqual(`
106
- ┌──────┬───────────────────┐
107
- │ info │ result │
108
- ├──────┼───────────────────┤
109
- │ file │ some/en-US.json │
110
- │ key │ key.one │
111
- │ msg │ key one error msg │
112
- ├──────┼───────────────────┤
113
- │ file │ some/en-US.json │
114
- │ key │ key.two │
115
- │ msg │ another msg │
116
- ├──────┼───────────────────┤
117
- │ file │ some/de.json │
118
- │ key │ key.three │
119
- │ msg │ key three msg │
120
- └──────┴───────────────────┘
121
- `.trim());
122
- });
123
- });
124
- describe('formatSummaryTable', () => {
125
- test('with CheckResult with single file and key', () => {
126
- expect((0, errorReporters_1.formatSummaryTable)({
127
- 'some/file.json': ['key.one'],
128
- })).toEqual(`
129
- ┌────────────────┬───────┐
130
- │ file │ total │
131
- ├────────────────┼───────┤
132
- │ some/file.json │ 1 │
133
- └────────────────┴───────┘
134
- `.trim());
135
- });
136
- test('with CheckResult with two files and three keys', () => {
137
- expect((0, errorReporters_1.formatSummaryTable)({
138
- 'some/de.json': ['key.one', 'key.two'],
139
- 'some/en.json': ['key.three'],
140
- })).toEqual(`
141
- ┌──────────────┬───────┐
142
- │ file │ total │
143
- ├──────────────┼───────┤
144
- │ some/de.json │ 2 │
145
- │ some/en.json │ 1 │
146
- └──────────────┴───────┘
147
- `.trim());
148
- });
149
- test('with InvalidTranslationsResult with two files and three keys', () => {
150
- expect((0, errorReporters_1.formatSummaryTable)({
151
- 'some/en-US.json': [
152
- { key: 'key.one', msg: 'key one error msg' },
153
- { key: 'key.two', msg: 'another msg' },
154
- ],
155
- 'some/de.json': [{ key: 'key.three', msg: 'key three msg' }],
156
- })).toEqual(`
157
- ┌─────────────────┬───────┐
158
- │ file │ total │
159
- ├─────────────────┼───────┤
160
- │ some/en-US.json │ 2 │
161
- │ some/de.json │ 1 │
162
- └─────────────────┴───────┘
163
- `.trim());
164
- });
165
- });
@@ -1 +0,0 @@
1
- export {};
@@ -1,83 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const findInvalidTranslations_1 = require("./findInvalidTranslations");
4
- const flattenTranslations_1 = require("./flattenTranslations");
5
- const sourceFile = require('../../translations/messageExamples/en-us.json');
6
- const secondaryFile = require('../../translations/messageExamples/de-de.json');
7
- describe('findInvalidTranslations:compareTranslationFiles', () => {
8
- it('should return empty array if files are identical', () => {
9
- expect((0, findInvalidTranslations_1.compareTranslationFiles)((0, flattenTranslations_1.flattenTranslations)(sourceFile), (0, flattenTranslations_1.flattenTranslations)(sourceFile))).toEqual([]);
10
- });
11
- it('should return the invalid keys in the target file', () => {
12
- expect((0, findInvalidTranslations_1.compareTranslationFiles)((0, flattenTranslations_1.flattenTranslations)({
13
- ...sourceFile,
14
- 'ten.eleven.twelve': 'ten eleven twelve',
15
- }), (0, flattenTranslations_1.flattenTranslations)(secondaryFile))).toEqual([{ key: 'multipleVariables', msg: 'Unexpected date element' }]);
16
- });
17
- it('should return empty array if placeholders are identical but in different positions', () => {
18
- expect((0, findInvalidTranslations_1.compareTranslationFiles)({
19
- basic: 'added {this} and {that} should work.',
20
- }, {
21
- basic: 'It is {this} with different position {that}',
22
- })).toEqual([]);
23
- });
24
- });
25
- describe('findInvalidTranslations', () => {
26
- it('should return an empty object if all files have no invalid keys', () => {
27
- expect((0, findInvalidTranslations_1.findInvalidTranslations)(sourceFile, { de: sourceFile })).toEqual({});
28
- });
29
- it('should return an object containing the keys for the missing language', () => {
30
- expect((0, findInvalidTranslations_1.findInvalidTranslations)({ ...sourceFile, 'ten.eleven.twelve': 'ten eleven twelve' }, { de: secondaryFile })).toEqual({
31
- de: [{ key: 'multipleVariables', msg: 'Unexpected date element' }],
32
- });
33
- });
34
- it('should return an object containing the keys for every language with missing key', () => {
35
- expect((0, findInvalidTranslations_1.findInvalidTranslations)({ ...sourceFile, 'ten.eleven.twelve': 'ten eleven twelve' }, {
36
- de: secondaryFile,
37
- fr: {
38
- 'four.five.six': 'four five six',
39
- 'seven.eight.nine': 'seven eight nine',
40
- 'message.text-format': 'yo,<p><b>John</b></p>!',
41
- },
42
- })).toEqual({
43
- de: [{ key: 'multipleVariables', msg: 'Unexpected date element' }],
44
- fr: [
45
- {
46
- key: 'message.text-format',
47
- msg: 'Expected tag to contain "b" but received "p"',
48
- },
49
- ],
50
- });
51
- });
52
- it('should allow for different types of keys per locale', () => {
53
- expect((0, findInvalidTranslations_1.findInvalidTranslations)(sourceFile, {
54
- de: {
55
- ...secondaryFile,
56
- 'message.plural': '{count, plural, other {# of {total} items}}',
57
- },
58
- })).toEqual({
59
- de: [
60
- {
61
- key: 'multipleVariables',
62
- msg: 'Unexpected date element',
63
- },
64
- ],
65
- });
66
- });
67
- it('should fail if a variable is changed in one of the translations', () => {
68
- expect((0, findInvalidTranslations_1.findInvalidTranslations)(sourceFile, {
69
- de: {
70
- ...secondaryFile,
71
- 'message.plural': '{count, plural, other {# of {cargado} items}}',
72
- },
73
- })).toEqual({
74
- de: [
75
- {
76
- key: 'message.plural',
77
- msg: 'Error in plural: Expected argument to contain "total" but received "cargado"',
78
- },
79
- { key: 'multipleVariables', msg: 'Unexpected date element' },
80
- ],
81
- });
82
- });
83
- });
@@ -1 +0,0 @@
1
- export {};
@@ -1,206 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const findInvalidi18nTranslations_1 = require("./findInvalidi18nTranslations");
4
- const flattenTranslations_1 = require("./flattenTranslations");
5
- const sourceFile = require('../../translations/i18NextMessageExamples/en-us.json');
6
- const targetFile = require('../../translations/i18NextMessageExamples/de-de.json');
7
- describe('findInvalid18nTranslations:compareTranslationFiles', () => {
8
- it('should return empty array if files are identical', () => {
9
- expect((0, findInvalidi18nTranslations_1.compareTranslationFiles)((0, flattenTranslations_1.flattenTranslations)(sourceFile), (0, flattenTranslations_1.flattenTranslations)(sourceFile))).toEqual([]);
10
- });
11
- it('should return the invalid keys in the target file', () => {
12
- expect((0, findInvalidi18nTranslations_1.compareTranslationFiles)((0, flattenTranslations_1.flattenTranslations)({
13
- ...sourceFile,
14
- 'ten.eleven.twelve': 'ten eleven twelve',
15
- }), (0, flattenTranslations_1.flattenTranslations)(targetFile))).toEqual([
16
- {
17
- key: 'key_with_broken_de',
18
- msg: 'Error in interpolation: Expected value but received val',
19
- },
20
- {
21
- key: 'intlNumber_broken_de',
22
- msg: 'Missing element interpolation',
23
- },
24
- ]);
25
- });
26
- it('should return an empty array if the strings contain paranthesis that have different content', () => {
27
- expect((0, findInvalidi18nTranslations_1.compareTranslationFiles)((0, flattenTranslations_1.flattenTranslations)({
28
- keyText: 'Key(s)',
29
- }), (0, flattenTranslations_1.flattenTranslations)({ keyText: 'Taste(n)' }))).toEqual([]);
30
- });
31
- it('should return empty array if placeholders are identical but in different positions', () => {
32
- expect((0, findInvalidi18nTranslations_1.compareTranslationFiles)({
33
- basic: 'added {{this}} and {{that}} should work.',
34
- }, {
35
- basic: 'It is {{this}} with different position {{that}}',
36
- })).toEqual([]);
37
- });
38
- it('should return the invalid key if tags are not identical', () => {
39
- expect((0, findInvalidi18nTranslations_1.compareTranslationFiles)({
40
- tag: 'This is some <b>bold text</b> and some <i>italic</i> text.',
41
- }, {
42
- tag: 'There is some <b>bold text</b> and some other <span>italic</span> text.',
43
- })).toEqual([
44
- {
45
- key: 'tag',
46
- msg: 'Expected tag "</i>" but received "</span>", Expected tag "<i>" but received "<span>"',
47
- },
48
- ]);
49
- });
50
- it('should return empty array if tags are identical', () => {
51
- expect((0, findInvalidi18nTranslations_1.compareTranslationFiles)({
52
- tag: 'This is some <b>bold text</b> and some <i>italic</i> text.',
53
- }, {
54
- tag: 'There is some <b>bold text</b> and some other <i>italic</i> text.',
55
- })).toEqual([]);
56
- });
57
- });
58
- describe('findInvalidTranslations', () => {
59
- it('should return an empty object if all files have no invalid keys', () => {
60
- expect((0, findInvalidi18nTranslations_1.findInvalid18nTranslations)(sourceFile, { de: sourceFile })).toEqual({});
61
- });
62
- it('should return an object containing the keys for the missing language', () => {
63
- expect((0, findInvalidi18nTranslations_1.findInvalid18nTranslations)({ ...sourceFile, 'ten.eleven.twelve': 'ten eleven twelve' }, { de: targetFile })).toEqual({
64
- de: [
65
- {
66
- key: 'key_with_broken_de',
67
- msg: 'Error in interpolation: Expected value but received val',
68
- },
69
- {
70
- key: 'intlNumber_broken_de',
71
- msg: 'Missing element interpolation',
72
- },
73
- ],
74
- });
75
- });
76
- it('should return an object containing the keys for every language with missing key', () => {
77
- expect((0, findInvalidi18nTranslations_1.findInvalid18nTranslations)({ ...sourceFile, 'ten.eleven.twelve': 'ten eleven twelve' }, {
78
- de: targetFile,
79
- fr: {
80
- key_with_broken_de: 'Some format {{value, formatname}} and some other format {{value, formatname}}',
81
- },
82
- })).toEqual({
83
- de: [
84
- {
85
- key: 'key_with_broken_de',
86
- msg: 'Error in interpolation: Expected value but received val',
87
- },
88
- {
89
- key: 'intlNumber_broken_de',
90
- msg: 'Missing element interpolation',
91
- },
92
- ],
93
- fr: [
94
- {
95
- key: 'key_with_broken_de',
96
- msg: 'Unexpected interpolation element',
97
- },
98
- ],
99
- });
100
- });
101
- it('should find invalid interval', () => {
102
- expect((0, findInvalidi18nTranslations_1.findInvalid18nTranslations)({
103
- key1_interval: '(1)[one item];(2-7)[a few items];(7-inf)[a lot of items];',
104
- }, {
105
- de: {
106
- key1_interval: '(1-2)[one or two items];(3-7)[a few items];(7-inf)[a lot of items];',
107
- },
108
- })).toEqual({
109
- de: [
110
- {
111
- key: 'key1_interval',
112
- msg: 'Error in plural: Expected 1 but received 1-2, Error in plural: Expected 2-7 but received 3-7',
113
- },
114
- ],
115
- });
116
- });
117
- it('should find invalid nested interpolation', () => {
118
- expect((0, findInvalidi18nTranslations_1.findInvalid18nTranslations)({
119
- 'tree.one': 'added {{something}}',
120
- }, {
121
- de: {
122
- 'tree.one': 'added {{somethings}}',
123
- },
124
- })).toEqual({
125
- de: [
126
- {
127
- key: 'tree.one',
128
- msg: 'Error in interpolation: Expected something but received somethings',
129
- },
130
- ],
131
- });
132
- });
133
- it('should find invalid relative time formatting', () => {
134
- expect((0, findInvalidi18nTranslations_1.findInvalid18nTranslations)({
135
- intlRelativeTimeWithOptionsExplicit: 'Lorem {{val, relativetime(range: quarter; style: narrow;)}}',
136
- }, {
137
- de: {
138
- intlRelativeTimeWithOptionsExplicit: 'Lorem {{val, relativetime(range: quarter; style: long;)}}',
139
- },
140
- })).toEqual({
141
- de: [
142
- {
143
- key: 'intlRelativeTimeWithOptionsExplicit',
144
- msg: 'Error in interpolation: Expected relativetime(range: quarter; style: narrow;) but received relativetime(range: quarter; style: long;)',
145
- },
146
- ],
147
- });
148
- });
149
- it('should find invalid key with options', () => {
150
- expect((0, findInvalidi18nTranslations_1.findInvalid18nTranslations)({
151
- keyWithOptions: 'Some format {{value, formatname(option1Name: option1Value; option2Name: option2Value)}}',
152
- }, {
153
- de: {
154
- keyWithOptions: 'Some format {{value, formatname(option3Name: option3Value; option4Name: option4Value)}}',
155
- },
156
- })).toEqual({
157
- de: [
158
- {
159
- key: 'keyWithOptions',
160
- msg: 'Error in interpolation: Expected formatname(option1Name: option1Value; option2Name: option2Value) but received formatname(option3Name: option3Value; option4Name: option4Value)',
161
- },
162
- ],
163
- });
164
- });
165
- it('should find invalid nesting', () => {
166
- expect((0, findInvalidi18nTranslations_1.findInvalid18nTranslations)({
167
- nesting1: '1 $t(nesting2)',
168
- }, {
169
- de: {
170
- nesting1: '1 $t(nesting3)',
171
- },
172
- })).toEqual({
173
- de: [
174
- {
175
- key: 'nesting1',
176
- msg: 'Error in nesting: Expected nesting2 but received nesting3',
177
- },
178
- ],
179
- });
180
- });
181
- it('should find invalid tags', () => {
182
- expect((0, findInvalidi18nTranslations_1.findInvalid18nTranslations)({
183
- tag: 'This is some <b>bold text</b> and some <i>italic</i> text.',
184
- }, {
185
- de: {
186
- tag: 'There is some <b>bold text</b> and some other <span>text inside a span</span>!',
187
- },
188
- })).toEqual({
189
- de: [
190
- {
191
- key: 'tag',
192
- msg: 'Expected tag "</i>" but received "</span>", Expected tag "<i>" but received "<span>"',
193
- },
194
- ],
195
- });
196
- });
197
- it('should recognize special characters', () => {
198
- expect((0, findInvalidi18nTranslations_1.findInvalid18nTranslations)({
199
- key: 'Test < {{a}} and > {{max_a}}',
200
- }, {
201
- de: {
202
- key: 'Test < {{a}} und > {{max_a}}',
203
- },
204
- })).toEqual({});
205
- });
206
- });
@@ -1 +0,0 @@
1
- export {};
@@ -1,41 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const findMissingKeys_1 = require("./findMissingKeys");
4
- const sourceFile = {
5
- 'one.two.three': 'one two three',
6
- 'four.five.six': 'four five six',
7
- 'seven.eight.nine': 'seven eight nine',
8
- };
9
- const secondaryFile = {
10
- 'one.two.three': 'one two three',
11
- 'four.five.six': 'four five six',
12
- 'seven.eight.nine': 'seven eight nine',
13
- };
14
- describe('findMissingKeys:compareTranslationFiles', () => {
15
- it('should return empty array if files are identical', () => {
16
- expect((0, findMissingKeys_1.compareTranslationFiles)(sourceFile, secondaryFile)).toEqual([]);
17
- });
18
- it('should return the missing keys in the secondary file', () => {
19
- expect((0, findMissingKeys_1.compareTranslationFiles)({ ...sourceFile, 'ten.eleven.twelve': 'ten eleven twelve' }, secondaryFile)).toEqual(['ten.eleven.twelve']);
20
- });
21
- });
22
- describe('findMissingKeys', () => {
23
- it('should return an empty object if all files have no missing keys', () => {
24
- expect((0, findMissingKeys_1.findMissingKeys)(sourceFile, { de: secondaryFile })).toEqual({});
25
- });
26
- it('should return an object containing the keys for the missing language', () => {
27
- expect((0, findMissingKeys_1.findMissingKeys)({ ...sourceFile, 'ten.eleven.twelve': 'ten eleven twelve' }, { de: secondaryFile })).toEqual({ de: ['ten.eleven.twelve'] });
28
- });
29
- it('should return an object containing the keys for every language with missing key', () => {
30
- expect((0, findMissingKeys_1.findMissingKeys)({ ...sourceFile, 'ten.eleven.twelve': 'ten eleven twelve' }, {
31
- de: secondaryFile,
32
- fr: {
33
- 'four.five.six': 'four five six',
34
- 'seven.eight.nine': 'seven eight nine',
35
- },
36
- })).toEqual({
37
- de: ['ten.eleven.twelve'],
38
- fr: ['one.two.three', 'ten.eleven.twelve'],
39
- });
40
- });
41
- });
@@ -1 +0,0 @@
1
- export {};
@@ -1,28 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const flattenTranslations_1 = require("./flattenTranslations");
4
- const flatStructure = require('../../translations/en-us.json');
5
- const nestedStructure = require('../../translations/flattenExamples/en-us.json');
6
- const expectedFlatStructure = {
7
- 'test.drive.one': 'testing one',
8
- 'test.drive.two': 'testing two',
9
- 'other.nested.three': 'testing three',
10
- 'other.nested.deep.more.final': 'nested translation',
11
- };
12
- describe('flattenTranslations', () => {
13
- it('should do nothing if the file structure is flat', () => {
14
- expect((0, flattenTranslations_1.flattenTranslations)(flatStructure)).toEqual(flatStructure);
15
- });
16
- describe('flattenEntry', () => {
17
- it('should flatten a nested object', () => {
18
- expect((0, flattenTranslations_1.flattenEntry)({
19
- a: {
20
- b: { c: 'one' },
21
- },
22
- })).toEqual({ 'a.b.c': 'one' });
23
- });
24
- });
25
- it('should do nothing if the file structure is flat', () => {
26
- expect((0, flattenTranslations_1.flattenTranslations)(nestedStructure)).toEqual(expectedFlatStructure);
27
- });
28
- });
@@ -1 +0,0 @@
1
- export {};