diff --git a/.github/workflows/i18n-update-website.yaml b/.github/workflows/i18n-update-website.yaml index edb51940206..22569f43290 100644 --- a/.github/workflows/i18n-update-website.yaml +++ b/.github/workflows/i18n-update-website.yaml @@ -2,10 +2,20 @@ name: 'i18n: Update Website' on: + push: + branches: [main] + paths: + - 'apps/website/src/locales/en/*.json' + - 'apps/website/src/config/locales.ts' + - 'apps/website/src/config/translation.ts' + - 'scripts/i18n/config.ts' + schedule: + - cron: '17 10 * * *' workflow_dispatch: permissions: contents: read + pull-requests: read concurrency: group: i18n-update-website-${{ github.ref }} @@ -13,8 +23,9 @@ concurrency: jobs: update-locales: - if: github.ref_type == 'branch' + if: github.repository == 'Comfy-Org/ComfyUI_frontend' && github.ref_type == 'branch' runs-on: ubuntu-latest + timeout-minutes: 30 steps: - name: Checkout repository uses: actions/checkout@v7 @@ -27,7 +38,31 @@ jobs: - name: Setup ComfyUI Frontend uses: ./.github/actions/setup-frontend + - name: Build on the open translation PR + id: base + if: github.ref_name == 'main' + env: + GH_TOKEN: ${{ github.token }} + TRANSLATION_BRANCH: i18n/website-locales + run: | + set -euo pipefail + echo "main_sha=$(git rev-parse HEAD)" >> "$GITHUB_OUTPUT" + open_pr=$(gh api "repos/$GITHUB_REPOSITORY/pulls?state=open&head=$GITHUB_REPOSITORY_OWNER:$TRANSLATION_BRANCH" \ + --jq '.[0].html_url // empty') + echo "open_pr=$open_pr" >> "$GITHUB_OUTPUT" + if [ -z "$open_pr" ]; then exit 0; fi + git fetch --no-tags origin "refs/heads/$TRANSLATION_BRANCH" + echo "branch_sha=$(git rev-parse FETCH_HEAD)" >> "$GITHUB_OUTPUT" + if git -c user.name=github-actions -c user.email=github-actions@github.com \ + merge --no-edit FETCH_HEAD; then + echo "merged=true" >> "$GITHUB_OUTPUT" + else + git merge --abort + fi + - name: Update translations + id: translate + continue-on-error: true run: pnpm --filter @comfyorg/website locale env: OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }} @@ -39,16 +74,54 @@ jobs: if git diff --cached --quiet; then exit 0; fi ./scripts/cicd/check-json.sh git -c user.name=github-actions -c user.email=github-actions@github.com \ - commit -m 'Update website locales' + commit -m 'fix(website): update locale catalogs' echo "committed=true" >> "$GITHUB_OUTPUT" - # Only this step sees the push token: the steps above run scripts from - # the dispatched branch - - name: Push updated locales - if: steps.commit.outputs.committed == 'true' + - name: Publish updated locales + if: steps.commit.outputs.committed == 'true' || github.ref_name == 'main' env: - TARGET_BRANCH: ${{ github.ref_name }} - PR_GH_TOKEN: ${{ secrets.PR_GH_TOKEN }} + GH_TOKEN: ${{ secrets.PR_GH_TOKEN }} + SOURCE_BRANCH: ${{ github.ref_name }} + TRANSLATION_BRANCH: i18n/website-locales + COMMITTED: ${{ steps.commit.outputs.committed }} + MAIN_SHA: ${{ steps.base.outputs.main_sha }} + OPEN_PR: ${{ steps.base.outputs.open_pr }} + BRANCH_SHA: ${{ steps.base.outputs.branch_sha }} + MERGED: ${{ steps.base.outputs.merged }} + RUN_URL: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }} + run: | + set -euo pipefail + remote="https://x-access-token:${GH_TOKEN}@github.com/${GITHUB_REPOSITORY}.git" + if [ "$SOURCE_BRANCH" != main ]; then + git push "$remote" "HEAD:refs/heads/$SOURCE_BRANCH" + exit 0 + fi + if git diff --quiet "$MAIN_SHA" HEAD; then + if [ -n "$OPEN_PR" ]; then + gh pr close "$OPEN_PR" --delete-branch --comment 'Main already has every translation on this branch.' + fi + exit 0 + fi + if [ "$COMMITTED" != true ] && [ "$MERGED" = true ]; then + echo "No new translations for $OPEN_PR" + exit 0 + fi + lease=--force + if [ -n "$BRANCH_SHA" ]; then + lease="--force-with-lease=refs/heads/$TRANSLATION_BRANCH:$BRANCH_SHA" + fi + git push "$lease" "$remote" "HEAD:refs/heads/$TRANSLATION_BRANCH" + if [ -n "$OPEN_PR" ]; then + echo "Updated $OPEN_PR" + exit 0 + fi + body=$(printf '## Summary\n\nTranslations of new or changed English website copy, generated by [this workflow run](%s).\n\nLater runs merge main into this branch and translate only what changed, so translations edited here are kept.\n' "$RUN_URL") + gh pr create --repo "$GITHUB_REPOSITORY" --base main --head "$TRANSLATION_BRANCH" \ + --title 'fix(website): update locale catalogs' --body "$body" \ + --label area:i18n --assignee benceruleanlu + + - name: Fail if translation did not finish + if: steps.translate.outcome == 'failure' run: | - git push "https://x-access-token:${PR_GH_TOKEN}@github.com/${GITHUB_REPOSITORY}.git" \ - "HEAD:refs/heads/$TARGET_BRANCH" + echo "::error::Website translation did not finish; the Update translations step lists what failed." + exit 1 diff --git a/apps/website/AGENTS.md b/apps/website/AGENTS.md index 39f98f532e7..20023d6cc7a 100644 --- a/apps/website/AGENTS.md +++ b/apps/website/AGENTS.md @@ -36,8 +36,11 @@ file wins. These root rules do not apply here: vue-i18n message syntax), not in the app's root `src/locales/`. Read it with the request-bound `Astro.locals.t` in Astro or `translationsFor(locale).t` in Vue and TypeScript; never fill a placeholder with `.replace`. Write a literal - `@`, `|`, `{` or `}` as `{'@'}`, `{'|'}`, `{'{'}` or `{'}'}`. Add `en` and - `zh-CN` values for every new string. See the README's Localization section. + `@`, `|`, `{` or `}` as `{'@'}`, `{'|'}`, `{'{'}` or `{'}'}`. Write new and + changed copy in `en/main.json` only. Do not edit another locale's file except + for the excluded legal namespaces in `src/config/translation.ts`: a workflow + translates eligible English changes on main into a PR, and missing strings + render in English until it merges. See the README's Localization section. - The dev server is `pnpm --filter @comfyorg/website dev` on `http://localhost:4321`, not `pnpm dev` on 5173. The root `/verify-visually` command points at the wrong server for this site. diff --git a/apps/website/README.md b/apps/website/README.md index f69967340a2..d4f4ed66044 100644 --- a/apps/website/README.md +++ b/apps/website/README.md @@ -53,16 +53,15 @@ as the application's `src/locales/` at the repository root: API. Astro middleware binds `Astro.locals.t` to the request locale. In Vue and TypeScript, bind once with `translationsFor(locale).t`; each locale has its own composer because the site renders locales concurrently. Missing messages fall -back to English. The catalog test compiles every message and checks that each -eligible English message has Chinese copy. +back to English. The catalog test compiles every message in every locale. `main.json` is the catalog for each locale. Keep feature copy grouped under a nested feature key. -Add new English copy to the English catalog; translated copy lives in the -matching file under each locale. Every eligible English message requires a -Chinese entry. Excluded namespaces use English fallback when no translation -exists. The catalog tests enforce this distinction. +Write new and changed copy in the English catalog only. Do not add or edit +eligible copy in other locales by hand: the generation workflow below +translates it after it merges, and until then those strings render in English. +People maintain the excluded namespaces listed below. Catalog files use two-space JSON indentation and a final newline. Legal and content pages render their sections in the order they appear in the catalog, so keep `en/main.json` in document order and never sort its keys. @@ -100,6 +99,15 @@ have no `/ja/` route yet. Generation never enables routes or indexing. ### Generating translations +The `i18n: Update Website` workflow runs when English catalogs or translation +config change on main, and daily. It opens or updates one +`fix(website): update locale catalogs` PR from the `i18n/website-locales` +branch. While that PR is open, each run merges main into the branch and +translates only what changed, so translations edited on the branch are kept. +When the branch conflicts with main, the run regenerates it from main instead. +Running the workflow by hand on another branch commits the translations to that +branch instead. + Inside this package, run `pnpm locale:check` for an offline preflight, or `pnpm locale` with `OPENAI_API_KEY` to translate eligible missing or changed copy. Both scripts call the shared CLI in `scripts/i18n/update-locales.ts` with @@ -114,8 +122,11 @@ of the English last generated. Its `knownViolations` field lists accepted protected-token violations as JSON-encoded key paths, such as `["cloud","reason","1","title"]`. Use a clone with full history: if the recorded blob is missing, `locale:check` warns and skips change detection and token -validation for that file, and `pnpm locale` fails. When translation of an entry file fails, -its English, locale catalogs and manifest entry keep their previous contents. +validation for that file, and `pnpm locale` fails. When a translation request +for an entry file throws, such as an HTTP or network error, its English, locale +catalogs and manifest entry keep their previous contents. Strings the provider +defers or the model keeps getting wrong are left out and retried on the next +run. Commit the generated English catalog, locale catalogs and manifest together. If you edit any of them after generation, run `pnpm locale` again before diff --git a/apps/website/src/config/translation.ts b/apps/website/src/config/translation.ts index 40dcdd058ca..9e7db5c8c2b 100644 --- a/apps/website/src/config/translation.ts +++ b/apps/website/src/config/translation.ts @@ -12,7 +12,7 @@ const languages = { { name: string; guidance?: string } > -export const translationExclusions = [ +const translationExclusions = [ 'tos', 'enterprise-msa', 'privacy', diff --git a/apps/website/src/i18n/translations.test.ts b/apps/website/src/i18n/translations.test.ts index ad8eb9cb27d..5be9cc4c043 100644 --- a/apps/website/src/i18n/translations.test.ts +++ b/apps/website/src/i18n/translations.test.ts @@ -3,7 +3,6 @@ import { describe, expect, it } from 'vitest' import type { Locale } from '@/config/locales' import { LOCALE_CODES } from '@/config/locales' -import { translationExclusions } from '@/config/translation' import { translationsFor } from './translations' type Catalog = { [key: string]: string | Catalog } @@ -113,22 +112,6 @@ describe('site translations', () => { }) describe.for(catalogs)('$file catalog', ({ english, messages }) => { - it('includes Chinese copy for every eligible English message', () => { - const chinese = messages['zh-CN'] ?? {} - const chineseKeys = new Set(leafMessages(chinese).map(([key]) => key)) - const missing = leafMessages(english) - .map(([key]) => key) - .filter( - (key) => - !chineseKeys.has(key) && - !translationExclusions.some( - (prefix) => key === prefix || key.startsWith(`${prefix}.`) - ) - ) - - expect(missing).toEqual([]) - }) - it.for(LOCALE_CODES)('renders every %s message', (locale: Locale) => { const i18n = createI18n({ legacy: false, diff --git a/scripts/i18n/translate.test.ts b/scripts/i18n/translate.test.ts index 92d63e6abf2..d93ecb3110e 100644 --- a/scripts/i18n/translate.test.ts +++ b/scripts/i18n/translate.test.ts @@ -53,24 +53,39 @@ describe('translateLocaleItems', () => { ) ) } - const translations = await translateLocaleItems( + const { translated } = await translateLocaleItems( locale, items, flaky, translationConfig ) - expect(translations.get('1')).toBe('Bonjour {name}') + expect(translated.get('1')).toBe('Bonjour {name}') expect(calls).toBe(2) }) - it('fails after exhausting rounds when tokens stay corrupted', async () => { - const corrupting: TranslateBatch = (_batchLocale, batch) => + it('keeps passing translations and reports items still corrupted after the last round', async () => { + const corruptingGreeting: TranslateBatch = (_batchLocale, batch) => Promise.resolve( - Object.fromEntries(batch.map((item) => [item.id, 'Bonjour name'])) + Object.fromEntries( + batch.map((item) => [ + item.id, + item.id === '1' ? 'Bonjour name' : 'Titre' + ]) + ) ) - await expect( - translateLocaleItems(locale, items, corrupting, translationConfig) - ).rejects.toThrow(/failed for 1 strings/) + const { translated, untranslated } = await translateLocaleItems( + locale, + [ + ...items, + { id: '2', context: 'main.json: title', source: 'Title', preserve: [] } + ], + corruptingGreeting, + translationConfig + ) + expect(translated).toEqual(new Map([['2', 'Titre']])) + expect(untranslated.map(({ context }) => context)).toEqual([ + 'main.json: greeting' + ]) }) it('retries empty translations', async () => { @@ -83,13 +98,13 @@ describe('translateLocaleItems', () => { ) ) } - const translations = await translateLocaleItems( + const { translated } = await translateLocaleItems( locale, items, blankFirst, translationConfig ) - expect(translations.get('1')).toBe('Bonjour {name}') + expect(translated.get('1')).toBe('Bonjour {name}') expect(calls).toBe(2) }) @@ -111,11 +126,11 @@ describe('translateLocaleItems', () => { inFlight-- return Object.fromEntries(batch.map((item) => [item.id, `t${item.id}`])) } - const translations = await translateLocaleItems(locale, sixItems, gated, { + const { translated } = await translateLocaleItems(locale, sixItems, gated, { ...translationConfig, requestConcurrency: 2 }) - expect(translations.size).toBe(6) + expect(translated.size).toBe(6) expect(maxInFlight).toBe(2) }) @@ -134,13 +149,13 @@ describe('translateLocaleItems', () => { let call = 0 const crossTalking: TranslateBatch = () => Promise.resolve(responses[call++] ?? {}) - const translations = await translateLocaleItems( + const { translated } = await translateLocaleItems( locale, threeItems, crossTalking, translationConfig ) - expect(translations.get('3')).toBe('ok3') + expect(translated.get('3')).toBe('ok3') }) it('sends a retry note naming the violation on later rounds', async () => { @@ -193,7 +208,7 @@ describe('translateLocaleItems', () => { ) } - const translations = await translateLocaleItems( + const { translated } = await translateLocaleItems( locale, [docsLink], correctsOnRetry, @@ -206,7 +221,7 @@ describe('translateLocaleItems', () => { } ) - expect(translations).toEqual(new Map([['1', accepted]])) + expect(translated).toEqual(new Map([['1', accepted]])) expect(requests).toEqual([[docsLink], [{ ...docsLink, retryNote }]]) } ) diff --git a/scripts/i18n/translate.ts b/scripts/i18n/translate.ts index 2fcd042fb5d..96e564491f7 100644 --- a/scripts/i18n/translate.ts +++ b/scripts/i18n/translate.ts @@ -391,8 +391,11 @@ export async function translateLocaleItems( | 'maxTranslationRounds' | 'strictProtectedTokens' > -): Promise> { - const results = new Map() +): Promise<{ + translated: Map + untranslated: TranslationItem[] +}> { + const translated = new Map() let remaining = [...items] for ( @@ -414,11 +417,11 @@ export async function translateLocaleItems( return Object.entries(response).filter(([id]) => requested.has(id)) } ) - const translated = new Map(responses.flat()) + const responded = new Map(responses.flat()) const failed: TranslationItem[] = [] for (const item of remaining) { - const value = translated.get(item.id) + const value = responded.get(item.id) const errors = value === undefined ? ['no translation returned'] @@ -428,7 +431,7 @@ export async function translateLocaleItems( strict: config.strictProtectedTokens }) if (value !== undefined && errors.length === 0) { - results.set(item.id, value) + translated.set(item.id, value) } else { failed.push({ ...item, @@ -439,14 +442,5 @@ export async function translateLocaleItems( remaining = failed } - if (remaining.length > 0) { - const details = remaining - .map((item) => ` ${item.context}`) - .slice(0, 20) - .join('\n') - throw new Error( - `Translation into ${locale.code} failed for ${remaining.length} strings after ${config.maxTranslationRounds} attempts:\n${details}` - ) - } - return results + return { translated, untranslated: remaining } } diff --git a/scripts/i18n/update-locales.integration.test.ts b/scripts/i18n/update-locales.integration.test.ts index d9f78f02b3b..aca6b2ba38d 100644 --- a/scripts/i18n/update-locales.integration.test.ts +++ b/scripts/i18n/update-locales.integration.test.ts @@ -386,66 +386,88 @@ describe('failure isolation', () => { const aFiles = ['en/a.json', 'ja/a.json', 'zh-CN/a.json'] - it.for([ - { - label: 'the provider fails', - translator: () => - createTranslator( - undefined, - (locale, item) => - locale === 'zh-CN' && item.context.startsWith('a.json:') - ), - failures: ['zh-CN/a.json: provider unavailable'] - }, - { - label: 'every attempt corrupts a protected token', - translator: () => - createTranslator((locale, item) => - `[${locale}] ${item.source}`.replace(' {name}', '') - ), - failures: [ - 'ja/a.json: Translation into ja failed for 1 strings after 3 attempts', - 'zh-CN/a.json: Translation into zh-CN failed for 1 strings after 3 attempts' - ] - } - ])( - 'discards one entry file when $label while another file is written', - async ({ translator, failures }) => { - const repo = createTwoFileRepo() - const before = repo.readTree() - const recordedA = repo.blobId({ alpha: 'Alpha' }) + it('discards one entry file when the provider fails while another file is written', async () => { + const repo = createTwoFileRepo() + const before = repo.readTree() + const recordedA = repo.blobId({ alpha: 'Alpha' }) + const failingZhA = createTranslator( + undefined, + (locale, item) => locale === 'zh-CN' && item.context.startsWith('a.json:') + ) - const error = await repo.run(false, translator().translate).then( - () => undefined, - (rejection: unknown) => String(rejection) - ) + const error = await repo.run(false, failingZhA.translate).then( + () => undefined, + (rejection: unknown) => String(rejection) + ) - expect(error).toContain(`Translation failed for ${failures.length}`) - expect(error?.split('\n')).toEqual( - expect.arrayContaining( - failures.map((failure) => expect.stringContaining(failure)) - ) - ) - const after = repo.readTree() - expect(aFiles.map((file) => after[file])).toEqual( - aFiles.map((file) => before[file]) - ) - expect(after['ja/b.json']).toBe( - json({ delta: '[ja] Delta', gamma: 'ガンマ' }) - ) - expect(after['zh-CN/b.json']).toBe( - json({ delta: '[zh-CN] Delta', gamma: '伽马' }) - ) - expect(repo.readManifest()).toEqual({ - version: 1, - files: { - 'a.json': recordedA, - 'b.json': repo.blobId({ delta: 'Delta', gamma: 'Gamma' }) - }, - knownViolations: { 'a.json': ['["alpha"]'] } - }) + expect(error).toContain( + 'Translation failed for 1 locale files:\nzh-CN/a.json: provider unavailable' + ) + const after = repo.readTree() + expect(aFiles.map((file) => after[file])).toEqual( + aFiles.map((file) => before[file]) + ) + expect(after['ja/b.json']).toBe( + json({ delta: '[ja] Delta', gamma: 'ガンマ' }) + ) + expect(after['zh-CN/b.json']).toBe( + json({ delta: '[zh-CN] Delta', gamma: '伽马' }) + ) + expect(repo.readManifest()).toEqual({ + version: 1, + files: { + 'a.json': recordedA, + 'b.json': repo.blobId({ delta: 'Delta', gamma: 'Gamma' }) + }, + knownViolations: { 'a.json': ['["alpha"]'] } + }) + }) +}) + +describe('strings with no valid translation after every attempt', () => { + it('leaves out strings one locale rejects and retries only those next run', async () => { + const repo = createCatalogRepo() + repo.recordEnglish({ 'main.json': { greeting: 'Hi {name}' } }) + const english = { + greeting: 'Hello {name}', + steps: ['Step {name}', 'Plain'], + title: 'Title' } - ) + repo.writeCatalog('en/main.json', english) + repo.writeCatalog('ja/main.json', { greeting: 'やあ {name}' }) + repo.writeCatalog('zh-CN/main.json', { greeting: '嗨 {name}' }) + const corruptingJapanese = createTranslator((locale, item) => + locale === 'ja' + ? `[ja] ${item.source}`.replace(' {name}', '') + : `[${locale}] ${item.source}` + ) + + const error = await repo.run(false, corruptingJapanese.translate).then( + () => undefined, + (rejection: unknown) => String(rejection) + ) + + expect(error).toContain( + '2 strings had no valid translation after every attempt' + ) + expect(error).toContain('ja/main.json: main.json: steps[0]') + expect(repo.readCatalog('ja/main.json')).toEqual({ title: '[ja] Title' }) + expect(repo.readCatalog('zh-CN/main.json')).toEqual({ + greeting: '[zh-CN] Hello {name}', + steps: ['[zh-CN] Step {name}', '[zh-CN] Plain'], + title: '[zh-CN] Title' + }) + expect(repo.readManifest()).toEqual({ + version: 1, + files: { 'main.json': repo.blobId(english) } + }) + + const healthy = createTranslator() + expect((await repo.run(false, healthy.translate)).status).toBe(0) + expect(healthy.sourcesByLocale()).toEqual({ + ja: ['Hello {name}', 'Step {name}', 'Plain'] + }) + }) }) describe('edits during generation', () => { diff --git a/scripts/i18n/update-locales.test.ts b/scripts/i18n/update-locales.test.ts index 32dcf8bdbdc..7482bdad751 100644 --- a/scripts/i18n/update-locales.test.ts +++ b/scripts/i18n/update-locales.test.ts @@ -55,20 +55,17 @@ async function updateLocaleFile( leafTokensDiffer ) const plan = buildTranslationItems('main.json', pendingLeaves) - const translations = - plan.items.length > 0 - ? await translateLocaleItems( - locale, - plan.items, - translateBatch, - translationConfig - ) - : new Map() + const { translated } = await translateLocaleItems( + locale, + plan.items, + translateBatch, + translationConfig + ) const output = rebuildLocale( source, existing, invalidated, - assembleLeafTranslations(pendingLeaves, plan, translations) + assembleLeafTranslations(pendingLeaves, plan, translated) ) return { output, translatedCount: plan.items.length } } diff --git a/scripts/i18n/update-locales.ts b/scripts/i18n/update-locales.ts index d04e884404f..c5e9f8ece02 100644 --- a/scripts/i18n/update-locales.ts +++ b/scripts/i18n/update-locales.ts @@ -133,11 +133,15 @@ export function assembleLeafTranslations( structuredClone(leaf.value) ]) ) + const untranslated = new Set() for (const item of plan.items) { const ref = plan.refs.get(item.id) + if (!ref) throw new Error(`Missing reference for item ${item.context}`) const translated = translations.get(item.id) - if (!ref || translated === undefined) - throw new Error(`Missing translation for item ${item.context}`) + if (translated === undefined) { + untranslated.add(ref.leafKey) + continue + } const leaf = assembled.get(ref.leafKey) if (leaf === undefined) throw new Error(`Unknown leaf for ${item.context}`) if (ref.indices.length === 0) { @@ -155,6 +159,7 @@ export function assembleLeafTranslations( } container[ref.indices.at(-1) ?? 0] = translated } + for (const key of untranslated) assembled.delete(key) return assembled } @@ -506,9 +511,17 @@ export async function updateLocales({ } type TranslationOutcome = - | { state: LocaleFileState; output: LocaleObject; known: string[] } + | { + state: LocaleFileState + output: LocaleObject + known: string[] + untranslated: string[] + } | { state: LocaleFileState; failure: string } +type CompletedOutcome = Extract +type FailedOutcome = Extract + async function translateStates( states: readonly LocaleFileState[], config: TranslationPipelineConfig, @@ -577,33 +590,36 @@ async function translateStates( config.localeFileConcurrency, async ({ state, translation }): Promise => { try { - const translated = translation.items.length - ? await translateLocaleItems( - state.locale, - translation.items, - translator, - config - ) - : new Map() - const values = new Map([ - ...state.retained, - ...assembleLeafTranslations( - state.pendingLeaves, - translation, - translated - ) - ]) + const { translated, untranslated } = await translateLocaleItems( + state.locale, + translation.items, + translator, + config + ) + const assembled = assembleLeafTranslations( + state.pendingLeaves, + translation, + translated + ) + const unassembled = state.pendingLeaves + .map(({ path }) => pathKey(path)) + .filter((key) => !assembled.has(key)) const output = rebuildLocale( state.plan.source, state.existing, state.plan.invalidated, - values, - state.omitted + new Map([...state.retained, ...assembled]), + new Set([...state.omitted, ...unassembled]) ) const audit = auditState(state, output, config, 'output') if (audit.unexpected.length) throw new Error(audit.unexpected.map(formatTokenViolation).join('\n')) - return { state, output, known: audit.known } + return { + state, + output, + known: audit.known, + untranslated: untranslated.map(({ context }) => context) + } } catch (error) { return { state, @@ -678,13 +694,39 @@ function writeOutcomes({ serializeManifest({ version: 1, files, knownViolations }) ) const written = writeCatalogUpdates(updates, inputs) - if (failures.length) - throw new Error( - `Translation failed for ${failures.length} locale files:\n${failures.map(({ state, failure }) => `${state.label}: ${failure}`).join('\n')}\nAll locale results for ${[...failedFiles].join(', ')} were discarded together. Other entry files were written and recorded in the manifest.` - ) + const problems = [ + ...describeFailedFiles(failures, failedFiles), + ...describeUntranslatedStrings(completed) + ] + if (problems.length) throw new Error(problems.join('\n')) return written } +function describeFailedFiles( + failures: readonly FailedOutcome[], + failedFiles: ReadonlySet +): string[] { + if (!failures.length) return [] + const details = failures + .map(({ state, failure }) => `${state.label}: ${failure}`) + .join('\n') + return [ + `Translation failed for ${failures.length} locale files:\n${details}\nAll locale results for ${[...failedFiles].join(', ')} were discarded together. Other entry files were written and recorded in the manifest.` + ] +} + +function describeUntranslatedStrings( + completed: readonly CompletedOutcome[] +): string[] { + const untranslated = completed.flatMap(({ state, untranslated }) => + untranslated.map((context) => `${state.label}: ${context}`) + ) + if (!untranslated.length) return [] + return [ + `${untranslated.length} strings had no valid translation after every attempt and were left out; they render in English and retry on the next run:\n${untranslated.join('\n')}` + ] +} + function writeCatalogUpdates( updates: ReadonlyMap, inputs: ReadonlyMap diff --git a/src/locales/CONTRIBUTING.md b/src/locales/CONTRIBUTING.md index d226ad02a83..faa1435dda0 100644 --- a/src/locales/CONTRIBUTING.md +++ b/src/locales/CONTRIBUTING.md @@ -118,7 +118,10 @@ translations whose placeholders no longer match the English source are re-queued for translation, so corrupted strings heal on the next run. Results persist per entry file: a failure translating one file does not discard the completed, validated work of the others — those are written and their manifest -entries advance, and only the failed files retry on the next run. Runs that +entries advance, and only the failed files retry on the next run. Within a +file, a string with no valid translation after every round, whether the model +keeps corrupting it or the provider defers it, is left out (English fallback) +and retried on the next run, while the rest of the file is written. Runs that prune keys report each affected file's exact deleted-key count. The release PR diff and review approve those deletions; there is no separate size-based bypass. Source-manifest, translation, and protected-token integrity failures remain hard