@digitaldefiance/i18n-lib 1.3.12 → 1.3.13
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 +4 -0
- package/package.json +12 -27
- package/src/active-context.ts +30 -0
- package/src/component-definition.ts +11 -0
- package/src/component-registration.ts +13 -0
- package/src/component-registry.ts +392 -0
- package/src/context-error-type.ts +3 -0
- package/src/context-error.ts +16 -0
- package/src/context-manager.ts +71 -0
- package/src/context.ts +90 -0
- package/src/core-i18n.ts +609 -0
- package/src/core-string-key.ts +49 -0
- package/src/create-translation-adapter.ts +47 -0
- package/src/currency-code.ts +35 -0
- package/{dist/currency-format.d.ts → src/currency-format.ts} +5 -4
- package/src/currency.ts +52 -0
- package/src/default-config.ts +199 -0
- package/src/enum-registry.ts +138 -0
- package/src/global-active-context.ts +255 -0
- package/src/handleable.ts +79 -0
- package/src/i-global-active-context.ts +59 -0
- package/src/i-handleable-error-options.ts +6 -0
- package/src/i-handleable.ts +5 -0
- package/src/i18n-config.ts +29 -0
- package/{dist/i18n-context.d.ts → src/i18n-context.ts} +7 -6
- package/src/i18n-engine.ts +491 -0
- package/{dist/index.d.ts → src/index.ts} +10 -1
- package/{dist/language-codes.d.ts → src/language-codes.ts} +23 -11
- package/src/language-definition.ts +13 -0
- package/src/language-registry.ts +292 -0
- package/src/plugin-i18n-engine.ts +520 -0
- package/src/plugin-translatable-generic-error.ts +106 -0
- package/src/plugin-translatable-handleable-generic.ts +60 -0
- package/src/plugin-typed-handleable.ts +77 -0
- package/src/registry-config.ts +15 -0
- package/src/registry-error-type.ts +12 -0
- package/src/registry-error.ts +74 -0
- package/src/strict-types.ts +35 -0
- package/src/template.ts +63 -0
- package/src/timezone.ts +20 -0
- package/src/translatable.ts +15 -0
- package/src/translation-engine.ts +8 -0
- package/src/translation-request.ts +12 -0
- package/src/translation-response.ts +8 -0
- package/src/typed-error.ts +384 -0
- package/src/typed-handleable.ts +70 -0
- package/{dist/types.d.ts → src/types.ts} +75 -20
- package/src/unified-translator.ts +96 -0
- package/src/utils.ts +213 -0
- package/src/validation-config.ts +11 -0
- package/src/validation-result.ts +12 -0
- package/dist/active-context.d.ts +0 -29
- package/dist/active-context.js +0 -2
- package/dist/component-definition.d.ts +0 -11
- package/dist/component-definition.js +0 -2
- package/dist/component-registration.d.ts +0 -9
- package/dist/component-registration.js +0 -2
- package/dist/component-registry.d.ts +0 -68
- package/dist/component-registry.js +0 -245
- package/dist/context-error-type.d.ts +0 -3
- package/dist/context-error-type.js +0 -7
- package/dist/context-error.d.ts +0 -6
- package/dist/context-error.js +0 -15
- package/dist/context-manager.d.ts +0 -33
- package/dist/context-manager.js +0 -61
- package/dist/context.d.ts +0 -44
- package/dist/context.js +0 -69
- package/dist/core-i18n.d.ts +0 -62
- package/dist/core-i18n.js +0 -477
- package/dist/core-string-key.d.ts +0 -42
- package/dist/core-string-key.js +0 -50
- package/dist/create-translation-adapter.d.ts +0 -20
- package/dist/create-translation-adapter.js +0 -36
- package/dist/currency-code.d.ts +0 -19
- package/dist/currency-code.js +0 -36
- package/dist/currency-format.js +0 -2
- package/dist/currency.d.ts +0 -11
- package/dist/currency.js +0 -48
- package/dist/default-config.d.ts +0 -32
- package/dist/default-config.js +0 -101
- package/dist/enum-registry.d.ts +0 -44
- package/dist/enum-registry.js +0 -100
- package/dist/global-active-context.d.ts +0 -50
- package/dist/global-active-context.js +0 -177
- package/dist/handleable.d.ts +0 -13
- package/dist/handleable.js +0 -56
- package/dist/i-global-active-context.d.ts +0 -22
- package/dist/i-global-active-context.js +0 -2
- package/dist/i-handleable-error-options.d.ts +0 -6
- package/dist/i-handleable-error-options.js +0 -2
- package/dist/i-handleable.d.ts +0 -5
- package/dist/i-handleable.js +0 -2
- package/dist/i18n-config.d.ts +0 -20
- package/dist/i18n-config.js +0 -2
- package/dist/i18n-context.js +0 -2
- package/dist/i18n-engine.d.ts +0 -178
- package/dist/i18n-engine.js +0 -338
- package/dist/index.js +0 -83
- package/dist/language-codes.js +0 -31
- package/dist/language-definition.d.ts +0 -13
- package/dist/language-definition.js +0 -2
- package/dist/language-registry.d.ts +0 -113
- package/dist/language-registry.js +0 -216
- package/dist/plugin-i18n-engine.d.ts +0 -146
- package/dist/plugin-i18n-engine.js +0 -360
- package/dist/plugin-translatable-generic-error.d.ts +0 -29
- package/dist/plugin-translatable-generic-error.js +0 -66
- package/dist/plugin-translatable-handleable-generic.d.ts +0 -28
- package/dist/plugin-translatable-handleable-generic.js +0 -40
- package/dist/plugin-typed-handleable.d.ts +0 -14
- package/dist/plugin-typed-handleable.js +0 -45
- package/dist/registry-config.d.ts +0 -14
- package/dist/registry-config.js +0 -2
- package/dist/registry-error-type.d.ts +0 -12
- package/dist/registry-error-type.js +0 -16
- package/dist/registry-error.d.ts +0 -18
- package/dist/registry-error.js +0 -45
- package/dist/strict-types.d.ts +0 -18
- package/dist/strict-types.js +0 -17
- package/dist/template.d.ts +0 -12
- package/dist/template.js +0 -30
- package/dist/timezone.d.ts +0 -11
- package/dist/timezone.js +0 -22
- package/dist/translatable-generic-error.d.ts +0 -29
- package/dist/translatable-generic-error.js +0 -66
- package/dist/translatable-handleable-generic.d.ts +0 -28
- package/dist/translatable-handleable-generic.js +0 -40
- package/dist/translatable.d.ts +0 -5
- package/dist/translatable.js +0 -11
- package/dist/translation-engine.d.ts +0 -8
- package/dist/translation-engine.js +0 -2
- package/dist/translation-request.d.ts +0 -9
- package/dist/translation-request.js +0 -2
- package/dist/translation-response.d.ts +0 -8
- package/dist/translation-response.js +0 -2
- package/dist/typed-error.d.ts +0 -72
- package/dist/typed-error.js +0 -251
- package/dist/typed-handleable.d.ts +0 -14
- package/dist/typed-handleable.js +0 -40
- package/dist/types.js +0 -18
- package/dist/unified-translator.d.ts +0 -30
- package/dist/unified-translator.js +0 -68
- package/dist/utils.d.ts +0 -64
- package/dist/utils.js +0 -130
- package/dist/validation-config.d.ts +0 -11
- package/dist/validation-config.js +0 -2
- package/dist/validation-result.d.ts +0 -12
- package/dist/validation-result.js +0 -2
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
import { PluginI18nEngine } from './plugin-i18n-engine';
|
|
2
|
+
import { I18nEngine } from './i18n-engine';
|
|
3
|
+
|
|
4
|
+
interface PluginSource {
|
|
5
|
+
type: 'plugin';
|
|
6
|
+
engine: PluginI18nEngine<any>;
|
|
7
|
+
componentId: string;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
interface LegacySource {
|
|
11
|
+
type: 'legacy';
|
|
12
|
+
engine: I18nEngine<any, any, any, any>;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
type TranslationSource = PluginSource | LegacySource;
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Unified translator with explicit component/engine specification
|
|
19
|
+
*/
|
|
20
|
+
export class UnifiedTranslator<TLanguage extends string = string> {
|
|
21
|
+
private sources = new Map<string, TranslationSource>();
|
|
22
|
+
private defaultLanguage: TLanguage;
|
|
23
|
+
private defaultSource?: string;
|
|
24
|
+
|
|
25
|
+
constructor(defaultLanguage: TLanguage) {
|
|
26
|
+
this.defaultLanguage = defaultLanguage;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Register a plugin component
|
|
31
|
+
*/
|
|
32
|
+
registerPlugin(
|
|
33
|
+
id: string,
|
|
34
|
+
engine: PluginI18nEngine<any>,
|
|
35
|
+
componentId: string,
|
|
36
|
+
): void {
|
|
37
|
+
this.sources.set(id, { type: 'plugin', engine, componentId });
|
|
38
|
+
if (!this.defaultSource) this.defaultSource = id;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* Register a legacy engine
|
|
43
|
+
*/
|
|
44
|
+
registerLegacy(id: string, engine: I18nEngine<any, any, any, any>): void {
|
|
45
|
+
this.sources.set(id, { type: 'legacy', engine });
|
|
46
|
+
if (!this.defaultSource) this.defaultSource = id;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* Set default source for unqualified keys
|
|
51
|
+
*/
|
|
52
|
+
setDefaultSource(id: string): void {
|
|
53
|
+
if (!this.sources.has(id)) {
|
|
54
|
+
throw new Error(`Source '${id}' not registered`);
|
|
55
|
+
}
|
|
56
|
+
this.defaultSource = id;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* Translate with explicit source: 'source:key' or just 'key' (uses default)
|
|
61
|
+
*/
|
|
62
|
+
translate(
|
|
63
|
+
key: string,
|
|
64
|
+
vars?: Record<string, string | number>,
|
|
65
|
+
language?: TLanguage,
|
|
66
|
+
): string {
|
|
67
|
+
const lang = language || this.defaultLanguage;
|
|
68
|
+
const [sourceName, actualKey] = key.includes(':')
|
|
69
|
+
? key.split(':', 2)
|
|
70
|
+
: [this.defaultSource, key];
|
|
71
|
+
|
|
72
|
+
if (!sourceName) return `[${key}]`;
|
|
73
|
+
|
|
74
|
+
const source = this.sources.get(sourceName);
|
|
75
|
+
if (!source) return `[${key}]`;
|
|
76
|
+
|
|
77
|
+
if (source.type === 'plugin') {
|
|
78
|
+
return source.engine.safeTranslate(source.componentId, actualKey, vars, lang);
|
|
79
|
+
} else {
|
|
80
|
+
return source.engine.safeTranslate(actualKey as any, vars, lang);
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
setLanguage(language: TLanguage): void {
|
|
85
|
+
this.defaultLanguage = language;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
getLanguage(): TLanguage {
|
|
89
|
+
return this.defaultLanguage;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
clearSources(): void {
|
|
93
|
+
this.sources.clear();
|
|
94
|
+
this.defaultSource = undefined;
|
|
95
|
+
}
|
|
96
|
+
}
|
package/src/utils.ts
ADDED
|
@@ -0,0 +1,213 @@
|
|
|
1
|
+
import moment from 'moment-timezone';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Replaces variables in a string with their corresponding values from vars or constants.
|
|
5
|
+
* @param str - The string containing variables to replace
|
|
6
|
+
* @param vars - An object mapping variable names to their replacement values
|
|
7
|
+
* @param constants - An object containing constant values for replacement
|
|
8
|
+
* @returns The string with variables replaced
|
|
9
|
+
*/
|
|
10
|
+
export function replaceVariables(
|
|
11
|
+
str: string,
|
|
12
|
+
vars?: Record<string, string | number>,
|
|
13
|
+
constants?: any,
|
|
14
|
+
): string {
|
|
15
|
+
// Ensure input is a string
|
|
16
|
+
if (typeof str !== 'string') {
|
|
17
|
+
str = String(str);
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
const variables = str.match(/\{(.+?)\}/g);
|
|
21
|
+
if (!variables) return str;
|
|
22
|
+
|
|
23
|
+
let result = str;
|
|
24
|
+
for (const variable of variables) {
|
|
25
|
+
const varName = variable.slice(1, -1);
|
|
26
|
+
let replacement = '';
|
|
27
|
+
|
|
28
|
+
if (vars && varName in vars) {
|
|
29
|
+
replacement = String(vars[varName]);
|
|
30
|
+
} else if (constants && varName in constants) {
|
|
31
|
+
replacement = String(constants[varName]);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
if (replacement) {
|
|
35
|
+
result = result.replace(variable, replacement);
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
return result;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* Checks if a given key indicates a template string.
|
|
44
|
+
* @param key - The key to check
|
|
45
|
+
* @returns True if the key indicates a template, false otherwise
|
|
46
|
+
*/
|
|
47
|
+
export function isTemplate(key: string): boolean {
|
|
48
|
+
return key.trim().toLowerCase().endsWith('template');
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* Checks if a given timezone string is valid.
|
|
53
|
+
* @param timezone - The timezone string to validate
|
|
54
|
+
* @returns
|
|
55
|
+
*/
|
|
56
|
+
export function isValidTimezone(timezone: string): boolean {
|
|
57
|
+
return moment.tz.zone(timezone) !== null;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* Converts parts to a single string key, joining with underscores.
|
|
62
|
+
* @param parts - The parts to join
|
|
63
|
+
* @returns The joined string key
|
|
64
|
+
*/
|
|
65
|
+
export function toStringKey<TStringKey extends string>(
|
|
66
|
+
...parts: string[]
|
|
67
|
+
): TStringKey {
|
|
68
|
+
return parts.join('_') as TStringKey;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
/**
|
|
72
|
+
* Converts an enum value to a string key by joining parts with underscores and appending the enum value.
|
|
73
|
+
* @param value - The enum value
|
|
74
|
+
* @param parts - Additional parts to join
|
|
75
|
+
* @returns The constructed string key
|
|
76
|
+
*/
|
|
77
|
+
export function toStringKeyFromEnum<TStringKey extends string>(
|
|
78
|
+
value: string,
|
|
79
|
+
...parts: string[]
|
|
80
|
+
): TStringKey {
|
|
81
|
+
const allParts = [...parts, value];
|
|
82
|
+
return allParts.join('_') as TStringKey;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
/**
|
|
86
|
+
* Type that constructs string keys from enum values with prefixes and optional template suffix
|
|
87
|
+
*/
|
|
88
|
+
type BuildStringKey<
|
|
89
|
+
TEnumValue extends string,
|
|
90
|
+
TPrefixes extends readonly string[],
|
|
91
|
+
TIsTemplate extends boolean = false,
|
|
92
|
+
> = TPrefixes extends readonly []
|
|
93
|
+
? `${TEnumValue}${TIsTemplate extends true ? 'Template' : ''}`
|
|
94
|
+
: TPrefixes extends readonly [infer First, ...infer Rest]
|
|
95
|
+
? First extends string
|
|
96
|
+
? Rest extends readonly string[]
|
|
97
|
+
? `${First}_${BuildStringKey<TEnumValue, Rest, TIsTemplate>}`
|
|
98
|
+
: never
|
|
99
|
+
: never
|
|
100
|
+
: never;
|
|
101
|
+
|
|
102
|
+
/**
|
|
103
|
+
* Type that maps all enum values to their corresponding string keys
|
|
104
|
+
*/
|
|
105
|
+
type ReasonMapFromEnum<
|
|
106
|
+
TEnum extends Record<string, string>,
|
|
107
|
+
TStringKey extends string,
|
|
108
|
+
TPrefixes extends readonly string[] = [],
|
|
109
|
+
TTemplateKeys extends Set<TEnum[keyof TEnum]> = never,
|
|
110
|
+
> = {
|
|
111
|
+
[K in TEnum[keyof TEnum]]: BuildStringKey<
|
|
112
|
+
K,
|
|
113
|
+
TPrefixes,
|
|
114
|
+
TTemplateKeys extends Set<K> ? true : false
|
|
115
|
+
> extends TStringKey
|
|
116
|
+
? BuildStringKey<K, TPrefixes, TTemplateKeys extends Set<K> ? true : false>
|
|
117
|
+
: never;
|
|
118
|
+
};
|
|
119
|
+
|
|
120
|
+
/**
|
|
121
|
+
* Builds a reason map from an enum object, mapping each enum value to a string key.
|
|
122
|
+
* @param enumObj - The enum object
|
|
123
|
+
* @param prefixes - Prefixes to prepend to each string key
|
|
124
|
+
* @param templateKeys - Optional set of enum values that should have 'Template' suffix for template processing
|
|
125
|
+
* @returns The constructed reason map
|
|
126
|
+
*/
|
|
127
|
+
export function buildReasonMap<
|
|
128
|
+
TEnum extends Record<string, string>,
|
|
129
|
+
TStringKey extends string,
|
|
130
|
+
>(
|
|
131
|
+
enumObj: TEnum,
|
|
132
|
+
prefixes: string[] = [],
|
|
133
|
+
templateKeys?: Set<TEnum[keyof TEnum]>,
|
|
134
|
+
): Record<TEnum[keyof TEnum], TStringKey> {
|
|
135
|
+
const map = {} as Record<TEnum[keyof TEnum], TStringKey>;
|
|
136
|
+
|
|
137
|
+
Object.values(enumObj).forEach((value) => {
|
|
138
|
+
const baseKey = [...prefixes, value].join('_');
|
|
139
|
+
const finalKey = templateKeys?.has(value as TEnum[keyof TEnum])
|
|
140
|
+
? baseKey + 'Template'
|
|
141
|
+
: baseKey;
|
|
142
|
+
map[value as TEnum[keyof TEnum]] = finalKey as TStringKey;
|
|
143
|
+
});
|
|
144
|
+
|
|
145
|
+
return map;
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
/**
|
|
149
|
+
* Type-safe version of buildReasonMap that ensures all enum values are mapped and all string keys exist
|
|
150
|
+
*/
|
|
151
|
+
export function buildTypeSafeReasonMap<
|
|
152
|
+
TEnum extends Record<string, string>,
|
|
153
|
+
TStringKey extends string,
|
|
154
|
+
TPrefixes extends readonly string[] = [],
|
|
155
|
+
TTemplateKeys extends Set<TEnum[keyof TEnum]> = never,
|
|
156
|
+
>(
|
|
157
|
+
enumObj: TEnum,
|
|
158
|
+
prefixes: TPrefixes,
|
|
159
|
+
templateKeys?: TTemplateKeys,
|
|
160
|
+
): ReasonMapFromEnum<TEnum, TStringKey, TPrefixes, TTemplateKeys> {
|
|
161
|
+
const map = {} as any;
|
|
162
|
+
|
|
163
|
+
Object.values(enumObj).forEach((value) => {
|
|
164
|
+
const baseKey = [...prefixes, value].join('_');
|
|
165
|
+
const finalKey = templateKeys?.has(value as TEnum[keyof TEnum])
|
|
166
|
+
? baseKey + 'Template'
|
|
167
|
+
: baseKey;
|
|
168
|
+
map[value as TEnum[keyof TEnum]] = finalKey;
|
|
169
|
+
});
|
|
170
|
+
|
|
171
|
+
return map;
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
/**
|
|
175
|
+
* Validates that a reason map has entries for all enum values
|
|
176
|
+
*/
|
|
177
|
+
export function validateReasonMap<
|
|
178
|
+
TEnum extends Record<string, string>,
|
|
179
|
+
TStringKey extends string,
|
|
180
|
+
>(
|
|
181
|
+
enumObj: TEnum,
|
|
182
|
+
reasonMap: Partial<Record<TEnum[keyof TEnum], TStringKey>>,
|
|
183
|
+
): reasonMap is Record<TEnum[keyof TEnum], TStringKey> {
|
|
184
|
+
return Object.values(enumObj).every(
|
|
185
|
+
(value) =>
|
|
186
|
+
value in reasonMap &&
|
|
187
|
+
reasonMap[value as TEnum[keyof TEnum]] !== undefined,
|
|
188
|
+
);
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
/**
|
|
192
|
+
* Creates a complete reason map ensuring all enum values are covered
|
|
193
|
+
*/
|
|
194
|
+
export function createCompleteReasonMap<
|
|
195
|
+
TEnum extends Record<string, string>,
|
|
196
|
+
TStringKey extends string,
|
|
197
|
+
>(
|
|
198
|
+
enumObj: TEnum,
|
|
199
|
+
prefixes: readonly string[] = [],
|
|
200
|
+
templateKeys?: Set<TEnum[keyof TEnum]>,
|
|
201
|
+
): Record<TEnum[keyof TEnum], TStringKey> {
|
|
202
|
+
const map = buildReasonMap(enumObj, [...prefixes], templateKeys) as Record<
|
|
203
|
+
TEnum[keyof TEnum],
|
|
204
|
+
TStringKey
|
|
205
|
+
>;
|
|
206
|
+
|
|
207
|
+
if (!validateReasonMap(enumObj, map)) {
|
|
208
|
+
const missing = Object.values(enumObj).filter((value) => !(value in map));
|
|
209
|
+
throw new Error(`Missing reason map entries for: ${missing.join(', ')}`);
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
return map;
|
|
213
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Configuration for component registration validation
|
|
3
|
+
*/
|
|
4
|
+
export interface ValidationConfig {
|
|
5
|
+
/** Whether to require all languages to have all strings */
|
|
6
|
+
readonly requireCompleteStrings: boolean;
|
|
7
|
+
/** Whether to allow registration with missing strings (will use fallbacks) */
|
|
8
|
+
readonly allowPartialRegistration: boolean;
|
|
9
|
+
/** Default language to fall back to for missing strings */
|
|
10
|
+
readonly fallbackLanguageId: string;
|
|
11
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Validation result for component registration
|
|
3
|
+
*/
|
|
4
|
+
export interface ValidationResult {
|
|
5
|
+
readonly isValid: boolean;
|
|
6
|
+
readonly missingKeys: ReadonlyArray<{
|
|
7
|
+
readonly languageId: string;
|
|
8
|
+
readonly componentId: string;
|
|
9
|
+
readonly stringKey: string;
|
|
10
|
+
}>;
|
|
11
|
+
readonly errors: readonly string[];
|
|
12
|
+
}
|
package/dist/active-context.d.ts
DELETED
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
import { CurrencyCode } from './currency-code';
|
|
2
|
-
import { Timezone } from './timezone';
|
|
3
|
-
import { LanguageContextSpace } from './types';
|
|
4
|
-
export interface IActiveContext<TLanguage extends string> {
|
|
5
|
-
/**
|
|
6
|
-
* The default language for the user facing application
|
|
7
|
-
*/
|
|
8
|
-
language: TLanguage;
|
|
9
|
-
/**
|
|
10
|
-
* The default language for the admin interface
|
|
11
|
-
*/
|
|
12
|
-
adminLanguage: TLanguage;
|
|
13
|
-
/**
|
|
14
|
-
* The default currency code for the user facing application
|
|
15
|
-
*/
|
|
16
|
-
currencyCode: CurrencyCode;
|
|
17
|
-
/**
|
|
18
|
-
* The default language context for the current context
|
|
19
|
-
*/
|
|
20
|
-
currentContext: LanguageContextSpace;
|
|
21
|
-
/**
|
|
22
|
-
* The default timezone for the user facing application
|
|
23
|
-
*/
|
|
24
|
-
timezone: Timezone;
|
|
25
|
-
/**
|
|
26
|
-
* The default timezone for the admin interface
|
|
27
|
-
*/
|
|
28
|
-
adminTimezone: Timezone;
|
|
29
|
-
}
|
package/dist/active-context.js
DELETED
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Component definition with its string keys
|
|
3
|
-
*/
|
|
4
|
-
export interface ComponentDefinition<TStringKeys extends string> {
|
|
5
|
-
/** Unique identifier for the component */
|
|
6
|
-
readonly id: string;
|
|
7
|
-
/** Human-readable name for the component */
|
|
8
|
-
readonly name: string;
|
|
9
|
-
/** Array of all string keys this component requires */
|
|
10
|
-
readonly stringKeys: readonly TStringKeys[];
|
|
11
|
-
}
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import { ComponentDefinition } from './component-definition';
|
|
2
|
-
import { PartialComponentLanguageStrings } from './types';
|
|
3
|
-
/**
|
|
4
|
-
* Registration payload for a component with its strings
|
|
5
|
-
*/
|
|
6
|
-
export interface ComponentRegistration<TStringKeys extends string, TLanguages extends string> {
|
|
7
|
-
readonly component: ComponentDefinition<TStringKeys>;
|
|
8
|
-
readonly strings: PartialComponentLanguageStrings<TStringKeys, TLanguages>;
|
|
9
|
-
}
|
|
@@ -1,68 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Component registry for managing internationalization components and their string translations
|
|
3
|
-
*/
|
|
4
|
-
import { ComponentDefinition } from './component-definition';
|
|
5
|
-
import { ComponentRegistration } from './component-registration';
|
|
6
|
-
import { TranslationRequest } from './translation-request';
|
|
7
|
-
import { TranslationResponse } from './translation-response';
|
|
8
|
-
import { ComponentLanguageStrings, PartialComponentLanguageStrings } from './types';
|
|
9
|
-
import { ValidationConfig } from './validation-config';
|
|
10
|
-
import { ValidationResult } from './validation-result';
|
|
11
|
-
/**
|
|
12
|
-
* Registry for managing components and their translations
|
|
13
|
-
*/
|
|
14
|
-
export declare class ComponentRegistry<TLanguages extends string> {
|
|
15
|
-
private readonly components;
|
|
16
|
-
private readonly componentStrings;
|
|
17
|
-
private readonly validationConfig;
|
|
18
|
-
private readonly registeredLanguages;
|
|
19
|
-
constructor(languages: readonly TLanguages[], validationConfig: ValidationConfig);
|
|
20
|
-
/**
|
|
21
|
-
* Update the set of registered languages (for dynamic language addition)
|
|
22
|
-
*/
|
|
23
|
-
updateRegisteredLanguages(languages: readonly TLanguages[]): void;
|
|
24
|
-
/**
|
|
25
|
-
* Register a new component with its translations
|
|
26
|
-
*/
|
|
27
|
-
registerComponent<TStringKeys extends string>(registration: ComponentRegistration<TStringKeys, TLanguages>): ValidationResult;
|
|
28
|
-
/**
|
|
29
|
-
* Update strings for an existing component
|
|
30
|
-
*/
|
|
31
|
-
updateComponentStrings<TStringKeys extends string>(componentId: string, strings: PartialComponentLanguageStrings<TStringKeys, TLanguages>): ValidationResult;
|
|
32
|
-
/**
|
|
33
|
-
* Get a translation for a specific component, string key, and language
|
|
34
|
-
*/
|
|
35
|
-
getTranslation<TStringKeys extends string>(request: TranslationRequest<TStringKeys, TLanguages>): TranslationResponse;
|
|
36
|
-
/**
|
|
37
|
-
* Get all registered components
|
|
38
|
-
*/
|
|
39
|
-
getComponents(): ReadonlyArray<ComponentDefinition<any>>;
|
|
40
|
-
/**
|
|
41
|
-
* Get a specific component by ID
|
|
42
|
-
*/
|
|
43
|
-
getComponent<TStringKeys extends string>(componentId: string): ComponentDefinition<TStringKeys> | undefined;
|
|
44
|
-
/**
|
|
45
|
-
* Check if a component is registered
|
|
46
|
-
*/
|
|
47
|
-
hasComponent(componentId: string): boolean;
|
|
48
|
-
/**
|
|
49
|
-
* Get all strings for a component in all languages
|
|
50
|
-
*/
|
|
51
|
-
getComponentStrings<TStringKeys extends string>(componentId: string): ComponentLanguageStrings<TStringKeys, TLanguages> | undefined;
|
|
52
|
-
/**
|
|
53
|
-
* Validate a component registration
|
|
54
|
-
*/
|
|
55
|
-
private validateComponentRegistration;
|
|
56
|
-
/**
|
|
57
|
-
* Complete missing strings with fallbacks
|
|
58
|
-
*/
|
|
59
|
-
private completeStringsWithFallbacks;
|
|
60
|
-
/**
|
|
61
|
-
* Merge existing strings with new strings
|
|
62
|
-
*/
|
|
63
|
-
private mergeStrings;
|
|
64
|
-
/**
|
|
65
|
-
* Clear all components and their strings (useful for testing)
|
|
66
|
-
*/
|
|
67
|
-
clearAllComponents(): void;
|
|
68
|
-
}
|