@digitaldefiance/i18n-lib 1.3.11 → 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.
Files changed (148) hide show
  1. package/README.md +8 -0
  2. package/package.json +12 -27
  3. package/src/active-context.ts +30 -0
  4. package/src/component-definition.ts +11 -0
  5. package/src/component-registration.ts +13 -0
  6. package/src/component-registry.ts +392 -0
  7. package/src/context-error-type.ts +3 -0
  8. package/src/context-error.ts +16 -0
  9. package/src/context-manager.ts +71 -0
  10. package/src/context.ts +90 -0
  11. package/src/core-i18n.ts +609 -0
  12. package/src/core-string-key.ts +49 -0
  13. package/src/create-translation-adapter.ts +47 -0
  14. package/src/currency-code.ts +35 -0
  15. package/{dist/currency-format.d.ts → src/currency-format.ts} +5 -4
  16. package/src/currency.ts +52 -0
  17. package/src/default-config.ts +199 -0
  18. package/src/enum-registry.ts +138 -0
  19. package/src/global-active-context.ts +255 -0
  20. package/src/handleable.ts +79 -0
  21. package/src/i-global-active-context.ts +59 -0
  22. package/src/i-handleable-error-options.ts +6 -0
  23. package/src/i-handleable.ts +5 -0
  24. package/src/i18n-config.ts +29 -0
  25. package/{dist/i18n-context.d.ts → src/i18n-context.ts} +7 -6
  26. package/src/i18n-engine.ts +491 -0
  27. package/{dist/index.d.ts → src/index.ts} +10 -1
  28. package/{dist/language-codes.d.ts → src/language-codes.ts} +23 -11
  29. package/src/language-definition.ts +13 -0
  30. package/src/language-registry.ts +292 -0
  31. package/src/plugin-i18n-engine.ts +520 -0
  32. package/src/plugin-translatable-generic-error.ts +106 -0
  33. package/src/plugin-translatable-handleable-generic.ts +60 -0
  34. package/src/plugin-typed-handleable.ts +77 -0
  35. package/src/registry-config.ts +15 -0
  36. package/src/registry-error-type.ts +12 -0
  37. package/src/registry-error.ts +74 -0
  38. package/src/strict-types.ts +35 -0
  39. package/src/template.ts +63 -0
  40. package/src/timezone.ts +20 -0
  41. package/src/translatable.ts +15 -0
  42. package/src/translation-engine.ts +8 -0
  43. package/src/translation-request.ts +12 -0
  44. package/src/translation-response.ts +8 -0
  45. package/src/typed-error.ts +384 -0
  46. package/src/typed-handleable.ts +70 -0
  47. package/{dist/types.d.ts → src/types.ts} +75 -20
  48. package/src/unified-translator.ts +96 -0
  49. package/src/utils.ts +213 -0
  50. package/src/validation-config.ts +11 -0
  51. package/src/validation-result.ts +12 -0
  52. package/dist/active-context.d.ts +0 -29
  53. package/dist/active-context.js +0 -2
  54. package/dist/component-definition.d.ts +0 -11
  55. package/dist/component-definition.js +0 -2
  56. package/dist/component-registration.d.ts +0 -9
  57. package/dist/component-registration.js +0 -2
  58. package/dist/component-registry.d.ts +0 -68
  59. package/dist/component-registry.js +0 -245
  60. package/dist/context-error-type.d.ts +0 -3
  61. package/dist/context-error-type.js +0 -7
  62. package/dist/context-error.d.ts +0 -6
  63. package/dist/context-error.js +0 -15
  64. package/dist/context-manager.d.ts +0 -33
  65. package/dist/context-manager.js +0 -61
  66. package/dist/context.d.ts +0 -44
  67. package/dist/context.js +0 -69
  68. package/dist/core-i18n.d.ts +0 -62
  69. package/dist/core-i18n.js +0 -477
  70. package/dist/core-string-key.d.ts +0 -42
  71. package/dist/core-string-key.js +0 -50
  72. package/dist/create-translation-adapter.d.ts +0 -20
  73. package/dist/create-translation-adapter.js +0 -36
  74. package/dist/currency-code.d.ts +0 -19
  75. package/dist/currency-code.js +0 -36
  76. package/dist/currency-format.js +0 -2
  77. package/dist/currency.d.ts +0 -11
  78. package/dist/currency.js +0 -48
  79. package/dist/default-config.d.ts +0 -32
  80. package/dist/default-config.js +0 -101
  81. package/dist/enum-registry.d.ts +0 -44
  82. package/dist/enum-registry.js +0 -100
  83. package/dist/global-active-context.d.ts +0 -50
  84. package/dist/global-active-context.js +0 -177
  85. package/dist/handleable.d.ts +0 -13
  86. package/dist/handleable.js +0 -56
  87. package/dist/i-global-active-context.d.ts +0 -22
  88. package/dist/i-global-active-context.js +0 -2
  89. package/dist/i-handleable-error-options.d.ts +0 -6
  90. package/dist/i-handleable-error-options.js +0 -2
  91. package/dist/i-handleable.d.ts +0 -5
  92. package/dist/i-handleable.js +0 -2
  93. package/dist/i18n-config.d.ts +0 -20
  94. package/dist/i18n-config.js +0 -2
  95. package/dist/i18n-context.js +0 -2
  96. package/dist/i18n-engine.d.ts +0 -178
  97. package/dist/i18n-engine.js +0 -338
  98. package/dist/index.js +0 -83
  99. package/dist/language-codes.js +0 -31
  100. package/dist/language-definition.d.ts +0 -13
  101. package/dist/language-definition.js +0 -2
  102. package/dist/language-registry.d.ts +0 -113
  103. package/dist/language-registry.js +0 -216
  104. package/dist/plugin-i18n-engine.d.ts +0 -146
  105. package/dist/plugin-i18n-engine.js +0 -360
  106. package/dist/plugin-translatable-generic-error.d.ts +0 -29
  107. package/dist/plugin-translatable-generic-error.js +0 -66
  108. package/dist/plugin-translatable-handleable-generic.d.ts +0 -28
  109. package/dist/plugin-translatable-handleable-generic.js +0 -40
  110. package/dist/plugin-typed-handleable.d.ts +0 -14
  111. package/dist/plugin-typed-handleable.js +0 -45
  112. package/dist/registry-config.d.ts +0 -14
  113. package/dist/registry-config.js +0 -2
  114. package/dist/registry-error-type.d.ts +0 -12
  115. package/dist/registry-error-type.js +0 -16
  116. package/dist/registry-error.d.ts +0 -18
  117. package/dist/registry-error.js +0 -45
  118. package/dist/strict-types.d.ts +0 -18
  119. package/dist/strict-types.js +0 -17
  120. package/dist/template.d.ts +0 -12
  121. package/dist/template.js +0 -30
  122. package/dist/timezone.d.ts +0 -11
  123. package/dist/timezone.js +0 -22
  124. package/dist/translatable-generic-error.d.ts +0 -29
  125. package/dist/translatable-generic-error.js +0 -66
  126. package/dist/translatable-handleable-generic.d.ts +0 -28
  127. package/dist/translatable-handleable-generic.js +0 -40
  128. package/dist/translatable.d.ts +0 -5
  129. package/dist/translatable.js +0 -11
  130. package/dist/translation-engine.d.ts +0 -8
  131. package/dist/translation-engine.js +0 -2
  132. package/dist/translation-request.d.ts +0 -9
  133. package/dist/translation-request.js +0 -2
  134. package/dist/translation-response.d.ts +0 -8
  135. package/dist/translation-response.js +0 -2
  136. package/dist/typed-error.d.ts +0 -72
  137. package/dist/typed-error.js +0 -251
  138. package/dist/typed-handleable.d.ts +0 -14
  139. package/dist/typed-handleable.js +0 -40
  140. package/dist/types.js +0 -18
  141. package/dist/unified-translator.d.ts +0 -30
  142. package/dist/unified-translator.js +0 -68
  143. package/dist/utils.d.ts +0 -64
  144. package/dist/utils.js +0 -130
  145. package/dist/validation-config.d.ts +0 -11
  146. package/dist/validation-config.js +0 -2
  147. package/dist/validation-result.d.ts +0 -12
  148. package/dist/validation-result.js +0 -2
@@ -1,245 +0,0 @@
1
- "use strict";
2
- /**
3
- * Component registry for managing internationalization components and their string translations
4
- */
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.ComponentRegistry = void 0;
7
- const registry_error_1 = require("./registry-error");
8
- const registry_error_type_1 = require("./registry-error-type");
9
- const utils_1 = require("./utils");
10
- /**
11
- * Registry for managing components and their translations
12
- */
13
- class ComponentRegistry {
14
- constructor(languages, validationConfig) {
15
- this.components = new Map();
16
- this.componentStrings = new Map();
17
- this.registeredLanguages = new Set(languages);
18
- this.validationConfig = validationConfig;
19
- }
20
- /**
21
- * Update the set of registered languages (for dynamic language addition)
22
- */
23
- updateRegisteredLanguages(languages) {
24
- this.registeredLanguages.clear();
25
- languages.forEach((lang) => this.registeredLanguages.add(lang));
26
- }
27
- /**
28
- * Register a new component with its translations
29
- */
30
- registerComponent(registration) {
31
- const { component, strings } = registration;
32
- // Check for duplicate component
33
- if (this.components.has(component.id)) {
34
- throw registry_error_1.RegistryError.createSimple(registry_error_type_1.RegistryErrorType.DuplicateComponent, `Component '${component.id}' is already registered`, { componentId: component.id });
35
- }
36
- // Validate the registration
37
- const validationResult = this.validateComponentRegistration(registration);
38
- if (!validationResult.isValid &&
39
- !this.validationConfig.allowPartialRegistration) {
40
- throw registry_error_1.RegistryError.createSimple(registry_error_type_1.RegistryErrorType.ValidationFailed, `Component registration validation failed: ${validationResult.errors.join(', ')}`, {
41
- componentId: component.id,
42
- missingKeys: validationResult.missingKeys,
43
- errors: validationResult.errors,
44
- });
45
- }
46
- // Complete missing strings with fallbacks if partial registration is allowed
47
- const completeStrings = this.completeStringsWithFallbacks(component, strings);
48
- // Register the component
49
- this.components.set(component.id, component);
50
- this.componentStrings.set(component.id, completeStrings);
51
- return validationResult;
52
- }
53
- /**
54
- * Update strings for an existing component
55
- */
56
- updateComponentStrings(componentId, strings) {
57
- const component = this.components.get(componentId);
58
- if (!component) {
59
- throw registry_error_1.RegistryError.createSimple(registry_error_type_1.RegistryErrorType.ComponentNotFound, `Component with ID '${componentId}' not found`, { componentId });
60
- }
61
- const registration = {
62
- component: component,
63
- strings,
64
- };
65
- const validationResult = this.validateComponentRegistration(registration);
66
- if (validationResult.isValid ||
67
- this.validationConfig.allowPartialRegistration) {
68
- const existingStrings = this.componentStrings.get(componentId) ||
69
- {};
70
- const updatedStrings = this.mergeStrings(existingStrings, strings);
71
- const completeStrings = this.completeStringsWithFallbacks(component, updatedStrings);
72
- this.componentStrings.set(componentId, completeStrings);
73
- }
74
- return validationResult;
75
- }
76
- /**
77
- * Get a translation for a specific component, string key, and language
78
- */
79
- getTranslation(request) {
80
- const { componentId, stringKey, language, variables } = request;
81
- // Check if component exists
82
- if (!this.components.has(componentId)) {
83
- throw registry_error_1.RegistryError.createSimple(registry_error_type_1.RegistryErrorType.ComponentNotFound, `Component '${componentId}' not found`, { componentId });
84
- }
85
- const componentStrings = this.componentStrings.get(componentId);
86
- if (!componentStrings) {
87
- throw registry_error_1.RegistryError.createSimple(registry_error_type_1.RegistryErrorType.StringKeyNotFound, `No strings registered for component '${componentId}'`, { componentId });
88
- }
89
- const targetLanguage = language || this.validationConfig.fallbackLanguageId;
90
- let actualLanguage = targetLanguage;
91
- let wasFallback = false;
92
- // Try to get the string in the requested language
93
- let languageStrings = componentStrings[targetLanguage];
94
- // If not found and different from fallback, try fallback language
95
- if (!languageStrings &&
96
- targetLanguage !== this.validationConfig.fallbackLanguageId) {
97
- languageStrings =
98
- componentStrings[this.validationConfig.fallbackLanguageId];
99
- actualLanguage = this.validationConfig.fallbackLanguageId;
100
- wasFallback = true;
101
- }
102
- if (!languageStrings) {
103
- throw registry_error_1.RegistryError.createSimple(registry_error_type_1.RegistryErrorType.LanguageNotFound, `No strings found for language '${targetLanguage}' in component '${componentId}'`, { componentId, language: targetLanguage });
104
- }
105
- const translation = languageStrings[stringKey];
106
- if (!translation) {
107
- throw registry_error_1.RegistryError.createSimple(registry_error_type_1.RegistryErrorType.StringKeyNotFound, `String key '${stringKey}' not found for component '${componentId}' in language '${actualLanguage}'`, { componentId, stringKey, language: actualLanguage });
108
- }
109
- // Process variables if the string key indicates it's a template
110
- let processedTranslation = translation;
111
- if (variables && (0, utils_1.isTemplate)(stringKey)) {
112
- processedTranslation = (0, utils_1.replaceVariables)(translation, variables);
113
- }
114
- return {
115
- translation: processedTranslation,
116
- actualLanguage,
117
- wasFallback,
118
- };
119
- }
120
- /**
121
- * Get all registered components
122
- */
123
- getComponents() {
124
- return Array.from(this.components.values());
125
- }
126
- /**
127
- * Get a specific component by ID
128
- */
129
- getComponent(componentId) {
130
- return this.components.get(componentId);
131
- }
132
- /**
133
- * Check if a component is registered
134
- */
135
- hasComponent(componentId) {
136
- return this.components.has(componentId);
137
- }
138
- /**
139
- * Get all strings for a component in all languages
140
- */
141
- getComponentStrings(componentId) {
142
- return this.componentStrings.get(componentId);
143
- }
144
- /**
145
- * Validate a component registration
146
- */
147
- validateComponentRegistration(registration) {
148
- const { component, strings } = registration;
149
- const missingKeys = [];
150
- const errors = [];
151
- // Check if all required string keys are provided for each language
152
- for (const languageId of this.registeredLanguages) {
153
- const languageStrings = strings[languageId];
154
- if (!languageStrings) {
155
- if (this.validationConfig.requireCompleteStrings) {
156
- errors.push(`Missing all strings for language '${languageId}' in component '${component.id}'`);
157
- }
158
- // Add all missing keys for this language
159
- for (const stringKey of component.stringKeys) {
160
- missingKeys.push({
161
- languageId,
162
- componentId: component.id,
163
- stringKey,
164
- });
165
- }
166
- continue;
167
- }
168
- // Check individual string keys
169
- for (const stringKey of component.stringKeys) {
170
- if (!languageStrings[stringKey]) {
171
- missingKeys.push({
172
- languageId,
173
- componentId: component.id,
174
- stringKey,
175
- });
176
- if (this.validationConfig.requireCompleteStrings) {
177
- errors.push(`Missing string key '${stringKey}' for language '${languageId}' in component '${component.id}'`);
178
- }
179
- }
180
- }
181
- }
182
- return {
183
- isValid: missingKeys.length === 0,
184
- missingKeys,
185
- errors,
186
- };
187
- }
188
- /**
189
- * Complete missing strings with fallbacks
190
- */
191
- completeStringsWithFallbacks(component, strings) {
192
- const result = {};
193
- const fallbackLanguage = this.validationConfig
194
- .fallbackLanguageId;
195
- const fallbackStrings = strings[fallbackLanguage];
196
- // Ensure all languages have all required keys
197
- for (const languageId of this.registeredLanguages) {
198
- const existingLanguageStrings = strings[languageId] || {};
199
- const languageStrings = {};
200
- for (const stringKey of component.stringKeys) {
201
- if (existingLanguageStrings[stringKey]) {
202
- languageStrings[stringKey] = existingLanguageStrings[stringKey];
203
- }
204
- else if (fallbackStrings && fallbackStrings[stringKey]) {
205
- // Try to use fallback language
206
- languageStrings[stringKey] = fallbackStrings[stringKey];
207
- }
208
- else {
209
- // Last resort: use a placeholder
210
- languageStrings[stringKey] = `[${component.id}.${stringKey}]`;
211
- }
212
- }
213
- result[languageId] = languageStrings;
214
- }
215
- return result;
216
- }
217
- /**
218
- * Merge existing strings with new strings
219
- */
220
- mergeStrings(existing, updates) {
221
- const result = {};
222
- // Copy existing strings
223
- for (const [languageId, languageStrings] of Object.entries(existing)) {
224
- result[languageId] = { ...languageStrings };
225
- }
226
- // Apply updates
227
- for (const [languageId, languageStrings] of Object.entries(updates)) {
228
- if (languageStrings) {
229
- result[languageId] = {
230
- ...result[languageId],
231
- ...languageStrings,
232
- };
233
- }
234
- }
235
- return result;
236
- }
237
- /**
238
- * Clear all components and their strings (useful for testing)
239
- */
240
- clearAllComponents() {
241
- this.components.clear();
242
- this.componentStrings.clear();
243
- }
244
- }
245
- exports.ComponentRegistry = ComponentRegistry;
@@ -1,3 +0,0 @@
1
- export declare enum ContextErrorType {
2
- InvalidContext = "InvalidContext"
3
- }
@@ -1,7 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.ContextErrorType = void 0;
4
- var ContextErrorType;
5
- (function (ContextErrorType) {
6
- ContextErrorType["InvalidContext"] = "InvalidContext";
7
- })(ContextErrorType || (exports.ContextErrorType = ContextErrorType = {}));
@@ -1,6 +0,0 @@
1
- import { ContextErrorType } from './context-error-type';
2
- export declare class ContextError extends Error {
3
- readonly type: ContextErrorType;
4
- readonly contextKey?: string;
5
- constructor(type: ContextErrorType, contextKey?: string);
6
- }
@@ -1,15 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.ContextError = void 0;
4
- class ContextError extends Error {
5
- constructor(type, contextKey) {
6
- const message = contextKey
7
- ? `Invalid context: ${contextKey}`
8
- : 'Invalid context';
9
- super(message);
10
- this.name = 'ContextError';
11
- this.type = type;
12
- this.contextKey = contextKey;
13
- }
14
- }
15
- exports.ContextError = ContextError;
@@ -1,33 +0,0 @@
1
- /**
2
- * Context change management for i18n systems
3
- */
4
- export type ContextChangeListener<T = any> = (property: string, oldValue: T, newValue: T) => void;
5
- /**
6
- * Manages context changes and notifies listeners.
7
- */
8
- export declare class ContextManager<TContext extends Record<string, any>> {
9
- protected listeners: ContextChangeListener[];
10
- /**
11
- * Adds a listener to be notified of context changes.
12
- * @param listener - The listener function to add
13
- */
14
- addListener(listener: ContextChangeListener): void;
15
- /**
16
- * Removes a listener from the notification list.
17
- * @param listener - The listener function to remove
18
- */
19
- removeListener(listener: ContextChangeListener): void;
20
- /**
21
- * Notifies all listeners of a context change.
22
- * @param property - The property that changed
23
- * @param oldValue - The old value of the property
24
- * @param newValue - The new value of the property
25
- */
26
- notifyChange<K extends keyof TContext>(property: K, oldValue: TContext[K], newValue: TContext[K]): void;
27
- /**
28
- * Creates a proxy for the given context to automatically notify listeners on changes.
29
- * @param context - The context object to proxy
30
- * @returns A proxied version of the context object
31
- */
32
- createProxy(context: TContext): TContext;
33
- }
@@ -1,61 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.ContextManager = void 0;
4
- /**
5
- * Manages context changes and notifies listeners.
6
- */
7
- class ContextManager {
8
- constructor() {
9
- this.listeners = [];
10
- }
11
- /**
12
- * Adds a listener to be notified of context changes.
13
- * @param listener - The listener function to add
14
- */
15
- addListener(listener) {
16
- this.listeners.push(listener);
17
- }
18
- /**
19
- * Removes a listener from the notification list.
20
- * @param listener - The listener function to remove
21
- */
22
- removeListener(listener) {
23
- const index = this.listeners.indexOf(listener);
24
- if (index > -1) {
25
- this.listeners.splice(index, 1);
26
- }
27
- }
28
- /**
29
- * Notifies all listeners of a context change.
30
- * @param property - The property that changed
31
- * @param oldValue - The old value of the property
32
- * @param newValue - The new value of the property
33
- */
34
- notifyChange(property, oldValue, newValue) {
35
- this.listeners.forEach((listener) => {
36
- try {
37
- listener(property, oldValue, newValue);
38
- }
39
- catch (error) {
40
- console.error('Error in context change listener:', error);
41
- }
42
- });
43
- }
44
- /**
45
- * Creates a proxy for the given context to automatically notify listeners on changes.
46
- * @param context - The context object to proxy
47
- * @returns A proxied version of the context object
48
- */
49
- createProxy(context) {
50
- const manager = this;
51
- return new Proxy(context, {
52
- set(target, property, value) {
53
- const oldValue = target[property];
54
- target[property] = value;
55
- manager.notifyChange(property, oldValue, value);
56
- return true;
57
- },
58
- });
59
- }
60
- }
61
- exports.ContextManager = ContextManager;
package/dist/context.d.ts DELETED
@@ -1,44 +0,0 @@
1
- import { CurrencyCode } from './currency-code';
2
- import { I18nContext } from './i18n-context';
3
- import { Timezone } from './timezone';
4
- import { LanguageContextSpace } from './types';
5
- /**
6
- * Creates a new I18n context with default values.
7
- * @param defaultLanguage - The default language for the context
8
- * @param defaultContext - The default language context
9
- * @param defaultCurrencyCode - The default currency code (defaults to USD)
10
- * @param defaultTimezone - The default timezone (defaults to UTC)
11
- * @param defaultAdminTimezone - The default admin timezone (defaults to UTC)
12
- * @returns A new I18nContext instance
13
- */
14
- export declare function createContext<TLanguage extends string>(defaultLanguage: TLanguage, defaultContext?: LanguageContextSpace, defaultCurrencyCode?: CurrencyCode, defaultTimezone?: Timezone, defaultAdminTimezone?: Timezone): I18nContext<TLanguage>;
15
- /**
16
- * Sets the language for the given I18n context.
17
- * @param context - The I18n context to modify
18
- * @param language - The language to set
19
- */
20
- export declare function setLanguage<TLanguage extends string>(context: I18nContext<TLanguage>, language: TLanguage): void;
21
- /**
22
- * Sets the admin language for the given I18n context.
23
- * @param context - The I18n context to modify
24
- * @param language - The admin language to set
25
- */
26
- export declare function setAdminLanguage<TLanguage extends string>(context: I18nContext<TLanguage>, language: TLanguage): void;
27
- /**
28
- * Sets the current context for the given I18n context.
29
- * @param context - The I18n context to modify
30
- * @param languageContext - The language context to set
31
- */
32
- export declare function setContext<TLanguage extends string>(context: I18nContext<TLanguage>, languageContext: LanguageContextSpace): void;
33
- /**
34
- * Sets the timezone for the given I18n context.
35
- * @param context - The I18n context to modify
36
- * @param timezone - The timezone to set
37
- */
38
- export declare function setTimezone<TLanguage extends string>(context: I18nContext<TLanguage>, timezone: Timezone): void;
39
- /**
40
- * Sets the admin timezone for the given I18n context.
41
- * @param context - The I18n context to modify
42
- * @param timezone - The admin timezone to set
43
- */
44
- export declare function setAdminTimezone<TLanguage extends string>(context: I18nContext<TLanguage>, timezone: Timezone): void;
package/dist/context.js DELETED
@@ -1,69 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.createContext = createContext;
4
- exports.setLanguage = setLanguage;
5
- exports.setAdminLanguage = setAdminLanguage;
6
- exports.setContext = setContext;
7
- exports.setTimezone = setTimezone;
8
- exports.setAdminTimezone = setAdminTimezone;
9
- const currency_code_1 = require("./currency-code");
10
- const timezone_1 = require("./timezone");
11
- /**
12
- * Creates a new I18n context with default values.
13
- * @param defaultLanguage - The default language for the context
14
- * @param defaultContext - The default language context
15
- * @param defaultCurrencyCode - The default currency code (defaults to USD)
16
- * @param defaultTimezone - The default timezone (defaults to UTC)
17
- * @param defaultAdminTimezone - The default admin timezone (defaults to UTC)
18
- * @returns A new I18nContext instance
19
- */
20
- function createContext(defaultLanguage, defaultContext = 'admin', defaultCurrencyCode = new currency_code_1.CurrencyCode('USD'), defaultTimezone = new timezone_1.Timezone('UTC'), defaultAdminTimezone = new timezone_1.Timezone('UTC')) {
21
- return {
22
- language: defaultLanguage,
23
- adminLanguage: defaultLanguage,
24
- currencyCode: defaultCurrencyCode,
25
- currentContext: defaultContext,
26
- timezone: defaultTimezone,
27
- adminTimezone: defaultAdminTimezone,
28
- };
29
- }
30
- /**
31
- * Sets the language for the given I18n context.
32
- * @param context - The I18n context to modify
33
- * @param language - The language to set
34
- */
35
- function setLanguage(context, language) {
36
- context.language = language;
37
- }
38
- /**
39
- * Sets the admin language for the given I18n context.
40
- * @param context - The I18n context to modify
41
- * @param language - The admin language to set
42
- */
43
- function setAdminLanguage(context, language) {
44
- context.adminLanguage = language;
45
- }
46
- /**
47
- * Sets the current context for the given I18n context.
48
- * @param context - The I18n context to modify
49
- * @param languageContext - The language context to set
50
- */
51
- function setContext(context, languageContext) {
52
- context.currentContext = languageContext;
53
- }
54
- /**
55
- * Sets the timezone for the given I18n context.
56
- * @param context - The I18n context to modify
57
- * @param timezone - The timezone to set
58
- */
59
- function setTimezone(context, timezone) {
60
- context.timezone = timezone;
61
- }
62
- /**
63
- * Sets the admin timezone for the given I18n context.
64
- * @param context - The I18n context to modify
65
- * @param timezone - The admin timezone to set
66
- */
67
- function setAdminTimezone(context, timezone) {
68
- context.adminTimezone = timezone;
69
- }
@@ -1,62 +0,0 @@
1
- /**
2
- * Core I18n component with default languages and system strings
3
- */
4
- import { ComponentDefinition } from './component-definition';
5
- import { ComponentRegistration } from './component-registration';
6
- import { CoreStringKey } from './core-string-key';
7
- import { LanguageCodes } from './language-codes';
8
- import { LanguageDefinition } from './language-definition';
9
- import { PluginI18nEngine } from './plugin-i18n-engine';
10
- /**
11
- * Core language code type - union of supported language codes
12
- * Provides compile-time type safety for core languages
13
- * For custom languages, extend this type or use string
14
- */
15
- export type CoreLanguageCode = typeof LanguageCodes[keyof typeof LanguageCodes];
16
- /**
17
- * Flexible language code type - use when you want runtime-only validation
18
- * Alias for string to indicate it's a language code
19
- */
20
- export type FlexibleLanguageCode = string;
21
- /**
22
- * Create default language definitions
23
- */
24
- export declare function createDefaultLanguages(): LanguageDefinition[];
25
- export declare const CoreI18nComponentId = "core";
26
- /**
27
- * Core component definition
28
- */
29
- export declare const CoreComponentDefinition: ComponentDefinition<CoreStringKey>;
30
- /**
31
- * Core component strings for all default languages
32
- */
33
- export declare function createCoreComponentStrings(): import("./strict-types").CompleteComponentLanguageStrings<CoreStringKey, string>;
34
- /**
35
- * Create core component registration
36
- */
37
- export declare function createCoreComponentRegistration(): ComponentRegistration<CoreStringKey, string>;
38
- /**
39
- * Get core language codes as array (for Mongoose enums, etc.)
40
- */
41
- export declare function getCoreLanguageCodes(): string[];
42
- /**
43
- * Get core language definitions
44
- */
45
- export declare function getCoreLanguageDefinitions(): LanguageDefinition[];
46
- /**
47
- * Create a pre-configured I18n engine with core components
48
- * Returns engine with string type - use registry for language validation
49
- */
50
- export declare function createCoreI18nEngine(instanceKey?: string): PluginI18nEngine<string>;
51
- /**
52
- * Type alias for easier usage
53
- */
54
- export type CoreI18nEngine = PluginI18nEngine<string>;
55
- /**
56
- * Helper function to get core translation
57
- */
58
- export declare function getCoreTranslation(stringKey: CoreStringKey, variables?: Record<string, string | number>, language?: string, instanceKey?: string): string;
59
- /**
60
- * Helper function to safely get core translation with fallback
61
- */
62
- export declare function safeCoreTranslation(stringKey: CoreStringKey, variables?: Record<string, string | number>, language?: string, instanceKey?: string): string;