@vocab/core 1.6.1 → 1.6.3
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 +2 -2
- package/dist/declarations/src/index.d.ts +1 -1
- package/dist/declarations/src/load-translations.d.ts +1 -1
- package/dist/vocab-core.cjs.d.ts +1 -1
- package/dist/vocab-core.cjs.dev.js +29 -22
- package/dist/vocab-core.cjs.prod.js +29 -22
- package/dist/vocab-core.esm.js +28 -21
- package/icu-handler/dist/vocab-core-icu-handler.cjs.d.ts +1 -1
- package/package.json +7 -2
- package/runtime/dist/vocab-core-runtime.cjs.d.ts +1 -1
- package/translation-file/dist/vocab-core-translation-file.cjs.d.ts +1 -1
- package/dist/vocab-core.cjs.d.ts.map +0 -1
- package/icu-handler/dist/vocab-core-icu-handler.cjs.d.ts.map +0 -1
- package/runtime/dist/vocab-core-runtime.cjs.d.ts.map +0 -1
- package/translation-file/dist/vocab-core-translation-file.cjs.d.ts.map +0 -1
package/README.md
CHANGED
|
@@ -39,8 +39,8 @@ This is the language Vocab will assume when it sees a `translation.json` file wi
|
|
|
39
39
|
```js
|
|
40
40
|
// vocab.config.js
|
|
41
41
|
module.exports = {
|
|
42
|
-
languages: [{ name: 'en' }, { name: 'fr' }]
|
|
43
|
-
devLanguage: 'en'
|
|
42
|
+
languages: [{ name: 'en' }, { name: 'fr' }],
|
|
43
|
+
devLanguage: 'en'
|
|
44
44
|
};
|
|
45
45
|
```
|
|
46
46
|
|
|
@@ -3,4 +3,4 @@ export { validate } from "./validate/index.js";
|
|
|
3
3
|
export { resolveConfig, resolveConfigSync, validateConfig } from "./config.js";
|
|
4
4
|
export { getAltLanguages, getAltLanguageFilePath, getDevLanguageFileFromTsFile, } from "./utils.js";
|
|
5
5
|
export { getUniqueKey, loadAllTranslations, loadTranslation, } from "./load-translations.js";
|
|
6
|
-
export * from "./types.js";
|
|
6
|
+
export type * from "./types.js";
|
|
@@ -4,7 +4,7 @@ export declare function getUniqueKey(key: string, namespace: string): string;
|
|
|
4
4
|
export declare function mergeWithDevLanguageTranslation({ translation, devTranslation, }: {
|
|
5
5
|
translation: TranslationsByKey;
|
|
6
6
|
devTranslation: TranslationsByKey;
|
|
7
|
-
}): TranslationsByKey
|
|
7
|
+
}): TranslationsByKey;
|
|
8
8
|
export declare function getLanguageHierarchy({ languages, }: {
|
|
9
9
|
languages: LanguageTarget[];
|
|
10
10
|
}): Map<string, string[]>;
|
package/dist/vocab-core.cjs.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
export * from "./declarations/src/index";
|
|
2
|
-
//# sourceMappingURL=
|
|
2
|
+
//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoidm9jYWItY29yZS5janMuZC50cyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4vZGVjbGFyYXRpb25zL3NyYy9pbmRleC5kLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiJBQUFBIn0=
|
|
@@ -7,7 +7,7 @@ var path = require('path');
|
|
|
7
7
|
var icuMessageformatParser = require('@formatjs/icu-messageformat-parser');
|
|
8
8
|
var prettier = require('prettier');
|
|
9
9
|
var chokidar = require('chokidar');
|
|
10
|
-
var
|
|
10
|
+
var pc = require('picocolors');
|
|
11
11
|
var debug = require('debug');
|
|
12
12
|
var glob = require('fast-glob');
|
|
13
13
|
var IntlMessageFormat = require('intl-messageformat');
|
|
@@ -20,7 +20,7 @@ function _interopDefault (e) { return e && e.__esModule ? e : { 'default': e };
|
|
|
20
20
|
var path__default = /*#__PURE__*/_interopDefault(path);
|
|
21
21
|
var prettier__default = /*#__PURE__*/_interopDefault(prettier);
|
|
22
22
|
var chokidar__default = /*#__PURE__*/_interopDefault(chokidar);
|
|
23
|
-
var
|
|
23
|
+
var pc__default = /*#__PURE__*/_interopDefault(pc);
|
|
24
24
|
var debug__default = /*#__PURE__*/_interopDefault(debug);
|
|
25
25
|
var glob__default = /*#__PURE__*/_interopDefault(glob);
|
|
26
26
|
var IntlMessageFormat__default = /*#__PURE__*/_interopDefault(IntlMessageFormat);
|
|
@@ -244,7 +244,7 @@ function getNamespaceByFilePath(relativePath, {
|
|
|
244
244
|
}
|
|
245
245
|
function printValidationError(...params) {
|
|
246
246
|
// eslint-disable-next-line no-console
|
|
247
|
-
console.error(
|
|
247
|
+
console.error(pc__default["default"].red('Error loading translation:'), ...params);
|
|
248
248
|
}
|
|
249
249
|
function getTranslationsFromFile(translationFileContents, {
|
|
250
250
|
isAltLanguage,
|
|
@@ -324,6 +324,8 @@ function loadAltLanguageFile({
|
|
|
324
324
|
try {
|
|
325
325
|
const altFilePath = getAltLanguageFilePath(filePath, fallbackLanguage);
|
|
326
326
|
delete require.cache[altFilePath];
|
|
327
|
+
|
|
328
|
+
// eslint-disable-next-line @typescript-eslint/no-require-imports
|
|
327
329
|
const translationFile = require(altFilePath);
|
|
328
330
|
const {
|
|
329
331
|
keys: fallbackLanguageTranslation
|
|
@@ -335,7 +337,7 @@ function loadAltLanguageFile({
|
|
|
335
337
|
translation: fallbackLanguageTranslation,
|
|
336
338
|
devTranslation
|
|
337
339
|
}));
|
|
338
|
-
} catch
|
|
340
|
+
} catch {
|
|
339
341
|
trace(`Missing alt language file ${getAltLanguageFilePath(filePath, fallbackLanguage)}
|
|
340
342
|
`);
|
|
341
343
|
}
|
|
@@ -359,6 +361,7 @@ function loadTranslation({
|
|
|
359
361
|
trace(`Loading translation file in "${fallbacks}" fallback mode: "${filePath}"`);
|
|
360
362
|
const languageSet = {};
|
|
361
363
|
delete require.cache[filePath];
|
|
364
|
+
// eslint-disable-next-line @typescript-eslint/no-require-imports
|
|
362
365
|
const translationContent = require(filePath);
|
|
363
366
|
const relativePath = path__default["default"].relative(userConfig.projectRoot || process.cwd(), filePath);
|
|
364
367
|
const {
|
|
@@ -419,13 +422,15 @@ async function loadAllTranslations({
|
|
|
419
422
|
cwd: projectRoot
|
|
420
423
|
});
|
|
421
424
|
trace(`Found ${translationFiles.length} translation files`);
|
|
422
|
-
const
|
|
423
|
-
filePath,
|
|
424
|
-
fallbacks,
|
|
425
|
-
withTags
|
|
426
|
-
}, config)));
|
|
425
|
+
const loadedTranslations = [];
|
|
427
426
|
const keys = new Set();
|
|
428
|
-
for (const
|
|
427
|
+
for (const translationFile of translationFiles) {
|
|
428
|
+
const loadedTranslation = loadTranslation({
|
|
429
|
+
filePath: translationFile,
|
|
430
|
+
fallbacks,
|
|
431
|
+
withTags
|
|
432
|
+
}, config);
|
|
433
|
+
loadedTranslations.push(loadedTranslation);
|
|
429
434
|
for (const key of loadedTranslation.keys) {
|
|
430
435
|
const uniqueKey = getUniqueKey(key, loadedTranslation.namespace);
|
|
431
436
|
if (keys.has(uniqueKey)) {
|
|
@@ -442,7 +447,7 @@ async function loadAllTranslations({
|
|
|
442
447
|
}
|
|
443
448
|
}
|
|
444
449
|
}
|
|
445
|
-
return
|
|
450
|
+
return loadedTranslations;
|
|
446
451
|
}
|
|
447
452
|
|
|
448
453
|
function extractHasTags(ast) {
|
|
@@ -659,7 +664,7 @@ async function writeIfChanged(filepath, contents) {
|
|
|
659
664
|
encoding: 'utf-8'
|
|
660
665
|
});
|
|
661
666
|
hasChanged = existingContents !== contents;
|
|
662
|
-
} catch
|
|
667
|
+
} catch {
|
|
663
668
|
// ignore error, likely a file doesn't exist error so we want to write anyway
|
|
664
669
|
}
|
|
665
670
|
if (hasChanged) {
|
|
@@ -706,10 +711,10 @@ async function validate(config) {
|
|
|
706
711
|
const [translationValid, result] = findMissingKeys(loadedTranslation, config.devLanguage, getAltLanguages(config));
|
|
707
712
|
if (!translationValid) {
|
|
708
713
|
valid = false;
|
|
709
|
-
console.log(
|
|
714
|
+
console.log(pc__default["default"].red(`Incomplete translations: "${pc__default["default"].bold(loadedTranslation.relativePath)}"`));
|
|
710
715
|
for (const lang of Object.keys(result)) {
|
|
711
716
|
const missingKeys = result[lang];
|
|
712
|
-
console.log(
|
|
717
|
+
console.log(pc__default["default"].yellow(lang), '->', missingKeys.map(v => `"${v}"`).join(', '));
|
|
713
718
|
}
|
|
714
719
|
}
|
|
715
720
|
}
|
|
@@ -724,6 +729,7 @@ class ValidationError extends Error {
|
|
|
724
729
|
}
|
|
725
730
|
}
|
|
726
731
|
|
|
732
|
+
const boldCyan = s => pc__default["default"].bold(pc__default["default"].cyan(s));
|
|
727
733
|
const validator = new Validator__default["default"]();
|
|
728
734
|
const schema = {
|
|
729
735
|
$$strict: true,
|
|
@@ -797,11 +803,11 @@ function validateConfig(c) {
|
|
|
797
803
|
if (isValid !== true) {
|
|
798
804
|
throw new ValidationError('InvalidStructure', (Array.isArray(isValid) ? isValid : []).map(v => {
|
|
799
805
|
if (v.type === 'objectStrict') {
|
|
800
|
-
return `Invalid key(s) ${splitMap(v.actual, m => `"${
|
|
806
|
+
return `Invalid key(s) ${splitMap(v.actual, m => `"${pc__default["default"].cyan(m)}"`)}. Expected one of ${splitMap(v.expected, pc__default["default"].green)}`;
|
|
801
807
|
}
|
|
802
808
|
if (v.field) {
|
|
803
809
|
var _v$message;
|
|
804
|
-
return (_v$message = v.message) === null || _v$message === void 0 ? void 0 : _v$message.replace(v.field,
|
|
810
|
+
return (_v$message = v.message) === null || _v$message === void 0 ? void 0 : _v$message.replace(v.field, pc__default["default"].cyan(v.field));
|
|
805
811
|
}
|
|
806
812
|
return v.message;
|
|
807
813
|
}).join(' \n'));
|
|
@@ -810,37 +816,37 @@ function validateConfig(c) {
|
|
|
810
816
|
|
|
811
817
|
// Dev Language should exist in languages
|
|
812
818
|
if (!languageStrings.includes(c.devLanguage)) {
|
|
813
|
-
throw new ValidationError('InvalidDevLanguage', `The dev language "${
|
|
819
|
+
throw new ValidationError('InvalidDevLanguage', `The dev language "${boldCyan(c.devLanguage)}" was not found in languages ${languageStrings.join(', ')}.`);
|
|
814
820
|
}
|
|
815
821
|
const foundLanguages = [];
|
|
816
822
|
for (const lang of c.languages) {
|
|
817
823
|
// Languages must only exist once
|
|
818
824
|
if (foundLanguages.includes(lang.name)) {
|
|
819
|
-
throw new ValidationError('DuplicateLanguage', `The language "${
|
|
825
|
+
throw new ValidationError('DuplicateLanguage', `The language "${boldCyan(lang.name)}" was defined multiple times.`);
|
|
820
826
|
}
|
|
821
827
|
foundLanguages.push(lang.name);
|
|
822
828
|
|
|
823
829
|
// Any extends must be in languages
|
|
824
830
|
if (lang.extends && !languageStrings.includes(lang.extends)) {
|
|
825
|
-
throw new ValidationError('InvalidExtends', `The language "${
|
|
831
|
+
throw new ValidationError('InvalidExtends', `The language "${boldCyan(lang.name)}"'s extends of ${boldCyan(lang.extends)} was not found in languages ${languageStrings.join(', ')}.`);
|
|
826
832
|
}
|
|
827
833
|
}
|
|
828
834
|
const foundGeneratedLanguages = [];
|
|
829
835
|
for (const generatedLang of c.generatedLanguages || []) {
|
|
830
836
|
// Generated languages must only exist once
|
|
831
837
|
if (foundGeneratedLanguages.includes(generatedLang.name)) {
|
|
832
|
-
throw new ValidationError('DuplicateGeneratedLanguage', `The generated language "${
|
|
838
|
+
throw new ValidationError('DuplicateGeneratedLanguage', `The generated language "${boldCyan(generatedLang.name)}" was defined multiple times.`);
|
|
833
839
|
}
|
|
834
840
|
foundGeneratedLanguages.push(generatedLang.name);
|
|
835
841
|
|
|
836
842
|
// Generated language names must not conflict with language names
|
|
837
843
|
if (languageStrings.includes(generatedLang.name)) {
|
|
838
|
-
throw new ValidationError('InvalidGeneratedLanguage', `The generated language "${
|
|
844
|
+
throw new ValidationError('InvalidGeneratedLanguage', `The generated language "${boldCyan(generatedLang.name)}" is already defined as a language.`);
|
|
839
845
|
}
|
|
840
846
|
|
|
841
847
|
// Any extends must be in languages
|
|
842
848
|
if (generatedLang.extends && !languageStrings.includes(generatedLang.extends)) {
|
|
843
|
-
throw new ValidationError('InvalidExtends', `The generated language "${
|
|
849
|
+
throw new ValidationError('InvalidExtends', `The generated language "${boldCyan(generatedLang.name)}"'s extends of ${boldCyan(generatedLang.extends)} was not found in languages ${languageStrings.join(', ')}.`);
|
|
844
850
|
}
|
|
845
851
|
}
|
|
846
852
|
trace('Configuration file is valid');
|
|
@@ -850,6 +856,7 @@ function createConfig(configFilePath) {
|
|
|
850
856
|
const cwd = path__default["default"].dirname(configFilePath);
|
|
851
857
|
return {
|
|
852
858
|
projectRoot: cwd,
|
|
859
|
+
// eslint-disable-next-line @typescript-eslint/no-require-imports
|
|
853
860
|
...require(configFilePath)
|
|
854
861
|
};
|
|
855
862
|
}
|
|
@@ -7,7 +7,7 @@ var path = require('path');
|
|
|
7
7
|
var icuMessageformatParser = require('@formatjs/icu-messageformat-parser');
|
|
8
8
|
var prettier = require('prettier');
|
|
9
9
|
var chokidar = require('chokidar');
|
|
10
|
-
var
|
|
10
|
+
var pc = require('picocolors');
|
|
11
11
|
var debug = require('debug');
|
|
12
12
|
var glob = require('fast-glob');
|
|
13
13
|
var IntlMessageFormat = require('intl-messageformat');
|
|
@@ -20,7 +20,7 @@ function _interopDefault (e) { return e && e.__esModule ? e : { 'default': e };
|
|
|
20
20
|
var path__default = /*#__PURE__*/_interopDefault(path);
|
|
21
21
|
var prettier__default = /*#__PURE__*/_interopDefault(prettier);
|
|
22
22
|
var chokidar__default = /*#__PURE__*/_interopDefault(chokidar);
|
|
23
|
-
var
|
|
23
|
+
var pc__default = /*#__PURE__*/_interopDefault(pc);
|
|
24
24
|
var debug__default = /*#__PURE__*/_interopDefault(debug);
|
|
25
25
|
var glob__default = /*#__PURE__*/_interopDefault(glob);
|
|
26
26
|
var IntlMessageFormat__default = /*#__PURE__*/_interopDefault(IntlMessageFormat);
|
|
@@ -244,7 +244,7 @@ function getNamespaceByFilePath(relativePath, {
|
|
|
244
244
|
}
|
|
245
245
|
function printValidationError(...params) {
|
|
246
246
|
// eslint-disable-next-line no-console
|
|
247
|
-
console.error(
|
|
247
|
+
console.error(pc__default["default"].red('Error loading translation:'), ...params);
|
|
248
248
|
}
|
|
249
249
|
function getTranslationsFromFile(translationFileContents, {
|
|
250
250
|
isAltLanguage,
|
|
@@ -324,6 +324,8 @@ function loadAltLanguageFile({
|
|
|
324
324
|
try {
|
|
325
325
|
const altFilePath = getAltLanguageFilePath(filePath, fallbackLanguage);
|
|
326
326
|
delete require.cache[altFilePath];
|
|
327
|
+
|
|
328
|
+
// eslint-disable-next-line @typescript-eslint/no-require-imports
|
|
327
329
|
const translationFile = require(altFilePath);
|
|
328
330
|
const {
|
|
329
331
|
keys: fallbackLanguageTranslation
|
|
@@ -335,7 +337,7 @@ function loadAltLanguageFile({
|
|
|
335
337
|
translation: fallbackLanguageTranslation,
|
|
336
338
|
devTranslation
|
|
337
339
|
}));
|
|
338
|
-
} catch
|
|
340
|
+
} catch {
|
|
339
341
|
trace(`Missing alt language file ${getAltLanguageFilePath(filePath, fallbackLanguage)}
|
|
340
342
|
`);
|
|
341
343
|
}
|
|
@@ -359,6 +361,7 @@ function loadTranslation({
|
|
|
359
361
|
trace(`Loading translation file in "${fallbacks}" fallback mode: "${filePath}"`);
|
|
360
362
|
const languageSet = {};
|
|
361
363
|
delete require.cache[filePath];
|
|
364
|
+
// eslint-disable-next-line @typescript-eslint/no-require-imports
|
|
362
365
|
const translationContent = require(filePath);
|
|
363
366
|
const relativePath = path__default["default"].relative(userConfig.projectRoot || process.cwd(), filePath);
|
|
364
367
|
const {
|
|
@@ -419,13 +422,15 @@ async function loadAllTranslations({
|
|
|
419
422
|
cwd: projectRoot
|
|
420
423
|
});
|
|
421
424
|
trace(`Found ${translationFiles.length} translation files`);
|
|
422
|
-
const
|
|
423
|
-
filePath,
|
|
424
|
-
fallbacks,
|
|
425
|
-
withTags
|
|
426
|
-
}, config)));
|
|
425
|
+
const loadedTranslations = [];
|
|
427
426
|
const keys = new Set();
|
|
428
|
-
for (const
|
|
427
|
+
for (const translationFile of translationFiles) {
|
|
428
|
+
const loadedTranslation = loadTranslation({
|
|
429
|
+
filePath: translationFile,
|
|
430
|
+
fallbacks,
|
|
431
|
+
withTags
|
|
432
|
+
}, config);
|
|
433
|
+
loadedTranslations.push(loadedTranslation);
|
|
429
434
|
for (const key of loadedTranslation.keys) {
|
|
430
435
|
const uniqueKey = getUniqueKey(key, loadedTranslation.namespace);
|
|
431
436
|
if (keys.has(uniqueKey)) {
|
|
@@ -442,7 +447,7 @@ async function loadAllTranslations({
|
|
|
442
447
|
}
|
|
443
448
|
}
|
|
444
449
|
}
|
|
445
|
-
return
|
|
450
|
+
return loadedTranslations;
|
|
446
451
|
}
|
|
447
452
|
|
|
448
453
|
function extractHasTags(ast) {
|
|
@@ -659,7 +664,7 @@ async function writeIfChanged(filepath, contents) {
|
|
|
659
664
|
encoding: 'utf-8'
|
|
660
665
|
});
|
|
661
666
|
hasChanged = existingContents !== contents;
|
|
662
|
-
} catch
|
|
667
|
+
} catch {
|
|
663
668
|
// ignore error, likely a file doesn't exist error so we want to write anyway
|
|
664
669
|
}
|
|
665
670
|
if (hasChanged) {
|
|
@@ -706,10 +711,10 @@ async function validate(config) {
|
|
|
706
711
|
const [translationValid, result] = findMissingKeys(loadedTranslation, config.devLanguage, getAltLanguages(config));
|
|
707
712
|
if (!translationValid) {
|
|
708
713
|
valid = false;
|
|
709
|
-
console.log(
|
|
714
|
+
console.log(pc__default["default"].red(`Incomplete translations: "${pc__default["default"].bold(loadedTranslation.relativePath)}"`));
|
|
710
715
|
for (const lang of Object.keys(result)) {
|
|
711
716
|
const missingKeys = result[lang];
|
|
712
|
-
console.log(
|
|
717
|
+
console.log(pc__default["default"].yellow(lang), '->', missingKeys.map(v => `"${v}"`).join(', '));
|
|
713
718
|
}
|
|
714
719
|
}
|
|
715
720
|
}
|
|
@@ -724,6 +729,7 @@ class ValidationError extends Error {
|
|
|
724
729
|
}
|
|
725
730
|
}
|
|
726
731
|
|
|
732
|
+
const boldCyan = s => pc__default["default"].bold(pc__default["default"].cyan(s));
|
|
727
733
|
const validator = new Validator__default["default"]();
|
|
728
734
|
const schema = {
|
|
729
735
|
$$strict: true,
|
|
@@ -797,11 +803,11 @@ function validateConfig(c) {
|
|
|
797
803
|
if (isValid !== true) {
|
|
798
804
|
throw new ValidationError('InvalidStructure', (Array.isArray(isValid) ? isValid : []).map(v => {
|
|
799
805
|
if (v.type === 'objectStrict') {
|
|
800
|
-
return `Invalid key(s) ${splitMap(v.actual, m => `"${
|
|
806
|
+
return `Invalid key(s) ${splitMap(v.actual, m => `"${pc__default["default"].cyan(m)}"`)}. Expected one of ${splitMap(v.expected, pc__default["default"].green)}`;
|
|
801
807
|
}
|
|
802
808
|
if (v.field) {
|
|
803
809
|
var _v$message;
|
|
804
|
-
return (_v$message = v.message) === null || _v$message === void 0 ? void 0 : _v$message.replace(v.field,
|
|
810
|
+
return (_v$message = v.message) === null || _v$message === void 0 ? void 0 : _v$message.replace(v.field, pc__default["default"].cyan(v.field));
|
|
805
811
|
}
|
|
806
812
|
return v.message;
|
|
807
813
|
}).join(' \n'));
|
|
@@ -810,37 +816,37 @@ function validateConfig(c) {
|
|
|
810
816
|
|
|
811
817
|
// Dev Language should exist in languages
|
|
812
818
|
if (!languageStrings.includes(c.devLanguage)) {
|
|
813
|
-
throw new ValidationError('InvalidDevLanguage', `The dev language "${
|
|
819
|
+
throw new ValidationError('InvalidDevLanguage', `The dev language "${boldCyan(c.devLanguage)}" was not found in languages ${languageStrings.join(', ')}.`);
|
|
814
820
|
}
|
|
815
821
|
const foundLanguages = [];
|
|
816
822
|
for (const lang of c.languages) {
|
|
817
823
|
// Languages must only exist once
|
|
818
824
|
if (foundLanguages.includes(lang.name)) {
|
|
819
|
-
throw new ValidationError('DuplicateLanguage', `The language "${
|
|
825
|
+
throw new ValidationError('DuplicateLanguage', `The language "${boldCyan(lang.name)}" was defined multiple times.`);
|
|
820
826
|
}
|
|
821
827
|
foundLanguages.push(lang.name);
|
|
822
828
|
|
|
823
829
|
// Any extends must be in languages
|
|
824
830
|
if (lang.extends && !languageStrings.includes(lang.extends)) {
|
|
825
|
-
throw new ValidationError('InvalidExtends', `The language "${
|
|
831
|
+
throw new ValidationError('InvalidExtends', `The language "${boldCyan(lang.name)}"'s extends of ${boldCyan(lang.extends)} was not found in languages ${languageStrings.join(', ')}.`);
|
|
826
832
|
}
|
|
827
833
|
}
|
|
828
834
|
const foundGeneratedLanguages = [];
|
|
829
835
|
for (const generatedLang of c.generatedLanguages || []) {
|
|
830
836
|
// Generated languages must only exist once
|
|
831
837
|
if (foundGeneratedLanguages.includes(generatedLang.name)) {
|
|
832
|
-
throw new ValidationError('DuplicateGeneratedLanguage', `The generated language "${
|
|
838
|
+
throw new ValidationError('DuplicateGeneratedLanguage', `The generated language "${boldCyan(generatedLang.name)}" was defined multiple times.`);
|
|
833
839
|
}
|
|
834
840
|
foundGeneratedLanguages.push(generatedLang.name);
|
|
835
841
|
|
|
836
842
|
// Generated language names must not conflict with language names
|
|
837
843
|
if (languageStrings.includes(generatedLang.name)) {
|
|
838
|
-
throw new ValidationError('InvalidGeneratedLanguage', `The generated language "${
|
|
844
|
+
throw new ValidationError('InvalidGeneratedLanguage', `The generated language "${boldCyan(generatedLang.name)}" is already defined as a language.`);
|
|
839
845
|
}
|
|
840
846
|
|
|
841
847
|
// Any extends must be in languages
|
|
842
848
|
if (generatedLang.extends && !languageStrings.includes(generatedLang.extends)) {
|
|
843
|
-
throw new ValidationError('InvalidExtends', `The generated language "${
|
|
849
|
+
throw new ValidationError('InvalidExtends', `The generated language "${boldCyan(generatedLang.name)}"'s extends of ${boldCyan(generatedLang.extends)} was not found in languages ${languageStrings.join(', ')}.`);
|
|
844
850
|
}
|
|
845
851
|
}
|
|
846
852
|
trace('Configuration file is valid');
|
|
@@ -850,6 +856,7 @@ function createConfig(configFilePath) {
|
|
|
850
856
|
const cwd = path__default["default"].dirname(configFilePath);
|
|
851
857
|
return {
|
|
852
858
|
projectRoot: cwd,
|
|
859
|
+
// eslint-disable-next-line @typescript-eslint/no-require-imports
|
|
853
860
|
...require(configFilePath)
|
|
854
861
|
};
|
|
855
862
|
}
|
package/dist/vocab-core.esm.js
CHANGED
|
@@ -3,7 +3,7 @@ import path from 'path';
|
|
|
3
3
|
import { TYPE, parse, isSelectElement, isPluralElement, isTagElement, isArgumentElement, isNumberElement, isDateElement, isTimeElement } from '@formatjs/icu-messageformat-parser';
|
|
4
4
|
import prettier from 'prettier';
|
|
5
5
|
import chokidar from 'chokidar';
|
|
6
|
-
import
|
|
6
|
+
import pc from 'picocolors';
|
|
7
7
|
import debug from 'debug';
|
|
8
8
|
import glob from 'fast-glob';
|
|
9
9
|
import IntlMessageFormat from 'intl-messageformat';
|
|
@@ -228,7 +228,7 @@ function getNamespaceByFilePath(relativePath, {
|
|
|
228
228
|
}
|
|
229
229
|
function printValidationError(...params) {
|
|
230
230
|
// eslint-disable-next-line no-console
|
|
231
|
-
console.error(
|
|
231
|
+
console.error(pc.red('Error loading translation:'), ...params);
|
|
232
232
|
}
|
|
233
233
|
function getTranslationsFromFile(translationFileContents, {
|
|
234
234
|
isAltLanguage,
|
|
@@ -308,6 +308,8 @@ function loadAltLanguageFile({
|
|
|
308
308
|
try {
|
|
309
309
|
const altFilePath = getAltLanguageFilePath(filePath, fallbackLanguage);
|
|
310
310
|
delete require.cache[altFilePath];
|
|
311
|
+
|
|
312
|
+
// eslint-disable-next-line @typescript-eslint/no-require-imports
|
|
311
313
|
const translationFile = require(altFilePath);
|
|
312
314
|
const {
|
|
313
315
|
keys: fallbackLanguageTranslation
|
|
@@ -319,7 +321,7 @@ function loadAltLanguageFile({
|
|
|
319
321
|
translation: fallbackLanguageTranslation,
|
|
320
322
|
devTranslation
|
|
321
323
|
}));
|
|
322
|
-
} catch
|
|
324
|
+
} catch {
|
|
323
325
|
trace(`Missing alt language file ${getAltLanguageFilePath(filePath, fallbackLanguage)}
|
|
324
326
|
`);
|
|
325
327
|
}
|
|
@@ -343,6 +345,7 @@ function loadTranslation({
|
|
|
343
345
|
trace(`Loading translation file in "${fallbacks}" fallback mode: "${filePath}"`);
|
|
344
346
|
const languageSet = {};
|
|
345
347
|
delete require.cache[filePath];
|
|
348
|
+
// eslint-disable-next-line @typescript-eslint/no-require-imports
|
|
346
349
|
const translationContent = require(filePath);
|
|
347
350
|
const relativePath = path.relative(userConfig.projectRoot || process.cwd(), filePath);
|
|
348
351
|
const {
|
|
@@ -403,13 +406,15 @@ async function loadAllTranslations({
|
|
|
403
406
|
cwd: projectRoot
|
|
404
407
|
});
|
|
405
408
|
trace(`Found ${translationFiles.length} translation files`);
|
|
406
|
-
const
|
|
407
|
-
filePath,
|
|
408
|
-
fallbacks,
|
|
409
|
-
withTags
|
|
410
|
-
}, config)));
|
|
409
|
+
const loadedTranslations = [];
|
|
411
410
|
const keys = new Set();
|
|
412
|
-
for (const
|
|
411
|
+
for (const translationFile of translationFiles) {
|
|
412
|
+
const loadedTranslation = loadTranslation({
|
|
413
|
+
filePath: translationFile,
|
|
414
|
+
fallbacks,
|
|
415
|
+
withTags
|
|
416
|
+
}, config);
|
|
417
|
+
loadedTranslations.push(loadedTranslation);
|
|
413
418
|
for (const key of loadedTranslation.keys) {
|
|
414
419
|
const uniqueKey = getUniqueKey(key, loadedTranslation.namespace);
|
|
415
420
|
if (keys.has(uniqueKey)) {
|
|
@@ -426,7 +431,7 @@ async function loadAllTranslations({
|
|
|
426
431
|
}
|
|
427
432
|
}
|
|
428
433
|
}
|
|
429
|
-
return
|
|
434
|
+
return loadedTranslations;
|
|
430
435
|
}
|
|
431
436
|
|
|
432
437
|
function extractHasTags(ast) {
|
|
@@ -643,7 +648,7 @@ async function writeIfChanged(filepath, contents) {
|
|
|
643
648
|
encoding: 'utf-8'
|
|
644
649
|
});
|
|
645
650
|
hasChanged = existingContents !== contents;
|
|
646
|
-
} catch
|
|
651
|
+
} catch {
|
|
647
652
|
// ignore error, likely a file doesn't exist error so we want to write anyway
|
|
648
653
|
}
|
|
649
654
|
if (hasChanged) {
|
|
@@ -690,10 +695,10 @@ async function validate(config) {
|
|
|
690
695
|
const [translationValid, result] = findMissingKeys(loadedTranslation, config.devLanguage, getAltLanguages(config));
|
|
691
696
|
if (!translationValid) {
|
|
692
697
|
valid = false;
|
|
693
|
-
console.log(
|
|
698
|
+
console.log(pc.red(`Incomplete translations: "${pc.bold(loadedTranslation.relativePath)}"`));
|
|
694
699
|
for (const lang of Object.keys(result)) {
|
|
695
700
|
const missingKeys = result[lang];
|
|
696
|
-
console.log(
|
|
701
|
+
console.log(pc.yellow(lang), '->', missingKeys.map(v => `"${v}"`).join(', '));
|
|
697
702
|
}
|
|
698
703
|
}
|
|
699
704
|
}
|
|
@@ -708,6 +713,7 @@ class ValidationError extends Error {
|
|
|
708
713
|
}
|
|
709
714
|
}
|
|
710
715
|
|
|
716
|
+
const boldCyan = s => pc.bold(pc.cyan(s));
|
|
711
717
|
const validator = new Validator();
|
|
712
718
|
const schema = {
|
|
713
719
|
$$strict: true,
|
|
@@ -781,11 +787,11 @@ function validateConfig(c) {
|
|
|
781
787
|
if (isValid !== true) {
|
|
782
788
|
throw new ValidationError('InvalidStructure', (Array.isArray(isValid) ? isValid : []).map(v => {
|
|
783
789
|
if (v.type === 'objectStrict') {
|
|
784
|
-
return `Invalid key(s) ${splitMap(v.actual, m => `"${
|
|
790
|
+
return `Invalid key(s) ${splitMap(v.actual, m => `"${pc.cyan(m)}"`)}. Expected one of ${splitMap(v.expected, pc.green)}`;
|
|
785
791
|
}
|
|
786
792
|
if (v.field) {
|
|
787
793
|
var _v$message;
|
|
788
|
-
return (_v$message = v.message) === null || _v$message === void 0 ? void 0 : _v$message.replace(v.field,
|
|
794
|
+
return (_v$message = v.message) === null || _v$message === void 0 ? void 0 : _v$message.replace(v.field, pc.cyan(v.field));
|
|
789
795
|
}
|
|
790
796
|
return v.message;
|
|
791
797
|
}).join(' \n'));
|
|
@@ -794,37 +800,37 @@ function validateConfig(c) {
|
|
|
794
800
|
|
|
795
801
|
// Dev Language should exist in languages
|
|
796
802
|
if (!languageStrings.includes(c.devLanguage)) {
|
|
797
|
-
throw new ValidationError('InvalidDevLanguage', `The dev language "${
|
|
803
|
+
throw new ValidationError('InvalidDevLanguage', `The dev language "${boldCyan(c.devLanguage)}" was not found in languages ${languageStrings.join(', ')}.`);
|
|
798
804
|
}
|
|
799
805
|
const foundLanguages = [];
|
|
800
806
|
for (const lang of c.languages) {
|
|
801
807
|
// Languages must only exist once
|
|
802
808
|
if (foundLanguages.includes(lang.name)) {
|
|
803
|
-
throw new ValidationError('DuplicateLanguage', `The language "${
|
|
809
|
+
throw new ValidationError('DuplicateLanguage', `The language "${boldCyan(lang.name)}" was defined multiple times.`);
|
|
804
810
|
}
|
|
805
811
|
foundLanguages.push(lang.name);
|
|
806
812
|
|
|
807
813
|
// Any extends must be in languages
|
|
808
814
|
if (lang.extends && !languageStrings.includes(lang.extends)) {
|
|
809
|
-
throw new ValidationError('InvalidExtends', `The language "${
|
|
815
|
+
throw new ValidationError('InvalidExtends', `The language "${boldCyan(lang.name)}"'s extends of ${boldCyan(lang.extends)} was not found in languages ${languageStrings.join(', ')}.`);
|
|
810
816
|
}
|
|
811
817
|
}
|
|
812
818
|
const foundGeneratedLanguages = [];
|
|
813
819
|
for (const generatedLang of c.generatedLanguages || []) {
|
|
814
820
|
// Generated languages must only exist once
|
|
815
821
|
if (foundGeneratedLanguages.includes(generatedLang.name)) {
|
|
816
|
-
throw new ValidationError('DuplicateGeneratedLanguage', `The generated language "${
|
|
822
|
+
throw new ValidationError('DuplicateGeneratedLanguage', `The generated language "${boldCyan(generatedLang.name)}" was defined multiple times.`);
|
|
817
823
|
}
|
|
818
824
|
foundGeneratedLanguages.push(generatedLang.name);
|
|
819
825
|
|
|
820
826
|
// Generated language names must not conflict with language names
|
|
821
827
|
if (languageStrings.includes(generatedLang.name)) {
|
|
822
|
-
throw new ValidationError('InvalidGeneratedLanguage', `The generated language "${
|
|
828
|
+
throw new ValidationError('InvalidGeneratedLanguage', `The generated language "${boldCyan(generatedLang.name)}" is already defined as a language.`);
|
|
823
829
|
}
|
|
824
830
|
|
|
825
831
|
// Any extends must be in languages
|
|
826
832
|
if (generatedLang.extends && !languageStrings.includes(generatedLang.extends)) {
|
|
827
|
-
throw new ValidationError('InvalidExtends', `The generated language "${
|
|
833
|
+
throw new ValidationError('InvalidExtends', `The generated language "${boldCyan(generatedLang.name)}"'s extends of ${boldCyan(generatedLang.extends)} was not found in languages ${languageStrings.join(', ')}.`);
|
|
828
834
|
}
|
|
829
835
|
}
|
|
830
836
|
trace('Configuration file is valid');
|
|
@@ -834,6 +840,7 @@ function createConfig(configFilePath) {
|
|
|
834
840
|
const cwd = path.dirname(configFilePath);
|
|
835
841
|
return {
|
|
836
842
|
projectRoot: cwd,
|
|
843
|
+
// eslint-disable-next-line @typescript-eslint/no-require-imports
|
|
837
844
|
...require(configFilePath)
|
|
838
845
|
};
|
|
839
846
|
}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
export * from "../../dist/declarations/src/icu-handler";
|
|
2
|
-
//# sourceMappingURL=
|
|
2
|
+
//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoidm9jYWItY29yZS1pY3UtaGFuZGxlci5janMuZC50cyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uLy4uL2Rpc3QvZGVjbGFyYXRpb25zL3NyYy9pY3UtaGFuZGxlci5kLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiJBQUFBIn0=
|
package/package.json
CHANGED
|
@@ -1,6 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vocab/core",
|
|
3
|
-
"version": "1.6.
|
|
3
|
+
"version": "1.6.3",
|
|
4
|
+
"repository": {
|
|
5
|
+
"type": "git",
|
|
6
|
+
"url": "https://github.com/seek-oss/vocab.git",
|
|
7
|
+
"directory": "packages/core"
|
|
8
|
+
},
|
|
4
9
|
"main": "dist/vocab-core.cjs.js",
|
|
5
10
|
"module": "dist/vocab-core.esm.js",
|
|
6
11
|
"exports": {
|
|
@@ -40,13 +45,13 @@
|
|
|
40
45
|
],
|
|
41
46
|
"dependencies": {
|
|
42
47
|
"@formatjs/icu-messageformat-parser": "^2.0.10",
|
|
43
|
-
"chalk": "^4.1.0",
|
|
44
48
|
"chokidar": "^3.4.3",
|
|
45
49
|
"debug": "^4.3.1",
|
|
46
50
|
"fast-glob": "^3.2.4",
|
|
47
51
|
"fastest-validator": "^1.9.0",
|
|
48
52
|
"find-up": "^5.0.0",
|
|
49
53
|
"intl-messageformat": "^10.0.0",
|
|
54
|
+
"picocolors": "^1.0.0",
|
|
50
55
|
"prettier": "^2.1.2"
|
|
51
56
|
},
|
|
52
57
|
"devDependencies": {
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
export * from "../../dist/declarations/src/runtime";
|
|
2
|
-
//# sourceMappingURL=
|
|
2
|
+
//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoidm9jYWItY29yZS1ydW50aW1lLmNqcy5kLnRzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vLi4vZGlzdC9kZWNsYXJhdGlvbnMvc3JjL3J1bnRpbWUuZC50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFBQSJ9
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
export * from "../../dist/declarations/src/translation-file";
|
|
2
|
-
//# sourceMappingURL=
|
|
2
|
+
//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoidm9jYWItY29yZS10cmFuc2xhdGlvbi1maWxlLmNqcy5kLnRzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vLi4vZGlzdC9kZWNsYXJhdGlvbnMvc3JjL3RyYW5zbGF0aW9uLWZpbGUuZC50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFBQSJ9
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"vocab-core.cjs.d.ts","sourceRoot":"","sources":["./declarations/src/index.d.ts"],"names":[],"mappings":"AAAA"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"vocab-core-icu-handler.cjs.d.ts","sourceRoot":"","sources":["../../dist/declarations/src/icu-handler.d.ts"],"names":[],"mappings":"AAAA"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"vocab-core-runtime.cjs.d.ts","sourceRoot":"","sources":["../../dist/declarations/src/runtime.d.ts"],"names":[],"mappings":"AAAA"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"vocab-core-translation-file.cjs.d.ts","sourceRoot":"","sources":["../../dist/declarations/src/translation-file.d.ts"],"names":[],"mappings":"AAAA"}
|