@digitaldefiance/express-suite-starter 2.4.4 → 2.4.6
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.
|
@@ -1,12 +1,41 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Express Suite Starter i18n Setup
|
|
3
|
+
* Uses I18nBuilder pattern for proper engine initialization.
|
|
4
|
+
* Supports translateStringKey for direct branded enum translation.
|
|
5
|
+
*/
|
|
1
6
|
import { I18nEngine } from '@digitaldefiance/i18n-lib';
|
|
2
7
|
import type { ComponentConfig, EngineConfig } from '@digitaldefiance/i18n-lib';
|
|
3
8
|
import { StarterStringKey } from './starter-string-key';
|
|
9
|
+
import { type StarterStringKeyValue } from './branded-starter-string-key';
|
|
4
10
|
export declare const StarterI18nEngineKey: "DigitalDefiance.Starter.I18nEngine";
|
|
5
|
-
export declare const StarterComponentId
|
|
11
|
+
export declare const StarterComponentId = "express-suite-starter";
|
|
12
|
+
/**
|
|
13
|
+
* Create Starter component configuration with all translations
|
|
14
|
+
*/
|
|
6
15
|
export declare function createStarterComponentConfig(): ComponentConfig;
|
|
16
|
+
/**
|
|
17
|
+
* Get or create the Starter i18n engine
|
|
18
|
+
*/
|
|
7
19
|
export declare function getStarterI18nEngine(config?: EngineConfig): I18nEngine;
|
|
20
|
+
/**
|
|
21
|
+
* Proxy for backward compatibility
|
|
22
|
+
*/
|
|
8
23
|
export declare const starterI18nEngine: I18nEngine;
|
|
24
|
+
/**
|
|
25
|
+
* Reset function for tests
|
|
26
|
+
*/
|
|
9
27
|
export declare function resetStarterI18nEngine(): void;
|
|
10
|
-
|
|
11
|
-
|
|
28
|
+
/**
|
|
29
|
+
* Helper to translate Starter strings using translateStringKey.
|
|
30
|
+
* Uses the branded enum for automatic component ID resolution.
|
|
31
|
+
*
|
|
32
|
+
* @param stringKey - Can be either the plain StarterStringKey enum or StarterStringKeyValue
|
|
33
|
+
*/
|
|
34
|
+
export declare function getStarterTranslation(stringKey: StarterStringKey | StarterStringKeyValue, variables?: Record<string, string | number>, language?: string): string;
|
|
35
|
+
/**
|
|
36
|
+
* Safe translation with fallback using safeTranslateStringKey.
|
|
37
|
+
*
|
|
38
|
+
* @param stringKey - Can be either the plain StarterStringKey enum or StarterStringKeyValue
|
|
39
|
+
*/
|
|
40
|
+
export declare function safeStarterTranslation(stringKey: StarterStringKey | StarterStringKeyValue, variables?: Record<string, string | number>, language?: string): string;
|
|
12
41
|
//# sourceMappingURL=i18n-setup.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"i18n-setup.d.ts","sourceRoot":"","sources":["../../../src/i18n/i18n-setup.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"i18n-setup.d.ts","sourceRoot":"","sources":["../../../src/i18n/i18n-setup.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,OAAO,EAEL,UAAU,EAIX,MAAM,2BAA2B,CAAC;AACnC,OAAO,KAAK,EAAE,eAAe,EAAE,YAAY,EAAE,MAAM,2BAA2B,CAAC;AAC/E,OAAO,EAAE,gBAAgB,EAAE,MAAM,sBAAsB,CAAC;AACxD,OAAO,EAGL,KAAK,qBAAqB,EAC3B,MAAM,8BAA8B,CAAC;AAGtC,eAAO,MAAM,oBAAoB,EAAG,oCAA6C,CAAC;AAClF,eAAO,MAAM,kBAAkB,0BAAuB,CAAC;AAEvD;;GAEG;AACH,wBAAgB,4BAA4B,IAAI,eAAe,CAe9D;AAqCD;;GAEG;AACH,wBAAgB,oBAAoB,CAAC,MAAM,CAAC,EAAE,YAAY,GAAG,UAAU,CAoBtE;AAED;;GAEG;AACH,eAAO,MAAM,iBAAiB,YAI5B,CAAC;AAEH;;GAEG;AACH,wBAAgB,sBAAsB,IAAI,IAAI,CAG7C;AAED;;;;;GAKG;AACH,wBAAgB,qBAAqB,CACnC,SAAS,EAAE,gBAAgB,GAAG,qBAAqB,EACnD,SAAS,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CAAC,EAC3C,QAAQ,CAAC,EAAE,MAAM,GAChB,MAAM,CAMR;AAED;;;;GAIG;AACH,wBAAgB,sBAAsB,CACpC,SAAS,EAAE,gBAAgB,GAAG,qBAAqB,EACnD,SAAS,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CAAC,EAC3C,QAAQ,CAAC,EAAE,MAAM,GAChB,MAAM,CAMR"}
|
|
@@ -6,64 +6,113 @@ exports.getStarterI18nEngine = getStarterI18nEngine;
|
|
|
6
6
|
exports.resetStarterI18nEngine = resetStarterI18nEngine;
|
|
7
7
|
exports.getStarterTranslation = getStarterTranslation;
|
|
8
8
|
exports.safeStarterTranslation = safeStarterTranslation;
|
|
9
|
+
/**
|
|
10
|
+
* Express Suite Starter i18n Setup
|
|
11
|
+
* Uses I18nBuilder pattern for proper engine initialization.
|
|
12
|
+
* Supports translateStringKey for direct branded enum translation.
|
|
13
|
+
*/
|
|
9
14
|
const i18n_lib_1 = require("@digitaldefiance/i18n-lib");
|
|
15
|
+
const branded_starter_string_key_1 = require("./branded-starter-string-key");
|
|
10
16
|
const translations_all_1 = require("./translations-all");
|
|
11
17
|
exports.StarterI18nEngineKey = 'DigitalDefiance.Starter.I18nEngine';
|
|
12
|
-
exports.StarterComponentId =
|
|
18
|
+
exports.StarterComponentId = branded_starter_string_key_1.STARTER_COMPONENT_ID;
|
|
19
|
+
/**
|
|
20
|
+
* Create Starter component configuration with all translations
|
|
21
|
+
*/
|
|
13
22
|
function createStarterComponentConfig() {
|
|
14
|
-
const translations = {
|
|
15
|
-
[i18n_lib_1.LanguageCodes.EN_US]: translations_all_1.allTranslations['en-US'],
|
|
16
|
-
[i18n_lib_1.LanguageCodes.EN_GB]: translations_all_1.allTranslations['en-GB'],
|
|
17
|
-
[i18n_lib_1.LanguageCodes.ES]: translations_all_1.allTranslations['es'],
|
|
18
|
-
[i18n_lib_1.LanguageCodes.FR]: translations_all_1.allTranslations['fr'],
|
|
19
|
-
[i18n_lib_1.LanguageCodes.DE]: translations_all_1.allTranslations['de'],
|
|
20
|
-
[i18n_lib_1.LanguageCodes.ZH_CN]: translations_all_1.allTranslations['zh-CN'],
|
|
21
|
-
[i18n_lib_1.LanguageCodes.JA]: translations_all_1.allTranslations['ja'],
|
|
22
|
-
[i18n_lib_1.LanguageCodes.UK]: translations_all_1.allTranslations['uk'],
|
|
23
|
-
};
|
|
24
23
|
return {
|
|
25
24
|
id: exports.StarterComponentId,
|
|
26
|
-
strings:
|
|
25
|
+
strings: {
|
|
26
|
+
[i18n_lib_1.LanguageCodes.EN_US]: translations_all_1.allTranslations['en-US'],
|
|
27
|
+
[i18n_lib_1.LanguageCodes.EN_GB]: translations_all_1.allTranslations['en-GB'],
|
|
28
|
+
[i18n_lib_1.LanguageCodes.ES]: translations_all_1.allTranslations['es'],
|
|
29
|
+
[i18n_lib_1.LanguageCodes.FR]: translations_all_1.allTranslations['fr'],
|
|
30
|
+
[i18n_lib_1.LanguageCodes.DE]: translations_all_1.allTranslations['de'],
|
|
31
|
+
[i18n_lib_1.LanguageCodes.ZH_CN]: translations_all_1.allTranslations['zh-CN'],
|
|
32
|
+
[i18n_lib_1.LanguageCodes.JA]: translations_all_1.allTranslations['ja'],
|
|
33
|
+
[i18n_lib_1.LanguageCodes.UK]: translations_all_1.allTranslations['uk'],
|
|
34
|
+
},
|
|
35
|
+
aliases: ['StarterStringKey'],
|
|
27
36
|
};
|
|
28
37
|
}
|
|
29
38
|
let _starterEngine;
|
|
39
|
+
let _componentRegistered = false;
|
|
40
|
+
/**
|
|
41
|
+
* Register the engine with all required components using I18nBuilder
|
|
42
|
+
*/
|
|
43
|
+
function registerEngine(config) {
|
|
44
|
+
const newEngine = i18n_lib_1.I18nBuilder.create()
|
|
45
|
+
.withLanguages((0, i18n_lib_1.getCoreLanguageDefinitions)())
|
|
46
|
+
.withDefaultLanguage(config?.defaultLanguage ?? i18n_lib_1.LanguageCodes.EN_US)
|
|
47
|
+
.withInstanceKey('default')
|
|
48
|
+
.withStringKeyEnum(branded_starter_string_key_1.StarterStringKeys)
|
|
49
|
+
.build();
|
|
50
|
+
// Register Core i18n component (required for error messages)
|
|
51
|
+
const coreReg = (0, i18n_lib_1.createCoreComponentRegistration)();
|
|
52
|
+
newEngine.register({
|
|
53
|
+
id: coreReg.component.id,
|
|
54
|
+
strings: coreReg.strings,
|
|
55
|
+
});
|
|
56
|
+
// Register Starter component
|
|
57
|
+
const starterConfig = createStarterComponentConfig();
|
|
58
|
+
const result = newEngine.registerIfNotExists(starterConfig);
|
|
59
|
+
if (!result.isValid && result.errors.length > 0) {
|
|
60
|
+
console.warn(`Starter component has ${result.errors.length} errors`, result.errors.slice(0, 5));
|
|
61
|
+
}
|
|
62
|
+
return newEngine;
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* Get or create the Starter i18n engine
|
|
66
|
+
*/
|
|
30
67
|
function getStarterI18nEngine(config) {
|
|
31
|
-
if (
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
aliases: ['StarterStringKey'],
|
|
42
|
-
});
|
|
43
|
-
if (!result.isValid && result.errors.length > 0) {
|
|
44
|
-
console.warn(`Starter component has ${result.errors.length} errors`, result.errors.slice(0, 5));
|
|
68
|
+
if (i18n_lib_1.I18nEngine.hasInstance('default')) {
|
|
69
|
+
_starterEngine = i18n_lib_1.I18nEngine.getInstance('default');
|
|
70
|
+
// Ensure our component is registered on existing instance
|
|
71
|
+
if (!_componentRegistered) {
|
|
72
|
+
_starterEngine.registerIfNotExists(createStarterComponentConfig());
|
|
73
|
+
// Register branded string key enum for translateStringKey support
|
|
74
|
+
if (!_starterEngine.hasStringKeyEnum(branded_starter_string_key_1.StarterStringKeys)) {
|
|
75
|
+
_starterEngine.registerStringKeyEnum(branded_starter_string_key_1.StarterStringKeys);
|
|
76
|
+
}
|
|
77
|
+
_componentRegistered = true;
|
|
45
78
|
}
|
|
46
|
-
|
|
79
|
+
}
|
|
80
|
+
else if (!_starterEngine) {
|
|
81
|
+
_starterEngine = registerEngine(config);
|
|
82
|
+
_componentRegistered = true;
|
|
47
83
|
}
|
|
48
84
|
return _starterEngine;
|
|
49
85
|
}
|
|
86
|
+
/**
|
|
87
|
+
* Proxy for backward compatibility
|
|
88
|
+
*/
|
|
50
89
|
exports.starterI18nEngine = new Proxy({}, {
|
|
51
|
-
get(
|
|
90
|
+
get(_target, prop) {
|
|
52
91
|
return getStarterI18nEngine()[prop];
|
|
53
92
|
},
|
|
54
93
|
});
|
|
94
|
+
/**
|
|
95
|
+
* Reset function for tests
|
|
96
|
+
*/
|
|
55
97
|
function resetStarterI18nEngine() {
|
|
56
98
|
_starterEngine = undefined;
|
|
99
|
+
_componentRegistered = false;
|
|
57
100
|
}
|
|
101
|
+
/**
|
|
102
|
+
* Helper to translate Starter strings using translateStringKey.
|
|
103
|
+
* Uses the branded enum for automatic component ID resolution.
|
|
104
|
+
*
|
|
105
|
+
* @param stringKey - Can be either the plain StarterStringKey enum or StarterStringKeyValue
|
|
106
|
+
*/
|
|
58
107
|
function getStarterTranslation(stringKey, variables, language) {
|
|
59
|
-
return getStarterI18nEngine().
|
|
108
|
+
return getStarterI18nEngine().translateStringKey(stringKey, variables, language);
|
|
60
109
|
}
|
|
110
|
+
/**
|
|
111
|
+
* Safe translation with fallback using safeTranslateStringKey.
|
|
112
|
+
*
|
|
113
|
+
* @param stringKey - Can be either the plain StarterStringKey enum or StarterStringKeyValue
|
|
114
|
+
*/
|
|
61
115
|
function safeStarterTranslation(stringKey, variables, language) {
|
|
62
|
-
|
|
63
|
-
return getStarterTranslation(stringKey, variables, language);
|
|
64
|
-
}
|
|
65
|
-
catch {
|
|
66
|
-
return `[${stringKey}]`;
|
|
67
|
-
}
|
|
116
|
+
return getStarterI18nEngine().safeTranslateStringKey(stringKey, variables, language);
|
|
68
117
|
}
|
|
69
118
|
//# sourceMappingURL=i18n-setup.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"i18n-setup.js","sourceRoot":"","sources":["../../../src/i18n/i18n-setup.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"i18n-setup.js","sourceRoot":"","sources":["../../../src/i18n/i18n-setup.ts"],"names":[],"mappings":"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"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@digitaldefiance/express-suite-starter",
|
|
3
|
-
"version": "2.4.
|
|
3
|
+
"version": "2.4.6",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"bin": {
|
|
6
6
|
"create-express-suite": "./dist/src/cli.js"
|
|
@@ -31,7 +31,7 @@
|
|
|
31
31
|
"publish:public": "npm publish --access public"
|
|
32
32
|
},
|
|
33
33
|
"dependencies": {
|
|
34
|
-
"@digitaldefiance/i18n-lib": "
|
|
34
|
+
"@digitaldefiance/i18n-lib": "^4.3.0",
|
|
35
35
|
"@inquirer/prompts": "^7.5.0",
|
|
36
36
|
"chalk": "^4.1.2",
|
|
37
37
|
"handlebars": "^4.7.8",
|
|
@@ -10,7 +10,7 @@ import {
|
|
|
10
10
|
} from '@digitaldefiance/i18n-lib';
|
|
11
11
|
import type { BrandedEnumValue } from '@digitaldefiance/branded-enum';
|
|
12
12
|
import { AppConstants } from './constants';
|
|
13
|
-
import { {{WorkspaceName}}StringKey } from './enumerations/{{workspaceName}}-string-key';
|
|
13
|
+
import { {{WorkspaceName}}StringKey, type {{WorkspaceName}}StringKeyValue } from './enumerations/{{workspaceName}}-string-key';
|
|
14
14
|
import { Strings } from './strings-collection';
|
|
15
15
|
import { createSuiteCoreComponentConfig } from '@digitaldefiance/suite-core-lib';
|
|
16
16
|
|
|
@@ -59,6 +59,11 @@ if (!registrationResult.isValid) {
|
|
|
59
59
|
console.warn('Component has missing translations:', registrationResult.errors);
|
|
60
60
|
}
|
|
61
61
|
|
|
62
|
+
// Register the branded string key enum for direct translation support
|
|
63
|
+
if (!i18nEngine.hasStringKeyEnum({{WorkspaceName}}StringKey)) {
|
|
64
|
+
i18nEngine.registerStringKeyEnum({{WorkspaceName}}StringKey);
|
|
65
|
+
}
|
|
66
|
+
|
|
62
67
|
const globalContext = GlobalActiveContext.getInstance<CoreLanguageCode, IActiveContext<CoreLanguageCode>>();
|
|
63
68
|
globalContext.createContext(LanguageCodes.EN_US, LanguageCodes.EN_US, ComponentId);
|
|
64
69
|
|
|
@@ -85,6 +90,7 @@ export const i18nContext: IActiveContext<CoreLanguageCode> = {
|
|
|
85
90
|
|
|
86
91
|
/**
|
|
87
92
|
* Translate a string key to the current or specified language.
|
|
93
|
+
* Uses translateStringKey for automatic component ID resolution.
|
|
88
94
|
*
|
|
89
95
|
* @param name - The branded string key value to translate
|
|
90
96
|
* @param variables - Optional variables to interpolate into the translation
|
|
@@ -93,7 +99,33 @@ export const i18nContext: IActiveContext<CoreLanguageCode> = {
|
|
|
93
99
|
* @returns The translated string
|
|
94
100
|
*/
|
|
95
101
|
export const translate = (
|
|
96
|
-
name: BrandedEnumValue<typeof {{WorkspaceName}}StringKey
|
|
102
|
+
name: BrandedEnumValue<typeof {{WorkspaceName}}StringKey> | {{WorkspaceName}}StringKeyValue,
|
|
103
|
+
variables?: Record<string, string | number>,
|
|
104
|
+
language?: CoreLanguageCode,
|
|
105
|
+
context?: LanguageContextSpace,
|
|
106
|
+
): string => {
|
|
107
|
+
const activeContext = context ?? globalContext.getContext(ComponentId).currentContext;
|
|
108
|
+
const lang =
|
|
109
|
+
language ??
|
|
110
|
+
(activeContext === 'admin'
|
|
111
|
+
? globalContext.getContext(ComponentId).adminLanguage
|
|
112
|
+
: globalContext.getContext(ComponentId).language);
|
|
113
|
+
|
|
114
|
+
return i18nEngine.translateStringKey(name, variables, lang);
|
|
115
|
+
};
|
|
116
|
+
|
|
117
|
+
/**
|
|
118
|
+
* Safe translation with fallback - never throws.
|
|
119
|
+
* Returns a placeholder string if translation fails.
|
|
120
|
+
*
|
|
121
|
+
* @param name - The branded string key value to translate
|
|
122
|
+
* @param variables - Optional variables to interpolate into the translation
|
|
123
|
+
* @param language - Optional language override
|
|
124
|
+
* @param context - Optional context space override
|
|
125
|
+
* @returns The translated string or a placeholder on failure
|
|
126
|
+
*/
|
|
127
|
+
export const safeTranslate = (
|
|
128
|
+
name: BrandedEnumValue<typeof {{WorkspaceName}}StringKey> | {{WorkspaceName}}StringKeyValue,
|
|
97
129
|
variables?: Record<string, string | number>,
|
|
98
130
|
language?: CoreLanguageCode,
|
|
99
131
|
context?: LanguageContextSpace,
|
|
@@ -105,5 +137,5 @@ export const translate = (
|
|
|
105
137
|
? globalContext.getContext(ComponentId).adminLanguage
|
|
106
138
|
: globalContext.getContext(ComponentId).language);
|
|
107
139
|
|
|
108
|
-
return i18nEngine.
|
|
140
|
+
return i18nEngine.safeTranslateStringKey(name, variables, lang);
|
|
109
141
|
};
|