

























@@ -2,13 +2,10 @@ import { existsSync } from "node:fs";
22import { readFile } from "node:fs/promises";
33import path from "node:path";
44import { fileURLToPath, pathToFileURL } from "node:url";
5-import type { TranslationMap } from "../ui/src/i18n/lib/types.ts";
6576const ROOT = path.resolve(fileURLToPath(new URL("..", import.meta.url)));
87const I18N_ASSETS_DIR = path.join(ROOT, "ui/src/i18n/.i18n");
9-const LOCALES_DIR = path.join(ROOT, "ui/src/i18n/locales");
108const RAW_COPY_BASELINE_PATH = path.join(I18N_ASSETS_DIR, "raw-copy-baseline.json");
11-const SOURCE_LOCALE_PATH = path.join(LOCALES_DIR, "en.ts");
129const DEFAULT_TOP = 10;
1310const LOCALE_LABELS: Record<string, string> = {
1411ar: "Arabic",
@@ -91,7 +88,6 @@ export type RawCopySummary = {
9188export type LocaleSummary = {
9289fallbackKeysInScope: string[];
9390meta: LocaleMeta;
94-sameAsEnglishKeys: string[];
9591};
96929793type ReportInput = {
@@ -193,29 +189,6 @@ function normalizeToken(value: string) {
193189return value.trim().toLowerCase();
194190}
195191196-export function flattenTranslations(
197-value: TranslationMap,
198-prefix = "",
199-out = new Map<string, string>(),
200-) {
201-for (const [key, nested] of Object.entries(value)) {
202-const fullKey = prefix ? `${prefix}.${key}` : key;
203-if (typeof nested === "string") {
204-out.set(fullKey, nested);
205-continue;
206-}
207-flattenTranslations(nested, fullKey, out);
208-}
209-return out;
210-}
211-212-export function computeSameAsEnglishKeys(source: Map<string, string>, target: Map<string, string>) {
213-return [...target.entries()]
214-.filter(([key, value]) => source.get(key) === value)
215-.map(([key]) => key)
216-.toSorted();
217-}
218-219192export function filterTranslationKeysBySurface(keys: string[], surface?: string) {
220193if (!surface) {
221194return keys;
@@ -275,24 +248,14 @@ function formatIssueLines(input: ReportInput) {
275248return lines;
276249}
277250278-if (
279-input.locale.fallbackKeysInScope.length === 0 &&
280-input.locale.sameAsEnglishKeys.length === 0
281-) {
251+if (input.locale.fallbackKeysInScope.length === 0) {
282252lines.push(` No ${input.locale.meta.locale} locale problems found in this scope.`);
283253return lines;
284254}
285255286-if (input.locale.fallbackKeysInScope.length > 0) {
287-lines.push(
288-` ${input.locale.meta.locale} has ${formatMissingKeyCount(input.locale.fallbackKeysInScope.length)}.`,
289-);
290-}
291-if (input.locale.sameAsEnglishKeys.length > 0) {
292-lines.push(
293-` ${formatSameAsEnglishIssue(input.locale.sameAsEnglishKeys.length, input.locale.meta.locale)}.`,
294-);
295-}
256+lines.push(
257+` ${input.locale.meta.locale} has ${formatMissingKeyCount(input.locale.fallbackKeysInScope.length)}.`,
258+);
296259return lines;
297260}
298261@@ -322,13 +285,6 @@ function formatFallbackCount(count: number) {
322285return `${count} ${count === 1 ? "fallback" : "fallbacks"}`;
323286}
324287325-function formatSameAsEnglishIssue(count: number, locale: string) {
326-if (count === 1) {
327-return `1 ${locale} translation still matches English and needs review`;
328-}
329-return `${count} ${locale} translations still match English and need review`;
330-}
331-332288function formatSurfaceLabel(surface?: string) {
333289if (!surface) {
334290return "all Control UI";
@@ -369,20 +325,6 @@ async function loadLocaleMeta(locale: string): Promise<LocaleMeta> {
369325return JSON.parse(await readFile(metaPath, "utf8")) as LocaleMeta;
370326}
371327372-async function loadLocaleMap(locale: string): Promise<TranslationMap> {
373-const filePath = locale === "en" ? SOURCE_LOCALE_PATH : path.join(LOCALES_DIR, `${locale}.ts`);
374-if (!existsSync(filePath)) {
375-throw new Error(`unknown locale file: ${locale}`);
376-}
377-const exportName = locale.replaceAll("-", "_");
378-const mod = (await import(pathToFileURL(filePath).href)) as Record<string, TranslationMap>;
379-const map = mod[exportName];
380-if (!map) {
381-throw new Error(`locale ${locale} does not export ${exportName}`);
382-}
383-return map;
384-}
385-386328async function buildReport(args: ReportArgs) {
387329const baseline = await loadRawCopyBaseline();
388330const entries = filterRawCopyEntries(baseline.entries, args.surface);
@@ -392,18 +334,10 @@ async function buildReport(args: ReportArgs) {
392334};
393335394336if (args.locale) {
395-const [meta, source, target] = await Promise.all([
396-loadLocaleMeta(args.locale),
397-loadLocaleMap("en"),
398-loadLocaleMap(args.locale),
399-]);
337+const meta = await loadLocaleMeta(args.locale);
400338input.locale = {
401339fallbackKeysInScope: filterTranslationKeysBySurface(meta.fallbackKeys, args.surface),
402340 meta,
403-sameAsEnglishKeys: filterTranslationKeysBySurface(
404-computeSameAsEnglishKeys(flattenTranslations(source), flattenTranslations(target)),
405-args.surface,
406-),
407341};
408342}
409343此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。