@digitaldefiance/i18n-lib 4.6.3 → 4.6.5
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
CHANGED
|
@@ -2065,6 +2065,57 @@ Contributions welcome! Please:
|
|
|
2065
2065
|
|
|
2066
2066
|
## ChangeLog
|
|
2067
2067
|
|
|
2068
|
+
### Version 4.6.4
|
|
2069
|
+
|
|
2070
|
+
- Dependency updates (branded-interface, noble/curves, noble/hashes)
|
|
2071
|
+
|
|
2072
|
+
### Version 4.6.3
|
|
2073
|
+
|
|
2074
|
+
**Branded Translation Options & Constants Schema**
|
|
2075
|
+
|
|
2076
|
+
- **NEW**: `createConstantsSchema()` — convenience wrapper for creating branded interface definitions for i18n constants validation
|
|
2077
|
+
- **NEW**: `BrandedTranslationOptions` — branded interface definition with runtime validation for translation option objects
|
|
2078
|
+
- **NEW**: `BrandedValidationErrorFormatter` — formats validation errors from branded interface parsing into human-readable messages with fallback chain support
|
|
2079
|
+
- Added `@digitaldefiance/branded-interface` dependency
|
|
2080
|
+
- Added `registerConstantsSchema()` and `getConstantsSchema()` to `ConstantsRegistry` for schema-aware constant registration
|
|
2081
|
+
- Comprehensive property-based tests for all new branded modules
|
|
2082
|
+
|
|
2083
|
+
### Version 4.6.2
|
|
2084
|
+
|
|
2085
|
+
**II18nConstants Interface & Constants Validation**
|
|
2086
|
+
|
|
2087
|
+
- **NEW**: `II18nConstants` interface — base interface for all i18n constants with index signature support
|
|
2088
|
+
- **NEW**: `ConstantKeys<T>` and `ConstantVariables<T>` utility types for type-safe constant access
|
|
2089
|
+
- **NEW**: `validateConstantsCoverage()` — test utility to verify all `{variable}` references in translation templates have corresponding constant keys
|
|
2090
|
+
- Updated `ConstantsRegistry` with improved conflict detection and error messages
|
|
2091
|
+
- Updated `createI18nSetup()` to accept constants registration in setup config
|
|
2092
|
+
- Added constants validation tests and `createI18nSetup` integration tests
|
|
2093
|
+
- Updated README with constants registration documentation
|
|
2094
|
+
|
|
2095
|
+
### Version 4.6.1
|
|
2096
|
+
|
|
2097
|
+
- Fixed constants merging in `I18nEngine`: registry constants now properly overlay config constants (app overrides win)
|
|
2098
|
+
|
|
2099
|
+
### Version 4.6.0
|
|
2100
|
+
|
|
2101
|
+
**Constants Registry**
|
|
2102
|
+
|
|
2103
|
+
- **NEW**: `ConstantsRegistry` — structured, namespaced constant registration with conflict detection and merged flat lookup for template variable replacement
|
|
2104
|
+
- **NEW**: `registerConstants()` / `getConstants()` / `getMergedConstants()` on `II18nEngine` for per-component constant management
|
|
2105
|
+
- **NEW**: `I18nSetupResult` interface for typed factory output
|
|
2106
|
+
- **NEW**: `I18nError` class for structured i18n error handling
|
|
2107
|
+
- Updated `createI18nSetup()` to return `I18nSetupResult` with engine and component references
|
|
2108
|
+
- Updated `I18nComponentPackage` interface with optional constants field
|
|
2109
|
+
- Updated README with Constants Registry documentation
|
|
2110
|
+
|
|
2111
|
+
### Version 4.5.0
|
|
2112
|
+
|
|
2113
|
+
**Cross-Module Enum Registration & Structural Fallback**
|
|
2114
|
+
|
|
2115
|
+
- `registerStringKeyEnum()` now accepts an optional explicit `componentId` parameter as an escape hatch for cross-module scenarios where Symbol-based branded enum detection fails
|
|
2116
|
+
- Enhanced `StringKeyEnumRegistry` with multi-step detection strategy: reference check → explicit componentId → branded enum detection → structural fallback
|
|
2117
|
+
- Added comprehensive cross-module tests: backward compatibility, fallback behavior, setup factory integration, structural fallback, and Symbol isolation
|
|
2118
|
+
|
|
2068
2119
|
### Version 4.4.0
|
|
2069
2120
|
|
|
2070
2121
|
**Factory-Based i18n Setup & Browser-Safe Fallback**
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@digitaldefiance/i18n-lib",
|
|
3
|
-
"version": "4.6.
|
|
3
|
+
"version": "4.6.5",
|
|
4
4
|
"description": "i18n library with enum translation support",
|
|
5
5
|
"homepage": "https://github.com/Digital-Defiance/i18n-lib",
|
|
6
6
|
"repository": {
|
|
@@ -50,10 +50,10 @@
|
|
|
50
50
|
"tslib": "^2.3.0"
|
|
51
51
|
},
|
|
52
52
|
"peerDependencies": {
|
|
53
|
-
"@digitaldefiance/branded-interface": "^0.0.
|
|
53
|
+
"@digitaldefiance/branded-interface": "^0.0.5"
|
|
54
54
|
},
|
|
55
55
|
"devDependencies": {
|
|
56
|
-
"@digitaldefiance/branded-interface": "^0.0.
|
|
56
|
+
"@digitaldefiance/branded-interface": "^0.0.5",
|
|
57
57
|
"@typescript-eslint/eslint-plugin": "^8.53.1",
|
|
58
58
|
"@typescript-eslint/parser": "^8.53.1",
|
|
59
59
|
"eslint-plugin-import": "^2.32.0",
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"component-store.d.ts","sourceRoot":"","sources":["../../../../../packages/digitaldefiance-i18n-lib/src/core/component-store.ts"],"names":[],"mappings":"AAAA;;GAEG;
|
|
1
|
+
{"version":3,"file":"component-store.d.ts","sourceRoot":"","sources":["../../../../../packages/digitaldefiance-i18n-lib/src/core/component-store.ts"],"names":[],"mappings":"AAAA;;GAEG;AAKH,OAAO,EAAE,eAAe,EAAE,gBAAgB,EAAE,MAAM,eAAe,CAAC;AAClE,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,wCAAwC,CAAC;AAQ7E;;GAEG;AACH,qBAAa,cAAc;IACzB,OAAO,CAAC,UAAU,CAAsC;IACxD,OAAO,CAAC,QAAQ,CAA6B;IAC7C,OAAO,CAAC,SAAS,CAAC,CAAiB;IAEnC;;;OAGG;gBACS,SAAS,CAAC,EAAE,cAAc;IAItC;;;;;OAKG;IACH,QAAQ,CAAC,MAAM,EAAE,eAAe,GAAG,gBAAgB;IAkBnD;;;;;;OAMG;IACH,MAAM,CACJ,WAAW,EAAE,MAAM,EACnB,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,GAC9C,gBAAgB;IAenB;;;;OAIG;IACH,GAAG,CAAC,WAAW,EAAE,MAAM,GAAG,OAAO;IAIjC;;;;;OAKG;IACH,GAAG,CAAC,WAAW,EAAE,MAAM,GAAG,eAAe;IASzC;;;OAGG;IACH,MAAM,IAAI,SAAS,eAAe,EAAE;IAIpC;;;;;;;;OAQG;IACH,SAAS,CACP,WAAW,EAAE,MAAM,EACnB,GAAG,EAAE,MAAM,EACX,SAAS,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,EAC/B,QAAQ,CAAC,EAAE,MAAM,GAChB,MAAM;IA+BT;;;;;;OAMG;IACH,OAAO,CAAC,iBAAiB;IAsBzB;;;;;;;OAOG;IACH,aAAa,CACX,WAAW,EAAE,MAAM,EACnB,GAAG,EAAE,MAAM,EACX,SAAS,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,EAC/B,QAAQ,CAAC,EAAE,MAAM,GAChB,MAAM;IAQT;;;;OAIG;IACH,OAAO,CAAC,QAAQ;IA6BhB;;;OAGG;IACH,YAAY,CAAC,SAAS,EAAE,cAAc,GAAG,IAAI;IAI7C;;OAEG;IACH,KAAK,IAAI,IAAI;CAId"}
|
|
@@ -6,9 +6,12 @@
|
|
|
6
6
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
7
|
exports.ComponentStore = void 0;
|
|
8
8
|
const i18n_error_1 = require("../errors/i18n-error");
|
|
9
|
+
const helpers_1 = require("../icu/helpers");
|
|
9
10
|
const language_plural_map_1 = require("../pluralization/language-plural-map");
|
|
10
11
|
const plural_types_1 = require("../types/plural-types");
|
|
11
12
|
const utils_1 = require("../utils");
|
|
13
|
+
/** Detect ICU MessageFormat patterns like {var, plural, ...} or {var, select, ...} */
|
|
14
|
+
const ICU_PATTERN = /\{[^,}]+,\s*(?:plural|select|selectordinal)\s*,/;
|
|
12
15
|
/**
|
|
13
16
|
* Class representing a storage for component configurations and translations.
|
|
14
17
|
*/
|
|
@@ -113,6 +116,17 @@ class ComponentStore {
|
|
|
113
116
|
}
|
|
114
117
|
// Resolve plural form if needed
|
|
115
118
|
const translation = this.resolvePluralForm(value, variables?.count, lang);
|
|
119
|
+
// If the resolved string contains ICU MessageFormat syntax (plural/select),
|
|
120
|
+
// format it with the ICU engine instead of simple variable replacement.
|
|
121
|
+
if (typeof translation === 'string' && ICU_PATTERN.test(translation)) {
|
|
122
|
+
try {
|
|
123
|
+
return (0, helpers_1.formatICUMessage)(translation, variables ?? {}, lang);
|
|
124
|
+
}
|
|
125
|
+
catch {
|
|
126
|
+
// Fall back to simple replacement if ICU parsing fails
|
|
127
|
+
return (0, utils_1.replaceVariables)(translation, variables, this.constants);
|
|
128
|
+
}
|
|
129
|
+
}
|
|
116
130
|
return (0, utils_1.replaceVariables)(translation, variables, this.constants);
|
|
117
131
|
}
|
|
118
132
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"component-store.js","sourceRoot":"","sources":["../../../../../packages/digitaldefiance-i18n-lib/src/core/component-store.ts"],"names":[],"mappings":";AAAA;;GAEG;AACH,2PAA2P;;;AAE3P,qDAAiD;
|
|
1
|
+
{"version":3,"file":"component-store.js","sourceRoot":"","sources":["../../../../../packages/digitaldefiance-i18n-lib/src/core/component-store.ts"],"names":[],"mappings":";AAAA;;GAEG;AACH,2PAA2P;;;AAE3P,qDAAiD;AACjD,4CAAkD;AAGlD,8EAAyE;AACzE,wDAA0E;AAC1E,oCAA4C;AAE5C,sFAAsF;AACtF,MAAM,WAAW,GAAG,iDAAiD,CAAC;AAEtE;;GAEG;AACH,MAAa,cAAc;IACjB,UAAU,GAAG,IAAI,GAAG,EAA2B,CAAC;IAChD,QAAQ,GAAG,IAAI,GAAG,EAAkB,CAAC;IACrC,SAAS,CAAkB;IAEnC;;;OAGG;IACH,YAAY,SAA0B;QACpC,IAAI,CAAC,SAAS,GAAG,SAAS,CAAC;IAC7B,CAAC;IAED;;;;;OAKG;IACH,QAAQ,CAAC,MAAuB;QAC9B,IAAI,IAAI,CAAC,U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