Skip to content

Conversation

jk-lamb
Copy link

@jk-lamb jk-lamb commented Sep 30, 2025

Pull Request

Description

Adds Gettext 0.26.0 compatibility with a custom backend adapter system:

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 #108
Related to #107

Changes Made

  • Custom Gettext Backend System: Created Kanta.Backend with CachedDB adapter that fetches translations from database/cache instead of PO files at runtime, with fallback support
  • New Architecture: Added backend adapter pattern with Kanta.Backend.Adapter behavior and FallbackBackend for missing translations
  • Migration Updates: Added v04 PostgreSQL and v03 SQLite migrations to support new backend system
  • Removed: Old Kanta.Gettext.Repo module (156 lines) replaced with new adapter system

Testing

Test Environment

  • Elixir version: 1.18.4
  • OTP version: 27.3.4.1
  • Phoenix version: 1.7.11
  • Database: PostgreSQL 17
  • Gettext version: 0.26.2

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

Adds Gettext 0.26.0 compatibility with a custom backend adapter system: Will not work with Gettextt < 0.26

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

ettext 0.26 Migration:

  • Migrates from experimental Gettext branch to official 0.26 release with backend support
  • Replaces Kanta.Gettext.Repo (156 lines removed) with new Kanta.Backend.Adapter.CachedDB backend adapter
  • Introduces fallback mechanism to PO files via Kanta.Backend.GettextFallback

Translation Storage/Retrieval:

  • New backend adapter fetches translations from database/cache at runtime instead of compiled PO files
  • Maintains existing caching layer for performance
  • All existing translations remain intact but retrieval mechanism changed

Extraction Process:

  • Added Kanta.Utils.GettextRecompiler for managing recompilation during extraction
  • New flag file system (priv/kanta/.fallback_recompiled) tracks extraction state
  • Improved extraction handling with ModuleFolder utilities

Database Schema Changes:

  • PostgreSQL v3 → v4 migration: Adds default context, updates null context_id values
  • SQLite v2 → v3 migration: Adds default context, updates null context_id values
  • Migration required for all existing installations

Security Considerations

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

Additional Notes

Plugin System Impact:

  • Internal API changes from Kanta.Gettext.Repo to backend adapter may require plugin updates
  • Plugins relying on old repo interface need migration to new backend adapter API
  • DeepL, POWriter, and KantaSync plugins should be tested for compatibility

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


arturz and others added 30 commits February 26, 2025 13:28
- Add Gettext.Backend implementation (Gettext 0.26.2) for Kanta.
- Kanta Cached DB
- Add Fallback Gettext backend for PO file checks
- Gettext.Recompiler util module to support one time recompilation after mix gettext.extract

Tests:
- Add migration(v4) for test repo
- Re-implemented DataCase helper (manual checkout)
- Add tests for the Backend and Adapter
- Remove Logger.debug(...)
- add removing trailing "." to safe_folder_name (for Windows)
@jk-lamb jk-lamb requested a review from arturz September 30, 2025 03:32
The changes add missing @moduledoc attributes to various modules,
providing clear documentation about their purpose.
mix ecto.drop && mix ecto.create && mix ecto.migrate
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