Files
adolf/scripts/android-app-i18n.ts
alvis bedb527145
Some checks failed
ClawSweeper Dispatch / dispatch (push) Has been cancelled
CodeQL / Security High (actions) (push) Has been cancelled
CodeQL / Security High (channel-runtime-boundary) (push) Has been cancelled
CodeQL / Security High (core-auth-secrets) (push) Has been cancelled
CodeQL / Security High (mcp-process-tool-boundary) (push) Has been cancelled
CodeQL / Security High (network-ssrf-boundary) (push) Has been cancelled
CodeQL / Security High (plugin-trust-boundary) (push) Has been cancelled
CodeQL / Security High (process-exec-boundary) (push) Has been cancelled
Docs Sync Publish Repo / sync-publish-repo (push) Has been cancelled
Docs / docs (push) Has been cancelled
OpenClaw Stable Main Closeout / Resolve stable release closeout inputs (push) Has been cancelled
OpenClaw Stable Main Closeout / Verify stable main closeout (push) Has been cancelled
Workflow Sanity / no-tabs (push) Has been cancelled
Workflow Sanity / actionlint (push) Has been cancelled
Workflow Sanity / generated-doc-baselines (push) Has been cancelled
CI / runner-admission (push) Has been cancelled
CI / preflight (push) Has been cancelled
CI / security-fast (push) Has been cancelled
CI / pnpm-store-warmup (push) Has been cancelled
CI / build-artifacts (push) Has been cancelled
CI / native-i18n (push) Has been cancelled
CI / ${{ matrix.check_name }} (push) Has been cancelled
CI / ${{ matrix.checkName }} (push) Has been cancelled
CI / checks-node-compat-node22 (push) Has been cancelled
CI / check-bundled-channel-config-metadata (push) Has been cancelled
CI / check-dependencies (push) Has been cancelled
CI / check-guards (push) Has been cancelled
CI / check-lint (push) Has been cancelled
CI / check-prod-types (push) Has been cancelled
CI / check-shrinkwrap (push) Has been cancelled
CI / check-test-types (push) Has been cancelled
CI / check-additional-boundaries-a (push) Has been cancelled
CI / check-additional-boundaries-bcd (push) Has been cancelled
CI / check-additional-extension-bundled (push) Has been cancelled
CI / check-additional-extension-channels (push) Has been cancelled
CI / check-additional-extension-package-boundary (push) Has been cancelled
CI / check-additional-runtime-topology-architecture (push) Has been cancelled
CI / check-session-accessor-boundary (push) Has been cancelled
CI / check-session-transcript-reader-boundary (push) Has been cancelled
CI / check-docs (push) Has been cancelled
CI / skills-python (push) Has been cancelled
CI / macos-swift (push) Has been cancelled
CI / ios-build (push) Has been cancelled
CI / ci-timings-summary (push) Has been cancelled
Native App Locale Refresh / Refresh native fa (push) Has been cancelled
Native App Locale Refresh / Refresh native fr (push) Has been cancelled
Native App Locale Refresh / Refresh native hi (push) Has been cancelled
Native App Locale Refresh / Refresh native id (push) Has been cancelled
Native App Locale Refresh / Refresh native it (push) Has been cancelled
Native App Locale Refresh / Refresh native ja-JP (push) Has been cancelled
Control UI Locale Refresh / plan (push) Has been cancelled
Control UI Locale Refresh / Refresh ${{ matrix.locale }} (push) Has been cancelled
Control UI Locale Refresh / Commit control UI locale refresh (push) Has been cancelled
Live Media Runner Image / Build live media runner image (push) Has been cancelled
Native App Locale Refresh / Refresh native ar (push) Has been cancelled
Native App Locale Refresh / Refresh native de (push) Has been cancelled
Native App Locale Refresh / Refresh native es (push) Has been cancelled
Native App Locale Refresh / Refresh native ko (push) Has been cancelled
Native App Locale Refresh / Refresh native nl (push) Has been cancelled
Native App Locale Refresh / Refresh native pl (push) Has been cancelled
Native App Locale Refresh / Refresh native pt-BR (push) Has been cancelled
Native App Locale Refresh / Refresh native ru (push) Has been cancelled
Native App Locale Refresh / Refresh native sv (push) Has been cancelled
Native App Locale Refresh / Refresh native th (push) Has been cancelled
Native App Locale Refresh / Refresh native tr (push) Has been cancelled
Native App Locale Refresh / Refresh native uk (push) Has been cancelled
Native App Locale Refresh / Refresh native vi (push) Has been cancelled
Native App Locale Refresh / Refresh native zh-CN (push) Has been cancelled
Native App Locale Refresh / Refresh native zh-TW (push) Has been cancelled
Native App Locale Refresh / Commit native locale refresh (push) Has been cancelled
Plugin Init Scaffold Validation / Validate provider scaffold (push) Has been cancelled
Plugin NPM Release / preview_plugins_npm (push) Has been cancelled
Plugin NPM Release / Validate release publish approval (push) Has been cancelled
Plugin NPM Release / preview_plugin_pack (push) Has been cancelled
Plugin NPM Release / publish_plugins_npm (push) Has been cancelled
Sandbox Common Smoke / sandbox-common-smoke (push) Has been cancelled
Website Installer Sync / static (push) Has been cancelled
Website Installer Sync / linux-docker (push) Has been cancelled
Website Installer Sync / macos-installer (push) Has been cancelled
Website Installer Sync / windows-installer (push) Has been cancelled
Website Installer Sync / sync-website (push) Has been cancelled
Vendor OpenClaw source as Adolf fork baseline
Adolf is a fork/vendored clone of github.com/openclaw/openclaw (v2026.6.11),
free to diverge. Tree copied sans upstream .git; upstream remote added for
future syncs. Node pinned to 24 (.nvmrc); engines already require >=22.19.
Preserves docs/ARCHITECTURE.md.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01LeqyaxJF2nbRXJtae2kNB2
2026-07-05 09:36:54 +00:00

112 lines
4.3 KiB
TypeScript

import { readdir, readFile } from "node:fs/promises";
import path from "node:path";
import { fileURLToPath } from "node:url";
import { NATIVE_I18N_LOCALES } from "./native-app-i18n.ts";
const HERE = path.dirname(fileURLToPath(import.meta.url));
const ROOT = path.resolve(HERE, "..");
const RESOURCE_ROOT = path.join(ROOT, "apps", "android", "app", "src", "main", "res");
const SOURCE_ROOT = path.join(ROOT, "apps", "android", "app", "src", "main");
const ANDROID_QUALIFIERS: Record<string, string> = {
id: "in",
"zh-CN": "zh-rCN",
"zh-TW": "zh-rTW",
"pt-BR": "pt-rBR",
"ja-JP": "ja",
};
const localeDirectory = (locale: string) => `values-${ANDROID_QUALIFIERS[locale] ?? locale}`;
const LOCALES = ["values", ...NATIVE_I18N_LOCALES.map(localeDirectory)] as const;
const STRING_RE = /<string\s+name="([A-Za-z0-9_]+)"[^>]*>([\s\S]*?)<\/string>/gu;
const FORMAT_RE = /%\d+\$[a-z]/giu;
const INVALID_APOSTROPHE_RE = /(?:&apos;|(?<!\\)')/u;
async function readStrings(locale: string): Promise<Map<string, string>> {
const source = await readFile(path.join(RESOURCE_ROOT, locale, "strings.xml"), "utf8");
return new Map(
[...source.matchAll(STRING_RE)]
.map((match) => [match[1], match[2]] as const)
.filter((entry): entry is readonly [string, string] => Boolean(entry[0] && entry[1])),
);
}
async function readAndroidSource(root = SOURCE_ROOT): Promise<string> {
const entries = await readdir(root, { withFileTypes: true });
const sources: string[] = [];
for (const entry of entries) {
const fullPath = path.join(root, entry.name);
if (entry.isDirectory()) {
if (fullPath.startsWith(`${RESOURCE_ROOT}${path.sep}values`)) {
continue;
}
sources.push(await readAndroidSource(fullPath));
continue;
}
if (entry.isFile() && /\.(?:kt|kts|xml)$/u.test(entry.name)) {
sources.push(await readFile(fullPath, "utf8"));
}
}
return sources.join("\n");
}
function findInvalidResourceSyntax(strings: Map<string, string>): string[] {
return [...strings]
.filter(([, value]) => {
const trimmed = value.trim();
const isQuoted = trimmed.startsWith('"') && trimmed.endsWith('"');
return !isQuoted && INVALID_APOSTROPHE_RE.test(trimmed);
})
.map(([key]) => key);
}
export async function checkAndroidAppI18n() {
const [source, localeStrings] = await Promise.all([
readAndroidSource(),
Promise.all(LOCALES.map(readStrings)),
]);
const [base, ...translations] = localeStrings;
const baseKeys = new Set(base.keys());
const problems = translations.flatMap((strings, index) => {
const locale = NATIVE_I18N_LOCALES[index];
const keys = new Set(strings.keys());
const placeholderMismatches = [...base].flatMap(([key, sourceValue]) => {
const translatedValue = strings.get(key);
if (!translatedValue) {
return [];
}
const expected = [...sourceValue.matchAll(FORMAT_RE)].map((match) => match[0]).toSorted();
const actual = [...translatedValue.matchAll(FORMAT_RE)].map((match) => match[0]).toSorted();
return expected.join("\u0000") === actual.join("\u0000") ? [] : [key];
});
return [
[`${locale} missing`, [...baseKeys].filter((key) => !keys.has(key))],
[`${locale} extra`, [...keys].filter((key) => !baseKeys.has(key))],
[`${locale} placeholders`, placeholderMismatches],
[`${locale} syntax`, findInvalidResourceSyntax(strings)],
] as const;
});
problems.push(["English syntax", findInvalidResourceSyntax(base)]);
const unusedBaseKeys = [...baseKeys].filter(
(key) => !source.includes(`R.string.${key}`) && !source.includes(`@string/${key}`),
);
problems.push(["English unused", unusedBaseKeys]);
if (problems.some(([, keys]) => keys.length)) {
throw new Error(
[
"Android app i18n resources are out of sync.",
...problems.map(([label, keys]) => `${label}=${keys.join(",") || "none"}`),
].join("\n"),
);
}
process.stdout.write(
`android-app-i18n: keys=${baseKeys.size} locales=${NATIVE_I18N_LOCALES.join(",")}\n`,
);
}
if (process.argv[1] && import.meta.url === `file://${path.resolve(process.argv[1])}`) {
const [command] = process.argv.slice(2);
if (command !== "check") {
throw new Error("usage: node --import tsx scripts/android-app-i18n.ts check");
}
await checkAndroidAppI18n();
}