Skip to content

Translations#1606

Open
kshitijk4poor wants to merge 64 commits into
CERT-Polska:mainfrom
kshitijk4poor:translations
Open

Translations#1606
kshitijk4poor wants to merge 64 commits into
CERT-Polska:mainfrom
kshitijk4poor:translations

Conversation

@kshitijk4poor

@kshitijk4poor kshitijk4poor commented Mar 16, 2025

Copy link
Copy Markdown
Contributor

Problem

Currently, when exporting reports in non-English languages, the process crashes on the first missing translation. This makes it difficult to develop and maintain translations as you can't see all missing translations at once. This PR aims to fix problem #1445

Solution

Implemented a flexible translation handling system that:

  • Makes lenient mode the default - uses original text for missing translations and collects them
  • Preserves the original strict behavior via an explicit flag (--strict-translations)
  • Generates a convenient file with all missing translations for easy filling

Implementation Details

  • Created TranslationCollectMissingException class that collects missing translations and returns the original text
  • Made lenient mode the default in all relevant functions by changing parameter defaults from strict_mode=True to strict_mode=False
  • Added --strict-translations/--lenient-translations CLI flag (with lenient as the default)
  • When in lenient mode (now the default), generates a missing_translations.po file with all missing translations
  • Updated documentation to reflect the new default behavior

Benefits

  • Improves translation workflow by allowing exports to complete even with incomplete translations
  • Provides a complete list of all missing translations in a single export
  • Generates template files ready for translation
  • Preserves the original strict behavior when explicitly requested with --strict-translations
  • Makes it easier to contribute partial translations

Backward Compatibility

  • The default behavior has changed from strict to lenient
  • Scripts that rely on the original behavior will need to add the --strict-translations flag
  • This change is documented in the user guide and CLI help text

TODO

  • Improve exception handling in TranslationCollectMissingException.gettext() - use more specific exception types instead of generic Exception
  • Add thread safety for the shared missing_translations class variable to handle concurrent access
  • Add error handling when saving missing translations file
  • Enhance missing translations storage to include context information (file/template source, etc.)
  • Add robust error handling for the subprocess call to pybabel
  • Replace complete stderr suppression in pybabel call with proper logging

kshitijk4poor and others added 30 commits August 10, 2024 01:31
- Added `strict_mode` parameter to `_install_translations_and_print_path` to control behavior on missing translations.
- Implemented lenient mode to allow report export with missing translations, generating a `missing_translations.po` file.
- Updated `export` and `export_cli` functions to support the new `--lenient-translations` flag.
- Added unit tests for strict and lenient translation modes, ensuring proper handling of missing translations.
- Introduced a threading lock to ensure safe access to the `missing_translations` set across multiple instances.
- Updated methods in `TranslationCollectMissingException` to use the lock when adding missing translations and retrieving the set.
- Ensured that the `get_missing_translations` and `clear_missing_translations` methods are thread-safe to prevent concurrent modification issues.
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