Skip to content

Document reporting missing messages with the backend callbacks - #447

Merged
whatyouhide merged 1 commit into
elixir-gettext:mainfrom
olehgerus:on-missing-translation
Oct 23, 2026
Merged

whatyouhide merged 1 commit into
elixir-gettext:mainfrom
olehgerus:on-missing-translation

Conversation

@olehgerus

@olehgerus olehgerus commented Oct 18, 2026 •

Copy link
Copy Markdown
Contributor

Refs #410.

Following the discussion here, this is now docs only and the :on_missing_translation option is gone.

It adds a "Reporting missing messages" section to the "Missing messages" docs in Gettext. It shows how to override handle_missing_translation/5 and handle_missing_plural_translation/7 in a backend, log a warning and call super, and mentions that the callbacks run for every locale that lacks the message, including the source one.

I ran the example from the docs: it logs the warning and still returns the msgid.

@josevalim

Copy link
Copy Markdown
Contributor

Perhaps I am missing something, but why not use the handle_missing_translation and handle_missing_plural_translation callbacks?

@olehgerus

Copy link
Copy Markdown
Contributor Author

Not missing anything, the callbacks can do this, and I checked that overriding both and calling super covers the same cases (missing keys, empty msgstr, unknown domains and locales, plurals, split_module_by).

I went with the option because of the discussion in #410, where @maennchen and @whatyouhide were in favor of an on_missing_translation backend option. It saves people writing the same override, and gives one shared error and log format. But if you'd rather keep the API small, I understand.

The docs don't mention the callbacks in the "Missing messages" section, so that part is easy to miss. If you prefer, I can turn this PR into a docs-only change with an example of warning or raising from the override, plus the default-domain fallback from the issue. Just tell me which way you want to go.

@josevalim

Copy link
Copy Markdown
Contributor

I'd prefer to use the callbacks but let's def er to @maennchen and @whatyouhide's decision.

@whatyouhide

Copy link
Copy Markdown
Contributor

When I suggested that option I was not thinking of callbacks, which in general are a good approach here I think. I would personally go for this:

  1. Improve docs around this instead of adding the option.
  2. Update Phoenix template to generate a missing-translation callback that does warn (because I think it's a nice behavior, and easier to take it out?).

Thoughts?

@olehgerus

Copy link
Copy Markdown
Contributor Author

Sounds good, I agree callbacks are the better fit here. I'll rework this PR into docs only and drop the option. The docs will show how to override handle_missing_translation/5 and handle_missing_plural_translation/7 to log a warning.

For the Phoenix template, I'm happy to open that PR in the Phoenix repo once the docs are in, if that works for you.

Missing messages are returned silently. Show how to override
handle_missing_translation/5 and handle_missing_plural_translation/7 and
call super to log a warning.
@olehgerus
olehgerus force-pushed the on-missing-translation branch from f92d604 to df67fd9 Compare October 22, 2026 20:44
@olehgerus olehgerus changed the title Add an :on_missing_translation backend option Document reporting missing messages with the backend callbacks Oct 22, 2026
@whatyouhide
whatyouhide merged commit 6e0de91 into elixir-gettext:main Oct 23, 2026
2 checks passed
@whatyouhide

Copy link
Copy Markdown
Contributor

Thank you @olehgerus 🫶

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.

3 participants