mirror of
https://github.com/moltbot/moltbot.git
synced 2026-03-07 22:44:16 +00:00
fix(ci): resolve i18n typing and generated-policy drift
This commit is contained in:
@@ -22,17 +22,17 @@ enum HostEnvSecurityPolicy {
|
||||
"PS4",
|
||||
"GCONV_PATH",
|
||||
"IFS",
|
||||
"SSLKEYLOGFILE",
|
||||
"SSLKEYLOGFILE"
|
||||
]
|
||||
|
||||
static let blockedOverrideKeys: Set<String> = [
|
||||
"HOME",
|
||||
"ZDOTDIR",
|
||||
"ZDOTDIR"
|
||||
]
|
||||
|
||||
static let blockedPrefixes: [String] = [
|
||||
"DYLD_",
|
||||
"LD_",
|
||||
"BASH_FUNC_",
|
||||
"BASH_FUNC_"
|
||||
]
|
||||
}
|
||||
|
||||
@@ -5,6 +5,18 @@ import {
|
||||
loadLazyLocaleTranslation,
|
||||
resolveNavigatorLocale,
|
||||
} from "../../ui/src/i18n/lib/registry.ts";
|
||||
import type { TranslationMap } from "../../ui/src/i18n/lib/types.ts";
|
||||
|
||||
function getNestedTranslation(map: TranslationMap | null, ...path: string[]): string | undefined {
|
||||
let value: string | TranslationMap | undefined = map ?? undefined;
|
||||
for (const key of path) {
|
||||
if (value === undefined || typeof value === "string") {
|
||||
return undefined;
|
||||
}
|
||||
value = value[key];
|
||||
}
|
||||
return typeof value === "string" ? value : undefined;
|
||||
}
|
||||
|
||||
describe("ui i18n locale registry", () => {
|
||||
it("lists supported locales", () => {
|
||||
@@ -23,8 +35,8 @@ describe("ui i18n locale registry", () => {
|
||||
const de = await loadLazyLocaleTranslation("de");
|
||||
const zhCN = await loadLazyLocaleTranslation("zh-CN");
|
||||
|
||||
expect(de?.common?.health).toBe("Status");
|
||||
expect(zhCN?.common?.health).toBe("健康状况");
|
||||
expect(getNestedTranslation(de, "common", "health")).toBe("Status");
|
||||
expect(getNestedTranslation(zhCN, "common", "health")).toBe("健康状况");
|
||||
expect(await loadLazyLocaleTranslation("en")).toBeNull();
|
||||
});
|
||||
});
|
||||
|
||||
@@ -37,6 +37,10 @@ export function isSupportedLocale(value: string | null | undefined): value is Lo
|
||||
return value !== null && value !== undefined && SUPPORTED_LOCALES.includes(value as Locale);
|
||||
}
|
||||
|
||||
function isLazyLocale(locale: Locale): locale is LazyLocale {
|
||||
return LAZY_LOCALES.includes(locale as LazyLocale);
|
||||
}
|
||||
|
||||
export function resolveNavigatorLocale(navLang: string): Locale {
|
||||
if (navLang.startsWith("zh")) {
|
||||
return navLang === "zh-TW" || navLang === "zh-HK" ? "zh-TW" : "zh-CN";
|
||||
@@ -51,13 +55,10 @@ export function resolveNavigatorLocale(navLang: string): Locale {
|
||||
}
|
||||
|
||||
export async function loadLazyLocaleTranslation(locale: Locale): Promise<TranslationMap | null> {
|
||||
if (locale === DEFAULT_LOCALE) {
|
||||
if (!isLazyLocale(locale)) {
|
||||
return null;
|
||||
}
|
||||
const registration = LAZY_LOCALE_REGISTRY[locale];
|
||||
if (!registration) {
|
||||
return null;
|
||||
}
|
||||
const module = await registration.loader();
|
||||
return module[registration.exportName] ?? null;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user