@kosdev-code/kos-ui-sdk 3.0.29 → 3.0.31
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/core/core/transport/mock/index.d.ts +2 -0
- package/core/core/transport/mock/index.d.ts.map +1 -1
- package/core/core/transport/mock/mock-boot.d.ts +39 -0
- package/core/core/transport/mock/mock-boot.d.ts.map +1 -0
- package/index.cjs +34 -4
- package/index.cjs.map +1 -1
- package/index.js +35 -5
- package/index.js.map +1 -1
- package/models/models/translation/translation-model.d.ts +4 -2
- package/models/models/translation/translation-model.d.ts.map +1 -1
- package/models/models/translation/types/index.d.ts +24 -6
- package/package.json +2 -2
- package/{software-info-registration-CA13_Qc_.cjs → software-info-registration-BPN4QLfN.cjs} +15 -9
- package/{software-info-registration-CA13_Qc_.cjs.map → software-info-registration-BPN4QLfN.cjs.map} +1 -1
- package/{software-info-registration-CKRUzp_3.js → software-info-registration-BTHhITrs.js} +15 -9
- package/{software-info-registration-CKRUzp_3.js.map → software-info-registration-BTHhITrs.js.map} +1 -1
- package/testing.cjs +1 -1
- package/testing.js +1 -1
- package/ui/contexts/translation-container/kos-translations-provider.d.ts +8 -1
- package/ui/contexts/translation-container/kos-translations-provider.d.ts.map +1 -1
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { IKosDataModel, IKosIdentifiable, KosContext, KosCreationContext } from '../../../core';
|
|
2
2
|
import { PublicModelInterface } from '../../../core/types';
|
|
3
3
|
import { LocaleDescriptor, TranslationResponse } from './services';
|
|
4
|
-
import { TranslationOptions } from './types';
|
|
4
|
+
import { TranslationFallback, TranslationOptions } from './types';
|
|
5
5
|
export declare const MODEL_TYPE = "translation-model";
|
|
6
6
|
interface ResolveTranslationOptionsBase<T = string> {
|
|
7
7
|
context?: string;
|
|
@@ -58,7 +58,7 @@ export declare class TranslationModelImpl implements IKosDataModel, IKosIdentifi
|
|
|
58
58
|
/** Currently active locale for translation resolution */
|
|
59
59
|
currentLocale: string;
|
|
60
60
|
/** Custom bundle resolver for loading translation data */
|
|
61
|
-
bundleResolver?: (namespace: string, locale: string, context?: KosContext) => Promise<TranslationResponse>;
|
|
61
|
+
bundleResolver?: (namespace: string, locale: string, context?: KosContext) => Promise<TranslationResponse | TranslationFallback>;
|
|
62
62
|
/** Flattened translation data for efficient key lookup */
|
|
63
63
|
private data;
|
|
64
64
|
/** Context logger for debugging and diagnostics */
|
|
@@ -79,6 +79,8 @@ export declare class TranslationModelImpl implements IKosDataModel, IKosIdentifi
|
|
|
79
79
|
* @private
|
|
80
80
|
*/
|
|
81
81
|
getTranslationLocales(locale: string): string[];
|
|
82
|
+
/** The namespace's translation file for `lang`, through `resolver`; empty when it has none. */
|
|
83
|
+
private loadFile;
|
|
82
84
|
/**
|
|
83
85
|
* Loads and merges translations for all locales in the fallback chain.
|
|
84
86
|
* @private
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"translation-model.d.ts","sourceRoot":"","sources":["../../../../../../packages/kos-ui-sdk/src/models/models/translation/translation-model.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EACV,aAAa,EACb,gBAAgB,EAChB,UAAU,EAEV,kBAAkB,EACnB,MAAM,eAAe,CAAC;AAQvB,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,qBAAqB,CAAC;AAEhE,OAAO,EACL,gBAAgB,EAChB,mBAAmB,EAEpB,MAAM,YAAY,CAAC;AAEpB,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,SAAS,CAAC;
|
|
1
|
+
{"version":3,"file":"translation-model.d.ts","sourceRoot":"","sources":["../../../../../../packages/kos-ui-sdk/src/models/models/translation/translation-model.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EACV,aAAa,EACb,gBAAgB,EAChB,UAAU,EAEV,kBAAkB,EACnB,MAAM,eAAe,CAAC;AAQvB,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,qBAAqB,CAAC;AAEhE,OAAO,EACL,gBAAgB,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C,IAAI,CAAC;IAOtB,yBAAyB;CAGhC"}
|
|
@@ -3,6 +3,20 @@ import { LocaleDescriptor, Localization, TranslationResponse } from '../services
|
|
|
3
3
|
import { TranslationContainerModel } from '../translation-container-model';
|
|
4
4
|
// --------------- Translation ---------------
|
|
5
5
|
|
|
6
|
+
/**
|
|
7
|
+
* What a `bundleResolver` resolves to when it does not serve a namespace itself: the
|
|
8
|
+
* namespace's translation file is then loaded through `resolver`, as without a
|
|
9
|
+
* `bundleResolver`. Resolving `undefined` instead merges nothing for that locale.
|
|
10
|
+
*
|
|
11
|
+
* @kosService core.translation
|
|
12
|
+
* @kosApiLevel 26
|
|
13
|
+
* @group KOS Model
|
|
14
|
+
* @category i18n
|
|
15
|
+
*/
|
|
16
|
+
export interface TranslationFallback {
|
|
17
|
+
fallback: true;
|
|
18
|
+
}
|
|
19
|
+
|
|
6
20
|
/**
|
|
7
21
|
* Options for a {@link TranslationModel}, which loads and resolves the keys of
|
|
8
22
|
* one translation namespace. Translation models are normally created by a
|
|
@@ -49,18 +63,19 @@ export interface TranslationOptions extends KosParentAware {
|
|
|
49
63
|
|
|
50
64
|
/**
|
|
51
65
|
* Loads translation data directly instead of fetching a file. When set,
|
|
52
|
-
* `resolver` is
|
|
66
|
+
* `resolver` is used only for a locale it resolves to `{ fallback: true }`.
|
|
53
67
|
*
|
|
54
68
|
* @param namespace - Target translation namespace
|
|
55
69
|
* @param locale - Target locale code
|
|
56
70
|
* @param context - KOS context of the translation model
|
|
57
|
-
* @returns Promise resolving to translation data
|
|
71
|
+
* @returns Promise resolving to translation data, or to {@link TranslationFallback}
|
|
72
|
+
* to load the namespace's file instead
|
|
58
73
|
*/
|
|
59
74
|
bundleResolver?: (
|
|
60
75
|
namespace: string,
|
|
61
76
|
locale: string,
|
|
62
77
|
context?: KosContext
|
|
63
|
-
) => Promise<TranslationResponse>;
|
|
78
|
+
) => Promise<TranslationResponse | TranslationFallback>;
|
|
64
79
|
}
|
|
65
80
|
|
|
66
81
|
// --------------- TranslationContainer ---------------
|
|
@@ -126,7 +141,9 @@ export interface TranslationContainerOptions {
|
|
|
126
141
|
|
|
127
142
|
/**
|
|
128
143
|
* Loads translation data for every namespace this container serves, instead of
|
|
129
|
-
* fetching files. When set, `resolver` is
|
|
144
|
+
* fetching files. When set, `resolver` is used only for a namespace and locale it
|
|
145
|
+
* resolves to `{ fallback: true }`, so it can serve some namespaces and leave the
|
|
146
|
+
* rest to their files.
|
|
130
147
|
*
|
|
131
148
|
* Each namespace's translation model calls it once per locale in its fallback
|
|
132
149
|
* chain and merges the results in chain order, as it does for loaded files. A
|
|
@@ -137,13 +154,14 @@ export interface TranslationContainerOptions {
|
|
|
137
154
|
* @param namespace - Target translation namespace
|
|
138
155
|
* @param locale - Target locale code
|
|
139
156
|
* @param context - KOS context of the translation model
|
|
140
|
-
* @returns Promise resolving to translation data
|
|
157
|
+
* @returns Promise resolving to translation data, or to {@link TranslationFallback}
|
|
158
|
+
* to load the namespace's file instead
|
|
141
159
|
*/
|
|
142
160
|
bundleResolver?: (
|
|
143
161
|
namespace: string,
|
|
144
162
|
locale: string,
|
|
145
163
|
context?: KosContext
|
|
146
|
-
) => Promise<TranslationResponse>;
|
|
164
|
+
) => Promise<TranslationResponse | TranslationFallback>;
|
|
147
165
|
}
|
|
148
166
|
|
|
149
167
|
/**
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kosdev-code/kos-ui-sdk",
|
|
3
|
-
"version": "3.0.
|
|
3
|
+
"version": "3.0.31",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "./index.cjs",
|
|
6
6
|
"module": "./index.js",
|
|
@@ -59,7 +59,7 @@
|
|
|
59
59
|
},
|
|
60
60
|
"kos": {
|
|
61
61
|
"build": {
|
|
62
|
-
"gitHash": "
|
|
62
|
+
"gitHash": "c42e1f96749c8a155eac907eaf3ba3bee422f122"
|
|
63
63
|
}
|
|
64
64
|
}
|
|
65
65
|
}
|
|
@@ -24129,6 +24129,7 @@ const splitKey = (currentNamespace, _key) => {
|
|
|
24129
24129
|
return { namespace: currentNamespace, key: _key };
|
|
24130
24130
|
}
|
|
24131
24131
|
};
|
|
24132
|
+
const isTranslationFallback = (bundle) => bundle?.fallback === true;
|
|
24132
24133
|
let TranslationModelImpl = class {
|
|
24133
24134
|
/** Unique identifier for the model instance */
|
|
24134
24135
|
id;
|
|
@@ -24188,23 +24189,28 @@ let TranslationModelImpl = class {
|
|
|
24188
24189
|
}
|
|
24189
24190
|
return langs;
|
|
24190
24191
|
}
|
|
24192
|
+
/** The namespace's translation file for `lang`, through `resolver`; empty when it has none. */
|
|
24193
|
+
loadFile(lang) {
|
|
24194
|
+
try {
|
|
24195
|
+
const translationsPath = this.resolver(this.namespace, lang);
|
|
24196
|
+
return getTranslations(translationsPath, this.rootUrl);
|
|
24197
|
+
} catch {
|
|
24198
|
+
return Promise.resolve({});
|
|
24199
|
+
}
|
|
24200
|
+
}
|
|
24191
24201
|
/**
|
|
24192
24202
|
* Loads and merges translations for all locales in the fallback chain.
|
|
24193
24203
|
* @private
|
|
24194
24204
|
*/
|
|
24195
24205
|
async loadTranslations() {
|
|
24196
24206
|
const reversed = this.getTranslationLocales(this.currentLocale).reverse();
|
|
24197
|
-
const allTranslations = reversed.map((lang) => {
|
|
24207
|
+
const allTranslations = reversed.map(async (lang) => {
|
|
24198
24208
|
if (this.bundleResolver) {
|
|
24199
24209
|
const context = KosContextManager.getContext(this.id);
|
|
24200
|
-
|
|
24201
|
-
|
|
24202
|
-
try {
|
|
24203
|
-
const translationsPath = this.resolver(this.namespace, lang);
|
|
24204
|
-
return getTranslations(translationsPath, this.rootUrl);
|
|
24205
|
-
} catch {
|
|
24206
|
-
return Promise.resolve({});
|
|
24210
|
+
const bundle = await this.bundleResolver(this.namespace, lang, context);
|
|
24211
|
+
return isTranslationFallback(bundle) ? this.loadFile(lang) : bundle;
|
|
24207
24212
|
}
|
|
24213
|
+
return this.loadFile(lang);
|
|
24208
24214
|
});
|
|
24209
24215
|
const results = await Promise.allSettled(allTranslations);
|
|
24210
24216
|
kosAction(() => {
|
|
@@ -25384,4 +25390,4 @@ exports.waitForRequest = waitForRequest;
|
|
|
25384
25390
|
exports.whenReady = whenReady;
|
|
25385
25391
|
exports.withCancellation = withCancellation;
|
|
25386
25392
|
exports.wrapWithFutureLifecycle = wrapWithFutureLifecycle;
|
|
25387
|
-
//# sourceMappingURL=software-info-registration-
|
|
25393
|
+
//# sourceMappingURL=software-info-registration-BPN4QLfN.cjs.map
|