Skip to content

Conversation

@barredterra
Copy link
Collaborator

@barredterra barredterra commented Oct 30, 2025

Summary

Adds support for the ignore_translatable_strings_from hook that allows apps to exclude translatable strings from specified dependency apps when generating POT files. This prevents duplication of translations that already exist in parent/dependency apps.

Problem

Custom apps frequently contain strings that already have translations in core apps (like Frappe or ERPNext). This creates unnecessary duplication in translation files and makes it harder to track which translations are actually needed for the custom app.

Impact:

  • ERPNext could reduce its translation file by ~8,000 lines (13%) by ignoring Frappe strings
  • HRMS could reduce by ~4,500 lines (28%) by ignoring Frappe and ERPNext strings

Solution

This PR introduces a new hook that allows apps to specify which dependency apps' translations should be excluded from their POT generation:

# In hooks.py
ignore_translatable_strings_from = ["frappe", "erpnext"]

Changes

  1. Core functionality (frappe/gettext/translate.py):

    • Added _get_ignored_strings() helper function that builds a set of (message, context) tuples from specified apps' POT files
    • Modified POT generation to filter out ignored strings during catalog building
    • Added validation to prevent apps from ignoring themselves (raises ValueError)
    • Added color-coded warning (yellow) when specified apps are not found
  2. Developer experience (frappe/utils/boilerplate.py):

    • Added hook documentation to the boilerplate template for new apps
    • Includes clear usage example

Technical Details

  • Performance: Uses set-based lookups for efficient filtering - each membership test is O(1) on average, making it suitable for large translation catalogs.
  • Safety: Validates that apps don't ignore themselves and provides clear error messages
  • Graceful degradation: Missing apps trigger warnings but don't break the build

Testing

To test this feature:

  1. Add ignore_translatable_strings_from = ["frappe"] to a custom app's hooks.py
  2. Run bench generate-pot-file for the app
  3. Verify that strings present in Frappe's POT file are excluded from the generated POT file

Documentation

no-docs (will add after merge)


Resolves #34541

…endencies

Add support for `ignore_translatable_strings_from` hook that allows apps
to exclude translatable strings from specified dependency apps when
generating POT files.

This is useful when an app extends another app and wants to avoid
duplicating translations that already exist in the parent app.

Usage:
    # In hooks.py
    ignore_translatable_strings_from = ["frappe", "erpnext"]

Changes:
- Add `_get_ignored_strings()` helper to build set of excluded strings
- Filter out ignored messages during POT generation
- Add validation to prevent apps from ignoring themselves
- Add hook documentation to boilerplate template
- Use color-coded warnings for missing apps

Performance: Uses set-based lookups (O(1)) for efficient filtering of
large translation catalogs.

Resolves frappe#34541
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

1 participant