Skip to content

Commit 860c8a1

Browse files
Copilothotlong
andcommitted
refactor: improve i18n bundle types in createKernel (code review feedback)
Co-authored-by: hotlong <50353452+hotlong@users.noreply.github.com> Agent-Logs-Url: https://github.com/objectstack-ai/objectui/sessions/00eab53d-cefa-4f13-9413-eed4af8e9854
1 parent f9eb2a9 commit 860c8a1

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed

apps/console/src/mocks/createKernel.ts

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -257,6 +257,15 @@ function buildCubesFromConfig(appConfig: any): Cube[] {
257257
return cubes;
258258
}
259259

260+
/** Per-language translation map: language code → translation tree. */
261+
type TranslationMap = Record<string, Record<string, unknown>>;
262+
263+
/** A named translation bundle as declared in a stack's i18n config. */
264+
interface I18nBundle {
265+
namespace: string;
266+
translations: TranslationMap;
267+
}
268+
260269
/**
261270
* Resolve translations for a given language from the i18n bundles
262271
* declared in the application configuration.
@@ -267,12 +276,12 @@ function buildCubesFromConfig(appConfig: any): Cube[] {
267276
* `crm.objects.account.label`.
268277
*/
269278
function resolveI18nTranslations(
270-
bundles: Array<{ namespace: string; translations: Record<string, unknown> }>,
279+
bundles: I18nBundle[],
271280
lang: string,
272281
): Record<string, unknown> {
273282
const merged: Record<string, unknown> = {};
274283
for (const bundle of bundles) {
275-
const langTranslations = (bundle.translations as Record<string, any>)?.[lang];
284+
const langTranslations = bundle.translations[lang];
276285
if (langTranslations) {
277286
merged[bundle.namespace] = langTranslations;
278287
}
@@ -320,8 +329,7 @@ export async function createKernel(options: KernelOptions): Promise<KernelResult
320329
// `i18n: { namespace, translations }` field and merged via sharedConfig).
321330
// This ensures both MSW/mock and server modes share the same translation
322331
// resolution pipeline — no manual per-environment i18n handlers required.
323-
const i18nBundles: Array<{ namespace: string; translations: Record<string, unknown> }> =
324-
appConfig.i18n?.bundles ?? [];
332+
const i18nBundles: I18nBundle[] = appConfig.i18n?.bundles ?? [];
325333

326334
if (i18nBundles.length > 0) {
327335
kernel.registerService('i18n', {

0 commit comments

Comments
 (0)