diff --git a/docs/cookbook/adding-a-package.i18n.yaml b/docs/cookbook/adding-a-package.i18n.yaml index fd7081a31c..5fdc926b52 100644 --- a/docs/cookbook/adding-a-package.i18n.yaml +++ b/docs/cookbook/adding-a-package.i18n.yaml @@ -21,8 +21,8 @@ en: 0894bd9f35430753 zh: 2d28090e71134edd /cookbook-adding-a-workspace-package/5-add-optional-plugin-display-metadata: - en: 6afc96ff6d2915a0 - zh: 01934cb5f6ddf089 + en: bf6a19c236cb00e3 + zh: 4f0d62de5466112f /cookbook-adding-a-workspace-package/6-verify: en: 80c7fb90b1175aae zh: 2ba37962dbc57299 diff --git a/docs/cookbook/adding-a-package.md b/docs/cookbook/adding-a-package.md index 1cb656b0ec..a0328ccf8a 100644 --- a/docs/cookbook/adding-a-package.md +++ b/docs/cookbook/adding-a-package.md @@ -136,7 +136,7 @@ Merge these entries into `package.json`, retaining existing runtime exports and } ``` -Keep language files together in `locale/`, with `en.json` as the discovery entry. Fields are optional; present values must be non-empty strings. English `meta.title` and `meta.description` use sentence case: capitalize only the first word, proper nouns, and product names, as in `Git worktrees` ([rule](../../.agents/skills/dsh-prose-standard/SKILL.md#required-coverage-by-prose-location)). Missing files or fields permit fallback, while malformed JSON or invalid fields produce a per-plugin diagnostic. First-party packages and plugin templates must provide `ja.json` covering every field present in `en.json` or `zh.json`, preserving placeholders; detail paths may point to the existing English document. Run `pnpm run check:i18n` to verify metadata, locale-owned display maps, and UI dictionary completeness; these checks also run in `check:all`, CI static checks, and hygiene. +Keep language files together in `locale/`, with `en.json` as the discovery entry. Fields are optional; present values must be non-empty strings. English `meta.title` and `meta.description` use sentence case: capitalize only the first word, proper nouns, and product names, as in `Git worktrees` ([rule](../../.agents/skills/dsh-prose-standard/SKILL.md#required-coverage-by-prose-location)). Missing files or fields permit fallback, while malformed JSON or invalid fields produce a per-plugin diagnostic. First-party packages and plugin templates must provide `ja.json` covering every field present in `en.json` or `zh.json`, preserving placeholders; detail paths may point to the existing English document. Run `pnpm run check:i18n` to verify JSON metadata and UI dictionary completeness; these checks also run in `check:all`, CI static checks, and hygiene. Fields fall back independently before view-specific name formatting, using the existing locale language chain first: diff --git a/docs/cookbook/adding-a-package.zh.md b/docs/cookbook/adding-a-package.zh.md index 88d92413f4..49fa2d0d01 100644 --- a/docs/cookbook/adding-a-package.zh.md +++ b/docs/cookbook/adding-a-package.zh.md @@ -136,7 +136,7 @@ Append-only, prefix-stable, replacing, or independent behavior, including the ex } ``` -语言文件统一放在 `locale/`,并保留 `en.json` 作为发现入口。字段可选,填写时必须是非空字符串。英文 `meta.title` 和 `meta.description` 使用 sentence case:只大写首个单词、专有名词和产品名,例如 `Git worktrees`([rule](../../.agents/skills/dsh-prose-standard/SKILL.md#required-coverage-by-prose-location))。文件或字段缺失时允许回退,JSON 损坏或字段无效时显示单插件诊断。 仓库内的包和插件模板必须提供 `ja.json`,覆盖 `en.json` 或 `zh.json` 中的全部字段并保留占位符;详情路径可指向现有英文文档。运行 `pnpm run check:i18n` 检查元数据、locale 所有的展示文案映射和 UI 字典完整性;这些检查也接入 `check:all`、CI 静态检查和 hygiene。 +语言文件统一放在 `locale/`,并保留 `en.json` 作为发现入口。字段可选,填写时必须是非空字符串。英文 `meta.title` 和 `meta.description` 使用 sentence case:只大写首个单词、专有名词和产品名,例如 `Git worktrees`([rule](../../.agents/skills/dsh-prose-standard/SKILL.md#required-coverage-by-prose-location))。文件或字段缺失时允许回退,JSON 损坏或字段无效时显示单插件诊断。 仓库内的包和插件模板必须提供 `ja.json`,覆盖 `en.json` 或 `zh.json` 中的全部字段并保留占位符;详情路径可指向现有英文文档。运行 `pnpm run check:i18n` 检查 JSON 元数据和 UI 字典完整性;这些检查也接入 `check:all`、CI 静态检查和 hygiene。 各字段先独立回退,再按页面规则格式化技术名称;回退优先经过现有 locale 语言链: diff --git a/package.json b/package.json index 3c15c22fef..b2dc54bd77 100644 --- a/package.json +++ b/package.json @@ -148,7 +148,6 @@ "verify-client-packages": "tsx scripts/verify-client-packages.ts", "check:i18n": "tsx scripts/run-gates.ts i18n", "verify-locale-metadata": "tsx scripts/verify-locale-metadata.ts", - "verify-localized-text": "tsx scripts/verify-localized-text.ts", "verify-client-ui-i18n": "tsx scripts/verify-client-ui-i18n.ts", "verify-client-route-resolution": "tsx scripts/verify-client-route-resolution.ts", "verify-no-bare-dispatcher": "tsx scripts/verify-no-bare-dispatcher.ts", diff --git a/scripts/run-gates.spec.ts b/scripts/run-gates.spec.ts index 51a79717cb..40ee62f364 100644 --- a/scripts/run-gates.spec.ts +++ b/scripts/run-gates.spec.ts @@ -370,12 +370,21 @@ describe('gate graph validation', () => { expect(ids).toEqual([ 'rescope-vendor', 'publint', 'constraints', 'default-product-isolation', 'product-use', 'official-bundle-catalog', 'provider-data', 'package-dependencies', 'application-entrypoints', 'dsh-package-licenses', 'node-next-types', - 'optional-dependency-imports', 'client-packages', 'locale-metadata', 'localized-text', 'locale-dictionaries', 'client-ui-i18n', 'client-route-resolution', 'no-bare-dispatcher', + 'optional-dependency-imports', 'client-packages', 'locale-metadata', 'locale-dictionaries', 'client-ui-i18n', 'client-route-resolution', 'no-bare-dispatcher', 'plugin-record-callers', 'no-unknown-casts', 'no-top-level-await', 'cordis-config', 'runtime-closure', ]) }) + it('includes metadata and dictionary completeness in local and CI aggregates', () => { + for (const mode of ['i18n', 'check-all', 'ci-static', 'hygiene'] as const) { + const ids = withPnpmEntrypoint(() => gatesForMode(mode).map(gate => gate.id)) + expect(ids).toEqual(expect.arrayContaining(['locale-metadata', 'locale-dictionaries'])) + } + expect(withPnpmEntrypoint(() => gatesForMode('i18n').map(gate => gate.id))) + .toEqual(['locale-metadata', 'locale-dictionaries']) + }) + it('caps the local hygiene aggregate at eight workers', () => { const ids = withPnpmEntrypoint(() => gatesForMode('hygiene').map(subject => subject.id)) diff --git a/scripts/run-gates.ts b/scripts/run-gates.ts index 509179674a..65e2d13d75 100644 --- a/scripts/run-gates.ts +++ b/scripts/run-gates.ts @@ -392,7 +392,6 @@ function ciSharedStaticGates(): Gate[] { function i18nGates(): Gate[] { return [ pnpmScript('locale-metadata', 'verify-locale-metadata', { label: 'Japanese plugin metadata' }), - pnpmScript('localized-text', 'verify-localized-text', { label: 'localized display text' }), pnpmExec('locale-dictionaries', ['vitest', 'run', 'scripts/locale-dictionary-parity.spec.ts'], { label: 'locale dictionaries' }), ] } diff --git a/scripts/verify-localized-text.spec.ts b/scripts/verify-localized-text.spec.ts deleted file mode 100644 index e97a01a3c8..0000000000 --- a/scripts/verify-localized-text.spec.ts +++ /dev/null @@ -1,45 +0,0 @@ -/** First-party display translations cannot silently omit a language or bypass their locale owner. */ -import { expect, it } from 'vitest' -import { localizedTextProblems } from './verify-localized-text.ts' -import { gatesForMode } from './run-gates.ts' - -it.each(['en', 'zh', 'ja'])('rejects a missing %s translation', (missing) => { - const fields = ['en', 'zh', 'ja'].filter(language => language !== missing).map(language => `${language}: 'text'`).join(',') - expect(localizedTextProblems('packages/demo/plugin/src/locales.ts', `const display = { ${fields} }`).join('\n')) - .toContain(`missing ${missing}`) -}) - -it('accepts complete locale-owned prose and dictionary references in registration code', () => { - expect(localizedTextProblems('packages/demo/plugin/src/locales.ts', "const text = { en: 'Text', zh: '文本', ja: '文' }")).toEqual([]) - expect(localizedTextProblems('packages/demo/plugin/src/index.ts', 'register(NS, { en, zh, ja })')).toEqual([]) -}) - -it('rejects inline display copy, including generated-looking files', () => { - const source = "const text = { en: 'Text', zh: '文本', ja: '文' }" - for (const file of ['index.ts', 'copy.generated.ts']) { - expect(localizedTextProblems(`packages/demo/plugin/src/${file}`, source).join('\n')).toContain('owning locales file') - } -}) - -it('admits only the runtime baseline definition and still checks other maps in the same file', () => { - const file = 'packages/client/locale/src/client/index.ts' - expect(localizedTextProblems(file, 'const BUILT_IN_LOCALE_METADATA = { en: {}, zh: {} } as const satisfies Metadata')).toEqual([]) - expect(localizedTextProblems(file, 'const other = { en: dictionary, zh: dictionary }').join('\n')).toContain('missing ja') -}) - -it('checks dynamic display text maps', () => { - expect(localizedTextProblems('packages/demo/plugin/src/locales.ts', 'const display = { en: format(reason), zh: format(reason) }') - .join('\n')).toContain('missing ja') -}) - -it('keeps completeness checks in local and CI aggregates', () => { - for (const mode of ['i18n', 'check-all', 'ci-static', 'hygiene'] as const) { - const ids = gatesForMode(mode).map(gate => gate.id) - expect(ids).toEqual(expect.arrayContaining(['locale-metadata', 'localized-text', 'locale-dictionaries'])) - } -}) - -it('rejects English-only display maps instead of allowing an implicit fallback', () => { - expect(localizedTextProblems('packages/demo/plugin/src/locales.ts', "const display = { en: 'Text' }").join('\n')) - .toContain('missing ja') -}) diff --git a/scripts/verify-localized-text.ts b/scripts/verify-localized-text.ts deleted file mode 100644 index 85f3f86d81..0000000000 --- a/scripts/verify-localized-text.ts +++ /dev/null @@ -1,59 +0,0 @@ -/** Keep first-party localized-text maps complete and their prose in locale-owned files. */ -import { globSync, readFileSync } from 'node:fs' -import { resolve } from 'node:path' -import ts from 'typescript' - -/** - * Inspect source translation maps, including maps outside Client namespace dictionaries. - * @param file - repository-relative source file. - * @param text - TypeScript or TSX source. - * @returns incomplete-map and misplaced-copy diagnostics. - */ -export function localizedTextProblems(file: string, text: string): string[] { - const source = ts.createSourceFile(file, text, ts.ScriptTarget.ESNext, true) - const problems: string[] = [] - const visit = (node: ts.Node): void => { - if (ts.isObjectLiteralExpression(node)) { - const fields = new Map() - for (const prop of node.properties) { - if (ts.isShorthandPropertyAssignment(prop)) fields.set(prop.name.text, prop.name) - else if (ts.isPropertyAssignment(prop) && (ts.isIdentifier(prop.name) || ts.isStringLiteral(prop.name))) { - fields.set(prop.name.text, prop.initializer) - } - } - const languages = ['en', 'zh', 'ja'].filter(language => fields.has(language)) - const literal = [...fields].some(([language, value]) => - languages.includes(language) && (ts.isStringLiteralLike(value) || ts.isTemplateExpression(value))) - if (languages.length >= 2 || literal) { - // Runtime baseline definitions are extended by addLanguage; these are not translations. - let declaration = node.parent - while (ts.isAsExpression(declaration) || ts.isSatisfiesExpression(declaration)) declaration = declaration.parent - const baseline = file === 'packages/client/locale/src/client/index.ts' - && ts.isVariableDeclaration(declaration) && declaration.name.getText(source) === 'BUILT_IN_LOCALE_METADATA' - if (!baseline) { - const site = `${file}:${source.getLineAndCharacterOfPosition(node.getStart(source)).line + 1}` - for (const language of ['en', 'zh', 'ja']) { - if (!fields.has(language)) problems.push(`${site}: localized text is missing ${language}`) - } - const prose = [...fields.values()].some(value => ts.isStringLiteralLike(value) || ts.isTemplateExpression(value)) - const owner = /(?:^|\/)locales(?:\.tsx?$|\/)/u.test(file) - // This generated file derives from JSON metadata covered by verify-locale-metadata. - const metadata = file === 'packages/boot/app-boot/src/official-bundles.generated.ts' - if (prose && !owner && !metadata) problems.push(`${site}: move translated prose into an owning locales file`) - } - } - } - ts.forEachChild(node, visit) - } - visit(source) - return problems -} - -if (import.meta.filename === resolve(process.argv[1] ?? '')) { - const files = globSync('packages/*/*/src/**/*.{ts,tsx}').filter(file => !file.endsWith('.d.ts')) - if (files.length === 0) throw new Error('verify-localized-text: no package sources found') - const problems = files.flatMap(file => localizedTextProblems(file.replaceAll('\\', '/'), readFileSync(file, 'utf8'))) - for (const problem of problems) console.error(problem) - if (problems.length > 0) process.exitCode = 1 - else console.log(`verify-localized-text: ${files.length} sources have complete, locale-owned translation maps.`) -}