Skip to content

Give new PO files as many plural forms as --plural-forms-header says - #461

Open
oliver-kriska wants to merge 1 commit into
elixir-gettext:mainfrom
oliver-kriska:plural-forms-header-count
Open

oliver-kriska wants to merge 1 commit into
elixir-gettext:mainfrom
oliver-kriska:plural-forms-header-count

Conversation

@oliver-kriska

Copy link
Copy Markdown
Contributor
  • mix gettext.merge --locale it --plural-forms-header "nplurals=3; ..." creates a PO file with the given Plural-Forms header, but each plural message gets the locale's default number of msgstr[n] entries (two for Italian).
  • A file like that logs message is missing plural form 2 which is required by the locale "it" when the backend compiles, and raises Gettext.PluralFormError for a count that selects the third form.
  • Gettext.Merger.new_po_file/4 now takes the number of forms from the header when Expo can parse it.

For a new it PO file with one plural message:

--plural-forms-header Plural-Forms in the file msgstr[n] entries before After
not given locale default 2 2
nplurals=3; plural=n==1 ? 0 : n==2 ? 1 : 2; as given 2 3
a header Expo cannot parse as given 2 2

Not changed:

  • An explicit :plural_forms option passed to new_po_file/4 still wins over the header.
  • Existing PO files: the merge keeps their own Plural-Forms header and takes the number of forms from it, so the flag only has an effect when a file is created. I left that alone, since changing it needs a decision about existing translations.

Checks

  • New test in gettext.merge_test.exs, next to "...with custom plural forms": a parsable three-form header gives msgstr[0], msgstr[1] and msgstr[2]. It fails on main with two entries.
  • Two new tests for new_po_file/4 in merger_test.exs: an explicit :plural_forms beats the header, and a header that cannot be parsed keeps the locale's count. Both also pass on main; they pin the behaviour that must not change.
  • Compiled a backend from a PO file with the three-form header and two forms: counts 1 and 2 translate, count 3 raises Gettext.PluralFormError.
  • mix format --check-formatted, mix compile --warnings-as-errors and mix test pass (201 passed).

🤖 Generated with Claude Code

`mix gettext.merge --plural-forms-header` wrote the given Plural-Forms
header to a new PO file but took the number of msgstr entries from the
locale, so a three-form header for Italian came with two forms per
message. Such a file logs "message is missing plural form 2" when it is
compiled and raises Gettext.PluralFormError for a count that needs the
third form.

Gettext.Merger.new_po_file/4 now takes the number of forms from the
header when Expo can parse it. An explicit :plural_forms option and a
header that cannot be parsed behave as before.

Co-Authored-By: Claude Fable 5.2 <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