Skip to content

fix(i18n): run localize-translate without cmd.exe and in batches to stay under the Windows command line limit - #186

Open
JohnYoungers wants to merge 2 commits into
native-federation:mainfrom
JohnYoungers:fix/i18n-windows-command-length
Open

JohnYoungers wants to merge 2 commits into
native-federation:mainfrom
JohnYoungers:fix/i18n-windows-command-length

Conversation

@JohnYoungers

Copy link
Copy Markdown
Contributor

Problem

translateFederationArtifacts runs localize-translate as one command string through execSync, which uses cmd.exe on Windows. cmd.exe limits the command line to 8191 characters. The -s argument lists every federation file, so in a workspace with a few hundred federation files the list alone is longer than that, and the build logs:

The command line is too long.

It runs fine on Linux. node_modules/.bin/localize-translate is a .cmd shim on Windows, so it can only be started through cmd.exe, even without the long list.

This was split out of #172. The missing-chunks part of that PR will follow once core#178 is released.

Change

  • Run the @angular/localize CLI script with process.execPath through execFileSync, so no shell is involved. The script path is resolved from the workspace's @angular/localize/package.json (bin["localize-translate"]) instead of .bin/localize-translate.
  • Split the federation file list into batches and run localize-translate once per batch. A batch holds at most 16,000 characters of file names, which keeps the command under the 32,767 character CreateProcess limit with room for the other arguments. All batches write into the same staging folder, which is copied into the locale folders after the last run, as before. A failing batch still throws and skips the copy.
  • Pass the arguments as an array. The shell used to strip the double quotes from the old JSON.stringify output, so the CLI received [a.xlf,b.xlf] for a locale with several translation files. That is the form convertArraysFromArgs in the CLI expects, so it is now built explicitly as [a,b].

The -s list is unchanged (still built from shared, exposes and chunks), so there is no behavior change for the translated output.

Verification

  • pnpm typecheck and pnpm lint pass.
  • Updated the translateFederationArtifacts unit tests for the argument array, and added one that splits 1000 files over several runs and checks that every file is translated exactly once and that each pattern stays under the limit. On my Windows machine three tests in i18n.spec.ts fail (/ vs \ in path assertions), identically with and without this change; I could not run the suite on Linux.
  • I did not run a full localize: true build with this change applied.

Open question

I picked 16,000 characters for the batch size as roughly half of the Windows limit. If you prefer a different threshold, or batching by file count, it is a single constant.

JohnYoungers and others added 2 commits October 19, 2026 07:11
…alize-translate

Run the localize-translate CLI script with node through execFileSync instead of a
cmd.exe command string, and split the federation file list over several runs when it
gets long.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
The i18n builder now resolves @angular/localize from the workspace, which knip reports
as an unlisted dependency. Declare it as an optional peer (like @angular/build does)
and as a devDependency, and fail with a clear message when it is not installed.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant