Skip to content

Keep the translation folder valid for keys i18n loads later - #374

Merged
kaixxx merged 1 commit into
kaixxx:mainfrom
cristianchiriac:fix/i18n-load-path
Oct 22, 2026
Merged

kaixxx merged 1 commit into
kaixxx:mainfrom
cristianchiriac:fix/i18n-load-path

Conversation

@cristianchiriac

Copy link
Copy Markdown
Contributor

Fixes #368.

main.py and whisper_mp_worker.py added the folder from impres.as_file(impres.files("trans")) to i18n.load_path. Because trans/ has no __init__.py, files("trans") returns a MultiplexedPath, and as_file() copies the folder into a temp directory that is deleted when the with block exits. python-i18n reads the load path again for any key it has not memoized yet, such as a missing key or the first fallback to en. That lookup then crashed with FileNotFoundError on the deleted temp trans folder.

The fix uses the approach @happyarts posted in the issue (thanks also to @omaer0 for the report and the first _paths workaround). The new utils.translations_dir() returns str((impres.files("trans") / "noScribe.en.yml").parent). Joining a file name on the MultiplexedPath gives the real file, so there is no temporary copy, and if more than one trans folder were on the path it picks the one that actually holds the .yml files. Both call sites now use the helper. It doesn't use the private _paths attribute.

Testing: tests/test_translations_dir.py only needs python-i18n and PyYAML, not torch or whisper. It checks that the returned folder still contains noScribe.en.yml, that a missing key returns the key name for both en and de without crashing, and that neither call site still uses as_file on trans.

  • With the helper changed back to the old as_file behaviour, the folder test and both missing-key tests fail. The missing-key tests fail with the FileNotFoundError from the issue.
  • With the fix, all 5 tests pass on Python 3.11 (importlib_resources backport), 3.12 and 3.13.
  • tests/test_worker_import_lightweight.py still passes for the worker modules.

I haven't tried a frozen PyInstaller build. trans/ is bundled there as a real folder, so it should behave the same.

main.py and the Whisper worker added the folder from
impres.as_file(impres.files("trans")) to i18n's load path. That is a
temporary copy, deleted when the with block ends, so the first lookup
of a key that is not memoized yet (a missing key, or the fallback to
"en") crashed with FileNotFoundError.

Add utils.translations_dir(), which returns the real folder of
noScribe.en.yml, and use it in both places.

Fixes kaixxx#368
@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review 🔄 Running since 2026-10-21T16:36:26.106943Z 25c9c86 PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@kaixxx

kaixxx commented Oct 22, 2026

Copy link
Copy Markdown
Owner

Thanks, @cristianchiriac and @happyarts. This looks good. I'll merge and test.

@kaixxx
kaixxx merged commit 7908a33 into kaixxx:main Oct 22, 2026
3 checks passed
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.

Localisation settings: crash if string not present in trans/noScribe.**.yml

2 participants