@digitaldefiance/i18n-lib 1.2.5 → 1.3.1

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.
@@ -7,7 +7,17 @@ import { CoreStringKey } from './core-string-key';
7
7
  import { LanguageCodes } from './language-codes';
8
8
  import { LanguageDefinition } from './language-definition';
9
9
  import { PluginI18nEngine } from './plugin-i18n-engine';
10
- export type CoreLanguageCode = typeof LanguageCodes.EN_US | typeof LanguageCodes.EN_GB | typeof LanguageCodes.FR | typeof LanguageCodes.ES | typeof LanguageCodes.DE | typeof LanguageCodes.ZH_CN | typeof LanguageCodes.JA | typeof LanguageCodes.UK;
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;
11
21
  /**
12
22
  * Create default language definitions
13
23
  */
@@ -20,24 +30,33 @@ export declare const CoreComponentDefinition: ComponentDefinition<CoreStringKey>
20
30
  /**
21
31
  * Core component strings for all default languages
22
32
  */
23
- export declare function createCoreComponentStrings(): import("./strict-types").CompleteComponentLanguageStrings<CoreStringKey, CoreLanguageCode>;
33
+ export declare function createCoreComponentStrings(): import("./strict-types").CompleteComponentLanguageStrings<CoreStringKey, string>;
24
34
  /**
25
35
  * Create core component registration
26
36
  */
27
- export declare function createCoreComponentRegistration(): ComponentRegistration<CoreStringKey, CoreLanguageCode>;
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[];
28
46
  /**
29
47
  * Create a pre-configured I18n engine with core components
48
+ * Returns engine with string type - use registry for language validation
30
49
  */
31
- export declare function createCoreI18nEngine(instanceKey?: string): PluginI18nEngine<CoreLanguageCode>;
50
+ export declare function createCoreI18nEngine(instanceKey?: string): PluginI18nEngine<string>;
32
51
  /**
33
52
  * Type alias for easier usage
34
53
  */
35
- export type CoreI18nEngine = PluginI18nEngine<CoreLanguageCode>;
54
+ export type CoreI18nEngine = PluginI18nEngine<string>;
36
55
  /**
37
56
  * Helper function to get core translation
38
57
  */
39
- export declare function getCoreTranslation(stringKey: CoreStringKey, variables?: Record<string, string | number>, language?: CoreLanguageCode, instanceKey?: string): string;
58
+ export declare function getCoreTranslation(stringKey: CoreStringKey, variables?: Record<string, string | number>, language?: string, instanceKey?: string): string;
40
59
  /**
41
60
  * Helper function to safely get core translation with fallback
42
61
  */
43
- export declare function safeCoreTranslation(stringKey: CoreStringKey, variables?: Record<string, string | number>, language?: CoreLanguageCode, instanceKey?: string): string;
62
+ export declare function safeCoreTranslation(stringKey: CoreStringKey, variables?: Record<string, string | number>, language?: string, instanceKey?: string): string;
package/dist/core-i18n.js CHANGED
@@ -7,6 +7,8 @@ exports.CoreComponentDefinition = exports.CoreI18nComponentId = void 0;
7
7
  exports.createDefaultLanguages = createDefaultLanguages;
8
8
  exports.createCoreComponentStrings = createCoreComponentStrings;
9
9
  exports.createCoreComponentRegistration = createCoreComponentRegistration;
10
+ exports.getCoreLanguageCodes = getCoreLanguageCodes;
11
+ exports.getCoreLanguageDefinitions = getCoreLanguageDefinitions;
10
12
  exports.createCoreI18nEngine = createCoreI18nEngine;
11
13
  exports.getCoreTranslation = getCoreTranslation;
12
14
  exports.safeCoreTranslation = safeCoreTranslation;
@@ -433,8 +435,21 @@ function createCoreComponentRegistration() {
433
435
  strings: createCoreComponentStrings(),
434
436
  };
435
437
  }
438
+ /**
439
+ * Get core language codes as array (for Mongoose enums, etc.)
440
+ */
441
+ function getCoreLanguageCodes() {
442
+ return Object.values(language_codes_1.LanguageCodes);
443
+ }
444
+ /**
445
+ * Get core language definitions
446
+ */
447
+ function getCoreLanguageDefinitions() {
448
+ return createDefaultLanguages();
449
+ }
436
450
  /**
437
451
  * Create a pre-configured I18n engine with core components
452
+ * Returns engine with string type - use registry for language validation
438
453
  */
439
454
  function createCoreI18nEngine(instanceKey = DefaultInstanceKey) {
440
455
  const languages = createDefaultLanguages();
@@ -1,4 +1,3 @@
1
- import { CoreLanguageCode } from './core-i18n';
2
1
  import { RegistryErrorType } from './registry-error-type';
3
2
  import { TranslationEngine } from './typed-error';
4
3
  /**
@@ -11,7 +10,7 @@ export declare class RegistryError extends Error {
11
10
  /**
12
11
  * Create a registry error with translation support
13
12
  */
14
- static createWithEngine(engine: TranslationEngine, type: RegistryErrorType, variables?: Record<string, string | number>, language?: CoreLanguageCode, metadata?: Record<string, any>): RegistryError;
13
+ static createWithEngine(engine: TranslationEngine, type: RegistryErrorType, variables?: Record<string, string | number>, language?: string, metadata?: Record<string, any>): RegistryError;
15
14
  /**
16
15
  * Create a simple RegistryError without engine dependency
17
16
  */
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.RegistryError = void 0;
4
+ // CoreLanguageCode is deprecated - using string
4
5
  const core_string_key_1 = require("./core-string-key");
5
6
  const registry_error_type_1 = require("./registry-error-type");
6
7
  const typed_error_1 = require("./typed-error");
@@ -1,6 +1,5 @@
1
1
  import { Language, StringKey } from './default-config';
2
2
  import { I18nEngine } from './i18n-engine';
3
- import { CoreLanguageCode } from './core-i18n';
4
3
  import { CoreStringKey } from './core-string-key';
5
4
  import { PluginI18nEngine } from './plugin-i18n-engine';
6
5
  import { TranslationEngine } from './translation-engine';
@@ -52,9 +51,9 @@ export declare abstract class PluginTypedError<TEnum extends Record<string, stri
52
51
  export declare abstract class CoreTypedError<TEnum extends Record<string, string>> extends Error {
53
52
  readonly type: TEnum[keyof TEnum];
54
53
  readonly reasonMap: CompleteReasonMap<TEnum, CoreStringKey>;
55
- readonly language?: CoreLanguageCode | undefined;
54
+ readonly language?: string | undefined;
56
55
  readonly otherVars?: Record<string, string | number> | undefined;
57
- constructor(engine: PluginI18nEngine<CoreLanguageCode>, type: TEnum[keyof TEnum], reasonMap: CompleteReasonMap<TEnum, CoreStringKey>, language?: CoreLanguageCode | undefined, otherVars?: Record<string, string | number> | undefined);
56
+ constructor(engine: PluginI18nEngine<string>, type: TEnum[keyof TEnum], reasonMap: CompleteReasonMap<TEnum, CoreStringKey>, language?: string | undefined, otherVars?: Record<string, string | number> | undefined);
58
57
  }
59
58
  /**
60
59
  * Helper function to create a plugin-based TypedError with automatic engine detection
@@ -63,7 +62,7 @@ export declare function createPluginTypedError<TEnum extends Record<string, stri
63
62
  /**
64
63
  * Helper function to create a core system TypedError with automatic engine detection
65
64
  */
66
- export declare function createCoreTypedError<TEnum extends Record<string, string>>(type: TEnum[keyof TEnum], reasonMap: CompleteReasonMap<TEnum, CoreStringKey>, otherVars?: Record<string, string | number>, language?: CoreLanguageCode, instanceKey?: string): Error;
65
+ export declare function createCoreTypedError<TEnum extends Record<string, string>>(type: TEnum[keyof TEnum], reasonMap: CompleteReasonMap<TEnum, CoreStringKey>, otherVars?: Record<string, string | number>, language?: string, instanceKey?: string): Error;
67
66
  /**
68
67
  * Create a simple error with translation support (generalized pattern from RegistryError)
69
68
  */
@@ -6,6 +6,8 @@ exports.createCoreTypedError = createCoreTypedError;
6
6
  exports.createTranslatedError = createTranslatedError;
7
7
  // Legacy imports (for backward compatibility)
8
8
  const default_config_1 = require("./default-config");
9
+ // New plugin architecture imports
10
+ // CoreLanguageCode is deprecated - using string for flexibility
9
11
  const core_string_key_1 = require("./core-string-key");
10
12
  const plugin_i18n_engine_1 = require("./plugin-i18n-engine");
11
13
  /**
@@ -187,7 +189,7 @@ class DatabaseError extends CoreTypedError<typeof DatabaseErrorType> {
187
189
  }
188
190
 
189
191
  // Usage:
190
- // const engine = PluginI18nEngine.getInstance<CoreLanguageCode>();
192
+ // const engine = PluginI18nEngine.getInstance<string>();
191
193
  // throw new DatabaseError(engine, DatabaseErrorType.ConnectionFailed);
192
194
  */
193
195
  // Example 2: Custom component error with custom strings
@@ -210,19 +212,19 @@ const userErrorReasonMap: CompleteReasonMap<typeof UserErrorType, UserErrorStrin
210
212
  [UserErrorType.AccountLocked]: UserErrorStringKey.AccountLockedMessage
211
213
  };
212
214
 
213
- class UserError extends PluginTypedError<typeof UserErrorType, UserErrorStringKey, CoreLanguageCode> {
215
+ class UserError extends PluginTypedError<typeof UserErrorType, UserErrorStringKey, string> {
214
216
  constructor(
215
- engine: PluginI18nEngine<CoreLanguageCode>,
217
+ engine: PluginI18nEngine<string>,
216
218
  type: UserErrorType,
217
219
  otherVars?: Record<string, string | number>,
218
- language?: CoreLanguage
220
+ language?: string
219
221
  ) {
220
222
  super(engine, 'user-system', type, userErrorReasonMap, language, otherVars);
221
223
  }
222
224
  }
223
225
 
224
226
  // Usage:
225
- // const engine = PluginI18nEngine.getInstance<CoreLanguageCode>();
227
+ // const engine = PluginI18nEngine.getInstance<string>();
226
228
  // throw new UserError(engine, UserErrorType.UserNotFound, { username: 'john_doe' });
227
229
  */
228
230
  // Example 3: Using helper functions for simpler error creation
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@digitaldefiance/i18n-lib",
3
- "version": "1.2.5",
3
+ "version": "1.3.1",
4
4
  "description": "Generic i18n library with enum translation support",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",