@lingual/i18n-check 0.8.10 → 0.8.11
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/dist/index.d.ts +2 -8
- package/dist/index.js +3 -3
- package/dist/types.d.ts +6 -0
- package/dist/utils/findMissingKeys.d.ts +4 -3
- package/dist/utils/findMissingKeys.js +44 -6
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -1,12 +1,6 @@
|
|
|
1
|
-
import { CheckResult, InvalidTranslationsResult, Translation, TranslationFile } from './types';
|
|
2
|
-
import { Context } from './errorReporters';
|
|
3
|
-
export type Options = {
|
|
4
|
-
format?: 'icu' | 'i18next' | 'react-intl' | 'next-intl';
|
|
5
|
-
checks?: Context[];
|
|
6
|
-
ignore?: string[];
|
|
7
|
-
};
|
|
1
|
+
import { CheckResult, InvalidTranslationsResult, Options, Translation, TranslationFile } from './types';
|
|
8
2
|
export declare const checkInvalidTranslations: (source: Translation, targets: Record<string, Translation>, options?: Options) => InvalidTranslationsResult;
|
|
9
|
-
export declare const checkMissingTranslations: (source: Translation, targets: Record<string, Translation
|
|
3
|
+
export declare const checkMissingTranslations: (source: Translation, targets: Record<string, Translation>, options: Options) => CheckResult;
|
|
10
4
|
export declare const checkTranslations: (source: TranslationFile[], targets: TranslationFile[], options?: Options) => {
|
|
11
5
|
missingKeys: CheckResult | undefined;
|
|
12
6
|
invalidKeys: InvalidTranslationsResult | undefined;
|
package/dist/index.js
CHANGED
|
@@ -18,8 +18,8 @@ const checkInvalidTranslations = (source, targets, options = { format: 'icu' })
|
|
|
18
18
|
: (0, findInvalidTranslations_1.findInvalidTranslations)(source, targets);
|
|
19
19
|
};
|
|
20
20
|
exports.checkInvalidTranslations = checkInvalidTranslations;
|
|
21
|
-
const checkMissingTranslations = (source, targets) => {
|
|
22
|
-
return (0, findMissingKeys_1.findMissingKeys)(source, targets);
|
|
21
|
+
const checkMissingTranslations = (source, targets, options) => {
|
|
22
|
+
return (0, findMissingKeys_1.findMissingKeys)(source, targets, options);
|
|
23
23
|
};
|
|
24
24
|
exports.checkMissingTranslations = checkMissingTranslations;
|
|
25
25
|
const checkTranslations = (source, targets, options = { format: 'icu', checks: ['invalidKeys', 'missingKeys'] }) => {
|
|
@@ -34,7 +34,7 @@ const checkTranslations = (source, targets, options = { format: 'icu', checks: [
|
|
|
34
34
|
.map(({ name, content }) => [name, content]));
|
|
35
35
|
const filteredContent = filterKeys(content, options.ignore ?? []);
|
|
36
36
|
if (hasMissingKeysCheck) {
|
|
37
|
-
merge(missingKeys, (0, exports.checkMissingTranslations)(filteredContent, files));
|
|
37
|
+
merge(missingKeys, (0, exports.checkMissingTranslations)(filteredContent, files, options));
|
|
38
38
|
}
|
|
39
39
|
if (hasInvalidKeysCheck) {
|
|
40
40
|
merge(invalidKeys, (0, exports.checkInvalidTranslations)(filteredContent, files, options));
|
package/dist/types.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { Context } from './errorReporters';
|
|
1
2
|
export type Translation = Record<string, unknown>;
|
|
2
3
|
export type CheckResult = Record<string, string[]>;
|
|
3
4
|
export type InvalidTranslationEntry = {
|
|
@@ -15,3 +16,8 @@ export type FileInfo = {
|
|
|
15
16
|
name: string;
|
|
16
17
|
path: string[];
|
|
17
18
|
};
|
|
19
|
+
export type Options = {
|
|
20
|
+
format?: 'icu' | 'i18next' | 'react-intl' | 'next-intl';
|
|
21
|
+
checks?: Context[];
|
|
22
|
+
ignore?: string[];
|
|
23
|
+
};
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
-
import { Translation } from '../types';
|
|
2
|
-
export declare const findMissingKeys: (source: Translation, targets: Record<string, Translation
|
|
3
|
-
export declare const compareTranslationFiles: (
|
|
1
|
+
import { Options, Translation } from '../types';
|
|
2
|
+
export declare const findMissingKeys: (source: Translation, targets: Record<string, Translation>, options?: Options) => Record<string, string[]>;
|
|
3
|
+
export declare const compareTranslationFiles: (src: Translation, target: Translation) => string[];
|
|
4
|
+
export declare const compareI18nextTranslationFiles: (src: Translation, target: Translation) => string[];
|
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.compareTranslationFiles = exports.findMissingKeys = void 0;
|
|
4
|
-
const findMissingKeys = (source, targets) => {
|
|
3
|
+
exports.compareI18nextTranslationFiles = exports.compareTranslationFiles = exports.findMissingKeys = void 0;
|
|
4
|
+
const findMissingKeys = (source, targets, options = {}) => {
|
|
5
5
|
const differences = {};
|
|
6
6
|
for (const [lang, file] of Object.entries(targets)) {
|
|
7
|
-
const result =
|
|
7
|
+
const result = options.format === 'i18next'
|
|
8
|
+
? (0, exports.compareI18nextTranslationFiles)(source, file)
|
|
9
|
+
: (0, exports.compareTranslationFiles)(source, file);
|
|
8
10
|
if (result.length > 0) {
|
|
9
11
|
differences[lang] = result;
|
|
10
12
|
}
|
|
@@ -12,10 +14,10 @@ const findMissingKeys = (source, targets) => {
|
|
|
12
14
|
return differences;
|
|
13
15
|
};
|
|
14
16
|
exports.findMissingKeys = findMissingKeys;
|
|
15
|
-
const compareTranslationFiles = (
|
|
17
|
+
const compareTranslationFiles = (src, target) => {
|
|
16
18
|
const diffs = [];
|
|
17
|
-
for (const key in
|
|
18
|
-
const counterKey =
|
|
19
|
+
for (const key in src) {
|
|
20
|
+
const counterKey = target[key];
|
|
19
21
|
if (!counterKey) {
|
|
20
22
|
diffs.push(key);
|
|
21
23
|
}
|
|
@@ -23,3 +25,39 @@ const compareTranslationFiles = (a, b) => {
|
|
|
23
25
|
return diffs;
|
|
24
26
|
};
|
|
25
27
|
exports.compareTranslationFiles = compareTranslationFiles;
|
|
28
|
+
const I18NEXT_PLURAL_SUFFIX = [
|
|
29
|
+
'_zero',
|
|
30
|
+
'_one',
|
|
31
|
+
'_two',
|
|
32
|
+
'_few',
|
|
33
|
+
'_many',
|
|
34
|
+
'_other',
|
|
35
|
+
'_interval',
|
|
36
|
+
];
|
|
37
|
+
const compareI18nextTranslationFiles = (src, target) => {
|
|
38
|
+
const diffs = [];
|
|
39
|
+
const flattedSrc = Object.entries(src).reduce((acc, [k, v]) => {
|
|
40
|
+
const pluralSuffix = I18NEXT_PLURAL_SUFFIX.find((suffix) => {
|
|
41
|
+
return k.endsWith(suffix);
|
|
42
|
+
});
|
|
43
|
+
const key = pluralSuffix ? k.replace(pluralSuffix, '') : k;
|
|
44
|
+
acc[key] = v;
|
|
45
|
+
return acc;
|
|
46
|
+
}, {});
|
|
47
|
+
const flattedTarget = Object.entries(target).reduce((acc, [k, v]) => {
|
|
48
|
+
const pluralSuffix = I18NEXT_PLURAL_SUFFIX.find((suffix) => {
|
|
49
|
+
return k.endsWith(suffix);
|
|
50
|
+
});
|
|
51
|
+
const key = pluralSuffix ? k.replace(pluralSuffix, '') : k;
|
|
52
|
+
acc[key] = v;
|
|
53
|
+
return acc;
|
|
54
|
+
}, {});
|
|
55
|
+
for (const key in flattedSrc) {
|
|
56
|
+
const counterKey = flattedTarget[key];
|
|
57
|
+
if (!counterKey) {
|
|
58
|
+
diffs.push(key);
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
return diffs;
|
|
62
|
+
};
|
|
63
|
+
exports.compareI18nextTranslationFiles = compareI18nextTranslationFiles;
|