Skip to content

Point the nplurals=<int> Plural-Forms warning at the PO file - #457

Merged
whatyouhide merged 1 commit into
elixir-gettext:mainfrom
oliver-kriska:plural-warning-file
Dec 4, 2026
Merged

whatyouhide merged 1 commit into
elixir-gettext:mainfrom
oliver-kriska:plural-warning-file

Conversation

@oliver-kriska

@oliver-kriska oliver-kriska commented Dec 3, 2026 •

Copy link
Copy Markdown
Contributor

Closes #409.

  • The warning about a Plural-Forms: nplurals=<int> header (without the plural= part) now points at the PO file that has the header, instead of printing a stack trace into Gettext.
  • It is still a compiler warning: Code.with_diagnostics/1 reports one :warning diagnostic with the PO file as file, so --warnings-as-errors behaves as before. Checked on Elixir 1.16.3 and 1.20.4.
  • When the messages have no file, the warning is printed as before.

The end of the warning, before:

nplurals=2; plural=(n != 1);

  (gettext 1.1.0) lib/gettext/plural.ex:282: Gettext.Plural.init/1
  (elixir 1.20.4) src/elixir.erl:382: :elixir.eval_external_handler/3
  ...

After:

nplurals=2; plural=(n != 1);

└─ priv/gettext/en/LC_MESSAGES/default.po: (file)

One thing to decide

The Gettext.Plural behaviour and the context passed to init/1 are unchanged: the file goes through a private function that plural_info/3 calls when the plural module is Gettext.Plural itself. A custom plural module that delegates to Gettext.Plural.init/1 still gets the warning, without the file.

The alternative is a :file key in the context given to init/1, which would cover that case and change what custom modules receive. I kept the public context as it is; happy to switch if you prefer the key.

Checks

  • New tests call plural_info/3 directly, with and without a file. The merger test for this header also asserts the file name.
  • The test for custom plural modules now compares the whole context map, so an extra key would fail it.
  • mix format --check-formatted, mix compile --warnings-as-errors and mix test pass (196 passed); the suite also passes on Elixir 1.16.3 / OTP 24.

🤖 Generated with Claude Code

The warning now carries the path of the PO file with the header
instead of a stack trace into Gettext.

Closes elixir-gettext#409

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
@whatyouhide
whatyouhide merged commit 45e4ee7 into elixir-gettext:main Dec 4, 2026
2 checks passed
@whatyouhide

Copy link
Copy Markdown
Contributor

Thank you Claude and @oliver-kriska.

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.

Include file in plural warnings?

2 participants