@digitaldefiance/i18n-lib 1.0.24 → 1.0.26
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/default-config.d.ts +7 -1
- package/dist/default-config.js +42 -0
- package/dist/typed-error.d.ts +9 -0
- package/dist/typed-error.js +18 -0
- package/dist/utils.d.ts +3 -3
- package/dist/utils.js +11 -7
- package/package.json +1 -1
package/dist/default-config.d.ts
CHANGED
|
@@ -2,7 +2,13 @@ import { I18nEngine } from './i18n-engine';
|
|
|
2
2
|
import { Timezone } from './timezone';
|
|
3
3
|
import { I18nContext, LanguageCodeCollection } from './types';
|
|
4
4
|
export declare enum DefaultStringKey {
|
|
5
|
-
Common_Test = "common_test"
|
|
5
|
+
Common_Test = "common_test",
|
|
6
|
+
Error_InstanceAlreadyExistsTemplate = "error_instanceAlreadyExistsTemplate",
|
|
7
|
+
Error_InstanceNotFoundTemplate = "error_instanceNotFoundTemplate",
|
|
8
|
+
Error_MissingStringCollectionTemplate = "error_missingStringCollectionTemplate",
|
|
9
|
+
Error_MissingTranslationTemplate = "error_missingTranslationTemplate",
|
|
10
|
+
Error_DefaultLanguageNoCollectionTemplate = "error_defaultLanguageNoCollectionTemplate",
|
|
11
|
+
Error_MissingTranslationKeyTemplate = "error_missingTranslationKeyTemplate"
|
|
6
12
|
}
|
|
7
13
|
export declare enum DefaultLanguage {
|
|
8
14
|
EnglishUS = "English (US)",
|
package/dist/default-config.js
CHANGED
|
@@ -9,6 +9,12 @@ const types_1 = require("./types");
|
|
|
9
9
|
var DefaultStringKey;
|
|
10
10
|
(function (DefaultStringKey) {
|
|
11
11
|
DefaultStringKey["Common_Test"] = "common_test";
|
|
12
|
+
DefaultStringKey["Error_InstanceAlreadyExistsTemplate"] = "error_instanceAlreadyExistsTemplate";
|
|
13
|
+
DefaultStringKey["Error_InstanceNotFoundTemplate"] = "error_instanceNotFoundTemplate";
|
|
14
|
+
DefaultStringKey["Error_MissingStringCollectionTemplate"] = "error_missingStringCollectionTemplate";
|
|
15
|
+
DefaultStringKey["Error_MissingTranslationTemplate"] = "error_missingTranslationTemplate";
|
|
16
|
+
DefaultStringKey["Error_DefaultLanguageNoCollectionTemplate"] = "error_defaultLanguageNoCollectionTemplate";
|
|
17
|
+
DefaultStringKey["Error_MissingTranslationKeyTemplate"] = "error_missingTranslationKeyTemplate";
|
|
12
18
|
})(DefaultStringKey || (exports.DefaultStringKey = DefaultStringKey = {}));
|
|
13
19
|
var DefaultLanguage;
|
|
14
20
|
(function (DefaultLanguage) {
|
|
@@ -34,21 +40,57 @@ const getConfig = (constants, timezone, adminTimezone) => ({
|
|
|
34
40
|
strings: {
|
|
35
41
|
[DefaultLanguage.EnglishUS]: {
|
|
36
42
|
[DefaultStringKey.Common_Test]: 'Test',
|
|
43
|
+
[DefaultStringKey.Error_InstanceAlreadyExistsTemplate]: 'Instance with key \'{key}\' already exists',
|
|
44
|
+
[DefaultStringKey.Error_InstanceNotFoundTemplate]: 'Instance with key \'{key}\' not found',
|
|
45
|
+
[DefaultStringKey.Error_MissingStringCollectionTemplate]: 'Missing string collection for language: {language}',
|
|
46
|
+
[DefaultStringKey.Error_MissingTranslationTemplate]: 'Missing translation for key \'{key}\' in language \'{language}\'',
|
|
47
|
+
[DefaultStringKey.Error_DefaultLanguageNoCollectionTemplate]: 'Default language \'{language}\' has no string collection',
|
|
48
|
+
[DefaultStringKey.Error_MissingTranslationKeyTemplate]: 'Missing translation key for type: {type}',
|
|
37
49
|
},
|
|
38
50
|
[DefaultLanguage.EnglishUK]: {
|
|
39
51
|
[DefaultStringKey.Common_Test]: 'Test',
|
|
52
|
+
[DefaultStringKey.Error_InstanceAlreadyExistsTemplate]: 'Instance with key \'{key}\' already exists',
|
|
53
|
+
[DefaultStringKey.Error_InstanceNotFoundTemplate]: 'Instance with key \'{key}\' not found',
|
|
54
|
+
[DefaultStringKey.Error_MissingStringCollectionTemplate]: 'Missing string collection for language: {language}',
|
|
55
|
+
[DefaultStringKey.Error_MissingTranslationTemplate]: 'Missing translation for key \'{key}\' in language \'{language}\'',
|
|
56
|
+
[DefaultStringKey.Error_DefaultLanguageNoCollectionTemplate]: 'Default language \'{language}\' has no string collection',
|
|
57
|
+
[DefaultStringKey.Error_MissingTranslationKeyTemplate]: 'Missing translation key for type: {type}',
|
|
40
58
|
},
|
|
41
59
|
[DefaultLanguage.French]: {
|
|
42
60
|
[DefaultStringKey.Common_Test]: 'Test',
|
|
61
|
+
[DefaultStringKey.Error_InstanceAlreadyExistsTemplate]: 'Instance avec clé \'{key}\' existe déjà',
|
|
62
|
+
[DefaultStringKey.Error_InstanceNotFoundTemplate]: 'Instance avec clé \'{key}\' introuvable',
|
|
63
|
+
[DefaultStringKey.Error_MissingStringCollectionTemplate]: 'Collection de chaînes manquante pour la langue: {language}',
|
|
64
|
+
[DefaultStringKey.Error_MissingTranslationTemplate]: 'Traduction manquante pour la clé \'{key}\' dans la langue \'{language}\'',
|
|
65
|
+
[DefaultStringKey.Error_DefaultLanguageNoCollectionTemplate]: 'La langue par défaut \'{language}\' n\'a pas de collection de chaînes',
|
|
66
|
+
[DefaultStringKey.Error_MissingTranslationKeyTemplate]: 'Clé de traduction manquante pour le type: {type}',
|
|
43
67
|
},
|
|
44
68
|
[DefaultLanguage.MandarinChinese]: {
|
|
45
69
|
[DefaultStringKey.Common_Test]: '测试',
|
|
70
|
+
[DefaultStringKey.Error_InstanceAlreadyExistsTemplate]: '键为\'{key}\'的实例已存在',
|
|
71
|
+
[DefaultStringKey.Error_InstanceNotFoundTemplate]: '未找到键为\'{key}\'的实例',
|
|
72
|
+
[DefaultStringKey.Error_MissingStringCollectionTemplate]: '缺少语言的字符串集合: {language}',
|
|
73
|
+
[DefaultStringKey.Error_MissingTranslationTemplate]: '在语言\'{language}\'中缺少键\'{key}\'的翻译',
|
|
74
|
+
[DefaultStringKey.Error_DefaultLanguageNoCollectionTemplate]: '默认语言\'{language}\'没有字符串集合',
|
|
75
|
+
[DefaultStringKey.Error_MissingTranslationKeyTemplate]: '类型缺少翻译键: {type}',
|
|
46
76
|
},
|
|
47
77
|
[DefaultLanguage.Spanish]: {
|
|
48
78
|
[DefaultStringKey.Common_Test]: 'Prueba',
|
|
79
|
+
[DefaultStringKey.Error_InstanceAlreadyExistsTemplate]: 'La instancia con clave \'{key}\' ya existe',
|
|
80
|
+
[DefaultStringKey.Error_InstanceNotFoundTemplate]: 'Instancia con clave \'{key}\' no encontrada',
|
|
81
|
+
[DefaultStringKey.Error_MissingStringCollectionTemplate]: 'Falta colección de cadenas para el idioma: {language}',
|
|
82
|
+
[DefaultStringKey.Error_MissingTranslationTemplate]: 'Falta traducción para la clave \'{key}\' en el idioma \'{language}\'',
|
|
83
|
+
[DefaultStringKey.Error_DefaultLanguageNoCollectionTemplate]: 'El idioma predeterminado \'{language}\' no tiene colección de cadenas',
|
|
84
|
+
[DefaultStringKey.Error_MissingTranslationKeyTemplate]: 'Falta clave de traducción para el tipo: {type}',
|
|
49
85
|
},
|
|
50
86
|
[DefaultLanguage.Ukrainian]: {
|
|
51
87
|
[DefaultStringKey.Common_Test]: 'Тест',
|
|
88
|
+
[DefaultStringKey.Error_InstanceAlreadyExistsTemplate]: 'Екземпляр з ключем \'{key}\' вже існує',
|
|
89
|
+
[DefaultStringKey.Error_InstanceNotFoundTemplate]: 'Екземпляр з ключем \'{key}\' не знайдено',
|
|
90
|
+
[DefaultStringKey.Error_MissingStringCollectionTemplate]: 'Відсутня колекція рядків для мови: {language}',
|
|
91
|
+
[DefaultStringKey.Error_MissingTranslationTemplate]: 'Відсутній переклад для ключа \'{key}\' в мові \'{language}\'',
|
|
92
|
+
[DefaultStringKey.Error_DefaultLanguageNoCollectionTemplate]: 'Мова за замовчуванням \'{language}\' не має колекції рядків',
|
|
93
|
+
[DefaultStringKey.Error_MissingTranslationKeyTemplate]: 'Відсутній ключ перекладу для типу: {type}',
|
|
52
94
|
},
|
|
53
95
|
},
|
|
54
96
|
stringNames: Object.values(DefaultStringKey),
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { Language, StringKey } from './default-config';
|
|
2
|
+
import { I18nEngine } from './i18n-engine';
|
|
3
|
+
export declare abstract class TypedError<T extends string | number> extends Error {
|
|
4
|
+
readonly type: T;
|
|
5
|
+
readonly reasonMap: Record<T, StringKey>;
|
|
6
|
+
readonly language?: Language | undefined;
|
|
7
|
+
readonly otherVars?: Record<string, string | number> | undefined;
|
|
8
|
+
constructor(engine: I18nEngine<StringKey, Language, Record<string, any>, string>, type: T, reasonMap: Record<T, StringKey>, language?: Language | undefined, otherVars?: Record<string, string | number> | undefined);
|
|
9
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.TypedError = void 0;
|
|
4
|
+
const default_config_1 = require("./default-config");
|
|
5
|
+
class TypedError extends Error {
|
|
6
|
+
constructor(engine, type, reasonMap, language, otherVars) {
|
|
7
|
+
const key = reasonMap[type];
|
|
8
|
+
if (!key)
|
|
9
|
+
throw new Error(engine.translate(default_config_1.DefaultStringKey.Error_MissingTranslationKeyTemplate, { type }, language));
|
|
10
|
+
super(engine.translate(key, otherVars, language));
|
|
11
|
+
this.type = type;
|
|
12
|
+
this.reasonMap = reasonMap;
|
|
13
|
+
this.language = language;
|
|
14
|
+
this.otherVars = otherVars;
|
|
15
|
+
this.name = this.constructor.name;
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
exports.TypedError = TypedError;
|
package/dist/utils.d.ts
CHANGED
|
@@ -26,16 +26,16 @@ export declare function isValidTimezone(timezone: string): boolean;
|
|
|
26
26
|
export declare function toStringKey<TStringKey extends string>(...parts: (string)[]): TStringKey;
|
|
27
27
|
/**
|
|
28
28
|
* Converts an enum value to a string key by joining parts with underscores and appending the enum value.
|
|
29
|
-
* @param enumObj - The enum object
|
|
30
29
|
* @param value - The enum value
|
|
31
30
|
* @param parts - Additional parts to join
|
|
32
31
|
* @returns The constructed string key
|
|
33
32
|
*/
|
|
34
|
-
export declare function toStringKeyFromEnum<TStringKey extends string
|
|
33
|
+
export declare function toStringKeyFromEnum<TStringKey extends string>(value: string, ...parts: string[]): TStringKey;
|
|
35
34
|
/**
|
|
36
35
|
* Builds a reason map from an enum object, mapping each enum value to a string key.
|
|
37
36
|
* @param enumObj - The enum object
|
|
38
37
|
* @param prefixes - Prefixes to prepend to each string key
|
|
38
|
+
* @param templateKeys - Optional set of enum values that should have 'Template' suffix for template processing
|
|
39
39
|
* @returns The constructed reason map
|
|
40
40
|
*/
|
|
41
|
-
export declare function buildReasonMap<
|
|
41
|
+
export declare function buildReasonMap<TEnum extends Record<string, string>, TStringKey extends string>(enumObj: TEnum, prefixes?: string[], templateKeys?: Set<TEnum[keyof TEnum]>): Record<TEnum[keyof TEnum], TStringKey>;
|
package/dist/utils.js
CHANGED
|
@@ -63,23 +63,27 @@ function toStringKey(...parts) {
|
|
|
63
63
|
}
|
|
64
64
|
/**
|
|
65
65
|
* Converts an enum value to a string key by joining parts with underscores and appending the enum value.
|
|
66
|
-
* @param enumObj - The enum object
|
|
67
66
|
* @param value - The enum value
|
|
68
67
|
* @param parts - Additional parts to join
|
|
69
68
|
* @returns The constructed string key
|
|
70
69
|
*/
|
|
71
70
|
function toStringKeyFromEnum(value, ...parts) {
|
|
72
|
-
|
|
71
|
+
const allParts = [...parts, value];
|
|
72
|
+
return allParts.join('_');
|
|
73
73
|
}
|
|
74
74
|
/**
|
|
75
75
|
* Builds a reason map from an enum object, mapping each enum value to a string key.
|
|
76
76
|
* @param enumObj - The enum object
|
|
77
77
|
* @param prefixes - Prefixes to prepend to each string key
|
|
78
|
+
* @param templateKeys - Optional set of enum values that should have 'Template' suffix for template processing
|
|
78
79
|
* @returns The constructed reason map
|
|
79
80
|
*/
|
|
80
|
-
function buildReasonMap(enumObj,
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
81
|
+
function buildReasonMap(enumObj, prefixes = [], templateKeys) {
|
|
82
|
+
const map = {};
|
|
83
|
+
Object.values(enumObj).forEach(value => {
|
|
84
|
+
const baseKey = [...prefixes, value].join('_');
|
|
85
|
+
const finalKey = templateKeys?.has(value) ? baseKey + 'Template' : baseKey;
|
|
86
|
+
map[value] = finalKey;
|
|
87
|
+
});
|
|
88
|
+
return map;
|
|
85
89
|
}
|