mirror of
https://github.com/openclaw/openclaw.git
synced 2026-03-12 07:20:45 +00:00
fix(ci): resolve i18n typing and generated-policy drift
This commit is contained in:
@@ -22,17 +22,17 @@ enum HostEnvSecurityPolicy {
|
|||||||
"PS4",
|
"PS4",
|
||||||
"GCONV_PATH",
|
"GCONV_PATH",
|
||||||
"IFS",
|
"IFS",
|
||||||
"SSLKEYLOGFILE",
|
"SSLKEYLOGFILE"
|
||||||
]
|
]
|
||||||
|
|
||||||
static let blockedOverrideKeys: Set<String> = [
|
static let blockedOverrideKeys: Set<String> = [
|
||||||
"HOME",
|
"HOME",
|
||||||
"ZDOTDIR",
|
"ZDOTDIR"
|
||||||
]
|
]
|
||||||
|
|
||||||
static let blockedPrefixes: [String] = [
|
static let blockedPrefixes: [String] = [
|
||||||
"DYLD_",
|
"DYLD_",
|
||||||
"LD_",
|
"LD_",
|
||||||
"BASH_FUNC_",
|
"BASH_FUNC_"
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,6 +5,18 @@ import {
|
|||||||
loadLazyLocaleTranslation,
|
loadLazyLocaleTranslation,
|
||||||
resolveNavigatorLocale,
|
resolveNavigatorLocale,
|
||||||
} from "../../ui/src/i18n/lib/registry.ts";
|
} 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", () => {
|
describe("ui i18n locale registry", () => {
|
||||||
it("lists supported locales", () => {
|
it("lists supported locales", () => {
|
||||||
@@ -23,8 +35,8 @@ describe("ui i18n locale registry", () => {
|
|||||||
const de = await loadLazyLocaleTranslation("de");
|
const de = await loadLazyLocaleTranslation("de");
|
||||||
const zhCN = await loadLazyLocaleTranslation("zh-CN");
|
const zhCN = await loadLazyLocaleTranslation("zh-CN");
|
||||||
|
|
||||||
expect(de?.common?.health).toBe("Status");
|
expect(getNestedTranslation(de, "common", "health")).toBe("Status");
|
||||||
expect(zhCN?.common?.health).toBe("健康状况");
|
expect(getNestedTranslation(zhCN, "common", "health")).toBe("健康状况");
|
||||||
expect(await loadLazyLocaleTranslation("en")).toBeNull();
|
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);
|
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 {
|
export function resolveNavigatorLocale(navLang: string): Locale {
|
||||||
if (navLang.startsWith("zh")) {
|
if (navLang.startsWith("zh")) {
|
||||||
return navLang === "zh-TW" || navLang === "zh-HK" ? "zh-TW" : "zh-CN";
|
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> {
|
export async function loadLazyLocaleTranslation(locale: Locale): Promise<TranslationMap | null> {
|
||||||
if (locale === DEFAULT_LOCALE) {
|
if (!isLazyLocale(locale)) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
const registration = LAZY_LOCALE_REGISTRY[locale];
|
const registration = LAZY_LOCALE_REGISTRY[locale];
|
||||||
if (!registration) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
const module = await registration.loader();
|
const module = await registration.loader();
|
||||||
return module[registration.exportName] ?? null;
|
return module[registration.exportName] ?? null;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user