@digitaldefiance/i18n-lib 1.3.0 → 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.
- package/README.md +7 -7
- package/dist/core-i18n.d.ts +15 -8
- package/dist/core-i18n.js +1 -0
- package/dist/registry-error.d.ts +1 -2
- package/dist/registry-error.js +1 -0
- package/dist/typed-error.d.ts +3 -4
- package/dist/typed-error.js +7 -5
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -2215,16 +2215,16 @@ For issues, questions, or contributions:
|
|
|
2215
2215
|
|
|
2216
2216
|
## ChangeLog
|
|
2217
2217
|
|
|
2218
|
-
### Version 1.3.
|
|
2218
|
+
### Version 1.3.1
|
|
2219
2219
|
|
|
2220
|
-
- **Changed**: `CoreLanguageCode` now
|
|
2221
|
-
-
|
|
2222
|
-
-
|
|
2223
|
-
-
|
|
2220
|
+
- **Changed**: `CoreLanguageCode` is now `string` - Language Registry is single source of truth
|
|
2221
|
+
- Use `engine.getLanguageRegistry().getLanguageIds()` for runtime validation
|
|
2222
|
+
- Use `getCoreLanguageCodes()` for static arrays (Mongoose schemas, etc.)
|
|
2223
|
+
- Runtime validation via registry, not compile-time types
|
|
2224
2224
|
- **Added**: `getCoreLanguageCodes()` - Get core language codes as runtime array
|
|
2225
2225
|
- **Added**: `getCoreLanguageDefinitions()` - Get core language definitions
|
|
2226
|
-
- **
|
|
2227
|
-
- **Benefit**:
|
|
2226
|
+
- **Philosophy**: Registry-based validation over hardcoded types
|
|
2227
|
+
- **Benefit**: Maximum flexibility - add languages without code changes
|
|
2228
2228
|
|
|
2229
2229
|
### Version 1.2.5
|
|
2230
2230
|
|
package/dist/core-i18n.d.ts
CHANGED
|
@@ -8,10 +8,16 @@ import { LanguageCodes } from './language-codes';
|
|
|
8
8
|
import { LanguageDefinition } from './language-definition';
|
|
9
9
|
import { PluginI18nEngine } from './plugin-i18n-engine';
|
|
10
10
|
/**
|
|
11
|
-
* Core language code type -
|
|
12
|
-
*
|
|
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
|
|
13
14
|
*/
|
|
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;
|
|
15
21
|
/**
|
|
16
22
|
* Create default language definitions
|
|
17
23
|
*/
|
|
@@ -24,11 +30,11 @@ export declare const CoreComponentDefinition: ComponentDefinition<CoreStringKey>
|
|
|
24
30
|
/**
|
|
25
31
|
* Core component strings for all default languages
|
|
26
32
|
*/
|
|
27
|
-
export declare function createCoreComponentStrings(): import("./strict-types").CompleteComponentLanguageStrings<CoreStringKey,
|
|
33
|
+
export declare function createCoreComponentStrings(): import("./strict-types").CompleteComponentLanguageStrings<CoreStringKey, string>;
|
|
28
34
|
/**
|
|
29
35
|
* Create core component registration
|
|
30
36
|
*/
|
|
31
|
-
export declare function createCoreComponentRegistration(): ComponentRegistration<CoreStringKey,
|
|
37
|
+
export declare function createCoreComponentRegistration(): ComponentRegistration<CoreStringKey, string>;
|
|
32
38
|
/**
|
|
33
39
|
* Get core language codes as array (for Mongoose enums, etc.)
|
|
34
40
|
*/
|
|
@@ -39,17 +45,18 @@ export declare function getCoreLanguageCodes(): string[];
|
|
|
39
45
|
export declare function getCoreLanguageDefinitions(): LanguageDefinition[];
|
|
40
46
|
/**
|
|
41
47
|
* Create a pre-configured I18n engine with core components
|
|
48
|
+
* Returns engine with string type - use registry for language validation
|
|
42
49
|
*/
|
|
43
|
-
export declare function createCoreI18nEngine(instanceKey?: string): PluginI18nEngine<
|
|
50
|
+
export declare function createCoreI18nEngine(instanceKey?: string): PluginI18nEngine<string>;
|
|
44
51
|
/**
|
|
45
52
|
* Type alias for easier usage
|
|
46
53
|
*/
|
|
47
|
-
export type CoreI18nEngine = PluginI18nEngine<
|
|
54
|
+
export type CoreI18nEngine = PluginI18nEngine<string>;
|
|
48
55
|
/**
|
|
49
56
|
* Helper function to get core translation
|
|
50
57
|
*/
|
|
51
|
-
export declare function getCoreTranslation(stringKey: CoreStringKey, variables?: Record<string, string | number>, language?:
|
|
58
|
+
export declare function getCoreTranslation(stringKey: CoreStringKey, variables?: Record<string, string | number>, language?: string, instanceKey?: string): string;
|
|
52
59
|
/**
|
|
53
60
|
* Helper function to safely get core translation with fallback
|
|
54
61
|
*/
|
|
55
|
-
export declare function safeCoreTranslation(stringKey: CoreStringKey, variables?: Record<string, string | number>, language?:
|
|
62
|
+
export declare function safeCoreTranslation(stringKey: CoreStringKey, variables?: Record<string, string | number>, language?: string, instanceKey?: string): string;
|
package/dist/core-i18n.js
CHANGED
|
@@ -449,6 +449,7 @@ function getCoreLanguageDefinitions() {
|
|
|
449
449
|
}
|
|
450
450
|
/**
|
|
451
451
|
* Create a pre-configured I18n engine with core components
|
|
452
|
+
* Returns engine with string type - use registry for language validation
|
|
452
453
|
*/
|
|
453
454
|
function createCoreI18nEngine(instanceKey = DefaultInstanceKey) {
|
|
454
455
|
const languages = createDefaultLanguages();
|
package/dist/registry-error.d.ts
CHANGED
|
@@ -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?:
|
|
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
|
*/
|
package/dist/registry-error.js
CHANGED
|
@@ -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");
|
package/dist/typed-error.d.ts
CHANGED
|
@@ -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?:
|
|
54
|
+
readonly language?: string | undefined;
|
|
56
55
|
readonly otherVars?: Record<string, string | number> | undefined;
|
|
57
|
-
constructor(engine: PluginI18nEngine<
|
|
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?:
|
|
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
|
*/
|
package/dist/typed-error.js
CHANGED
|
@@ -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<
|
|
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,
|
|
215
|
+
class UserError extends PluginTypedError<typeof UserErrorType, UserErrorStringKey, string> {
|
|
214
216
|
constructor(
|
|
215
|
-
engine: PluginI18nEngine<
|
|
217
|
+
engine: PluginI18nEngine<string>,
|
|
216
218
|
type: UserErrorType,
|
|
217
219
|
otherVars?: Record<string, string | number>,
|
|
218
|
-
language?:
|
|
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<
|
|
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
|