Skip to content

fix(translations): accept explicit plural forms in writeTranslation - #18

Merged
Kvintus merged 2 commits into
mmntm:mainfrom
dada-amater:fix/explicit-plural-forms
Oct 15, 2026
Merged

Kvintus merged 2 commits into
mmntm:mainfrom
dada-amater:fix/explicit-plural-forms

Conversation

@dada-amater

Copy link
Copy Markdown
Contributor

Problem

For a plural unit, writeTranslation / bulkWriteTranslations split the single value string into forms heuristically, before every %d. That works only when each form starts with %d. A sentence with text before the number is cut in the wrong place:

"This link is valid for %d hour and can be used only once."
→ ["This link is valid for ", "%d hour and can be used only once."]

There is no way to pass the forms unambiguously. The output also joins plural forms with an empty string, so a broken split looks exactly like a correct one.

Change

  • value accepts either a string (unchanged behaviour, the heuristic still applies) or an array with one string per plural form. The array is sent to Weblate as is, so Weblate validates the number of forms.
  • Plural source/target forms in the tool output are separated by |.

Tested against a Weblate instance with plural units in en (2 forms), cs/pl/ru (3 forms) and es/fr/it/pt (3 forms, CLDR "many").

@changeset-bot

changeset-bot Bot commented Oct 15, 2026 •

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: cbb3dbd

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@mmntm/weblate-mcp Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

A single string is split into plural forms heuristically, before every %d.
That only works when each form starts with %d: a sentence like
"This link is valid for %d hours" ends up as ["This link is valid for ",
"%d hours..."]. The value can now be an array of forms, sent to Weblate as is.

Plural forms in the output were joined without a separator, so a broken split
looked the same as a correct one; they are now separated by " | ".
@dada-amater
dada-amater force-pushed the fix/explicit-plural-forms branch from 052a17f to d960a72 Compare October 15, 2026 12:00
@dada-amater
dada-amater marked this pull request as ready for review October 15, 2026 12:00
CI installs pnpm latest, which now fails pnpm install --frozen-lockfile with
ERR_PNPM_IGNORED_BUILDS for @nestjs/core. Its postinstall only prints an
Open Collective banner, so it is explicitly not run.
@dada-amater
dada-amater force-pushed the fix/explicit-plural-forms branch from cbb3dbd to 2835bca Compare October 15, 2026 12:06
@dada-amater

Copy link
Copy Markdown
Contributor Author

The CI failure was not caused by this change: pnpm-version: latest now installs pnpm 12, which fails pnpm install --frozen-lockfile with ERR_PNPM_IGNORED_BUILDS for @nestjs/core (main would fail the same way today).

I added a separate commit with pnpm-workspace.yaml that explicitly skips that build script (it only prints an Open Collective banner). Verified locally with pnpm 12.11.2: install with the unchanged lockfile and build pass. Happy to move it into its own PR if you prefer.

@Kvintus
Kvintus merged commit 8df9bd5 into mmntm:main Oct 15, 2026
1 check passed
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.

2 participants