Repository navigation
Fall back to English when a translation catalog is corrupted - #120
Merged
Merged
Conversation
gettext.translation(..., fallback=True) only handles missing catalogs: a corrupted or unreadable .mo raised OSError/struct.error/ValueError/ LookupError at import time and prevented guidata-based applications (PlotPy, Sigima, DataLab) from starting. get_translation now emits a RuntimeWarning identifying the faulty catalog and returns the untranslated (English) callback. Fixes #119 Assisted-by: Claude Opus 5.5
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
guidata.configtools.get_translationcallsgettext.translation(modname, modlocpath, fallback=True).fallback=Trueonly handles missing catalogs: a.mofile that exists but is corrupted or unreadable raisesOSError(bad magic number, file is corrupt, permission denied),struct.error(truncated file),ValueError(invalid UTF-8, invalidPlural-Forms) orLookupError(unknown charset).As
get_translationruns at import time (guidata.config,plotpy.config,sigima.config,datalab.config), a single corrupted catalog prevents every guidata-based application from starting.Fix
get_translationcatches these errors, emits aRuntimeWarningnaming the module, the locale directory and the underlying error, and returns the untranslated (English) callback (gettext.NullTranslations).Exception) so that programming errors are not hidden.gettextonly caches successfully parsed catalogs, so no stale cache entry is left behind.Tests
guidata/tests/unit/test_translations.py(Qt-free) builds GNU.mocatalogs in a temporary locale directory:Plural-Forms):RuntimeWarning+ English fallback. All 7 fail without the fix.Validation:
pytest(full guidata suite, Python 3.11): 251 passed, 2 skipped.ruff format/ruff check: clean.frcatalog,guidata,plotpy.config,sigima.configanddatalab.configall import; guidata falls back to English with the warning while DataLab's own catalog keeps working.Release notes
Entry added to the
Unreleasedsection ofdoc/release_notes/release_3.16.md(patch 3.16.x). To be cherry-picked intodevelopafter merge.Fixes #119