Skip to content

make handle_missing*_translation overridable#135

Open
kubosuke wants to merge 2 commits intocuriosum-dev:mainfrom
kubosuke:feat/override
Open

make handle_missing*_translation overridable#135
kubosuke wants to merge 2 commits intocuriosum-dev:mainfrom
kubosuke:feat/override

Conversation

@kubosuke
Copy link
Contributor

@kubosuke kubosuke commented Nov 13, 2025

Pull Request

#136

Description

In the previous version of gettext-runtime, the functions handle_missing_translation and handle_missing_plural_translation were overridable:
https://github.com/ravensiris/gettext/blob/600e4630fb7db514d464f92e2069a138cf9c68a1/lib/gettext.ex#L633

However, in the latest Kanta v0.5, overriding these functions is no longer allowed:
https://github.com/curiosum-dev/kanta/blob/main/lib/kanta/backend.ex

This PR restores the ability to override these fallback functions.
(Use case: in our application, when translation values are missing, instead of returning the msgid immediately, we’d like to fall back to the en locale. To achieve this, we need to override these functions.)

Type of Change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Documentation update
  • Performance improvement
  • Code refactoring
  • Test improvements
  • CI/CD improvements

Related Issues

Fixes #
Closes #
Related to #

Changes Made

Testing

Test Environment

  • Elixir version: 1.19.2
  • OTP version: 28
  • Phoenix version: 1.8.0
  • Database: psql 16.9
  • Gettext version: 1.0

Test Cases

  • All existing tests pass
  • New tests added for new functionality at appropriate levels
  • Manual testing performed

Test Commands Run

# List the commands you ran to test
mix test
MIX_ENV=test mix credo
MIX_ENV=test mix dialyzer

Documentation

  • Updated README.md (if applicable)
  • Updated documentation comments (with examples for new features)
  • Updated CHANGELOG.md (if applicable)

Code Quality

  • Code follows the existing style conventions
  • Self-review of the code has been performed
  • Code has been commented, particularly in hard-to-understand areas
  • No new linting warnings introduced
  • No new Dialyzer warnings introduced

Backward Compatibility

  • This change is backward compatible
  • This change includes breaking changes (please describe below)
  • Migration guide provided for breaking changes

Breaking Changes

Performance Impact

  • No performance impact
  • Performance improvement
  • Potential performance regression (please describe)

Performance Notes

Translation Management Impact

  • No impact on existing translations
  • Affects translation extraction process
  • Affects translation storage/retrieval
  • Affects Kanta UI/dashboard
  • Affects plugin system
  • Database schema changes

Translation Impact Notes

Security Considerations

  • No security impact
  • Security improvement
  • Potential security impact (please describe)

Additional Notes

Screenshots/Examples

# Example usage of new translation management feature
# For UI changes, show before/after screenshots
# For API changes, show usage example:

# Example: New translation extraction feature
Kanta.extract_translations_from_po_files(domain: "errors")

# Example: New plugin integration
defmodule MyApp.CustomTranslationPlugin do
  use Kanta.Plugin
  # implementation
end

Checklist

  • I have read the Contributing Guidelines
  • I have performed a self-review of my code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes
  • Any dependent changes have been merged and published

Reviewer Notes


kanta on  feat/override via  v16.14.2
❯ MIX_ENV=test mix ecto.drop && MIX_ENV=test mix ecto.create && MIX_ENV=test mix ecto.migrate
Compiling 1 file (.ex)
Generated kanta app
The database for Kanta.Test.Repo has been dropped
The database for Kanta.Test.Repo has been created

15:46:33.175 [info] == Running 20250327123641 Kanta.Test.Repo.Migrations.UpdateKantaMigrations.up/0 forward

15:46:33.183 [info] create table if not exists kanta_locales

15:46:33.192 [info] create index if not exists kanta_locales_iso639_code_index

15:46:33.193 [info] create table if not exists kanta_contexts

15:46:33.196 [info] create index if not exists kanta_contexts_name_index

15:46:33.197 [info] create table if not exists kanta_domains

15:46:33.199 [info] create index if not exists kanta_domains_name_index

15:46:33.200 [info] execute "\n      DO $$ BEGIN\n          CREATE TYPE gettext_message_type AS ENUM ('singular', 'plural');\n      EXCEPTION\n          WHEN duplicate_object THEN null;\n      END $$\n    "

15:46:33.202 [info] create table if not exists kanta_messages

15:46:33.206 [info] execute "  ALTER TABLE public.kanta_messages\n    ADD COLUMN IF NOT EXISTS searchable tsvector\n    GENERATED ALWAYS AS (\n      setweight(to_tsvector('english', coalesce(msgid, '')), 'A')\n    ) STORED;\n"

15:46:33.208 [info] execute "  CREATE INDEX IF NOT EXISTS kanta_messages_searchable_idx ON public.kanta_messages USING gin(searchable);\n"

15:46:33.209 [info] create index if not exists kanta_messages_context_id_domain_id_msgid_index

15:46:33.210 [info] create table if not exists kanta_singular_translations

15:46:33.212 [info] create index if not exists kanta_singular_translations_locale_id_message_id_index

15:46:33.213 [info] create table if not exists kanta_plural_translations

15:46:33.215 [info] create index if not exists kanta_plural_translations_locale_id_message_id_nplural_index_index

15:46:33.215 [info] identifier "kanta_plural_translations_locale_id_message_id_nplural_index_index" will be truncated to "kanta_plural_translations_locale_id_message_id_nplural_index_in"

15:46:33.215 [info] execute "  ALTER TABLE public.kanta_plural_translations\n    ADD COLUMN IF NOT EXISTS searchable tsvector\n    GENERATED ALWAYS AS (\n      setweight(to_tsvector('simple', coalesce(translated_text, '')), 'A')\n    ) STORED;\n"

15:46:33.216 [info] execute "  CREATE INDEX IF NOT EXISTS kanta_plural_translations_searchable_idx ON public.kanta_plural_translations USING gin(searchable);\n"

15:46:33.217 [info] execute "  ALTER TABLE public.kanta_singular_translations\n    ADD COLUMN IF NOT EXISTS searchable tsvector\n    GENERATED ALWAYS AS (\n      setweight(to_tsvector('simple', coalesce(translated_text, '')), 'A')\n    ) STORED;\n"

15:46:33.218 [info] execute "  CREATE INDEX IF NOT EXISTS kanta_singular_translations_searchable_idx ON public.kanta_singular_translations USING gin(searchable);\n"

15:46:33.219 [info] execute "CREATE EXTENSION IF NOT EXISTS unaccent;"

15:46:33.221 [info] create table if not exists kanta_application_sources

15:46:33.222 [info] create index if not exists kanta_application_sources_name_index

15:46:33.222 [info] alter table kanta_messages

15:46:33.223 [info] drop index kanta_messages_context_id_domain_id_msgid_index

15:46:33.224 [info] create index if not exists kanta_messages_application_source_id_context_id_domain_id_msgid_index

15:46:33.224 [info] identifier "kanta_messages_application_source_id_context_id_domain_id_msgid_index" will be truncated to "kanta_messages_application_source_id_context_id_domain_id_msgid"

15:46:33.224 [info] execute "INSERT INTO kanta_contexts (name, inserted_at, updated_at)\nVALUES ('default', NOW(), NOW())\nON CONFLICT (name) DO NOTHING;\n"

15:46:33.224 [info] execute "UPDATE kanta_messages\nSET context_id = (SELECT id FROM kanta_contexts WHERE name = 'default')\nWHERE context_id IS NULL;\n"

15:46:33.225 [info] execute "COMMENT ON TABLE \"public\".kanta_messages IS '4'"

15:46:33.226 [info] == Migrated 20250327123641 in 0.0s

kanta on  feat/override via  v16.14.2
❯ mix test
Running ExUnit with seed: 998188, max_cases: 22

...................................................................................................
Finished in 1.2 seconds (1.0s async, 0.2s sync)
99 tests, 0 failures

kanta on  feat/override via  v16.14.2
❯ elixir -v
Erlang/OTP 28 [erts-16.1] [source] [64-bit] [smp:11:11] [ds:11:11:10] [async-threads:1] [jit]

Elixir 1.19.2 (compiled with Erlang/OTP 26)

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