python / python/cpython

Make the gettext functions accept a localedir of type Traversable

Open
#149,809 4 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

stdlib type-feature
Dominant language
Python
Stars
77.2k
Forks
35.9k
PR merge metrics
PR metrics pending

Description

Feature or enhancement

Proposal:
from gettext import bindtextdomain, find, translation
import importlib.resources

bindtextdomain("demo-zipapp", importlib.resources.files("demo_zipapp").joinpath("locales"))
translation("demo-zipapp", importlib.resources.files("demo_zipapp").joinpath("locales"))
find("demo-zipapp", importlib.resources.files("demo_zipapp").joinpath("locales"))

In ZipApp, since files within the application cannot be read directly through traditional file APIs, it is necessary to use importlib.resources.files to read them.

importlib.resources.files returns a Traversable object, which is not supported by gettext.

Here is a demo app: demo-zipapp.zip (source) | demo-zipapp.zip (zipapp)

Has this already been discussed elsewhere?

I have already discussed this feature proposal on Discourse

Links to previous discussion of this feature:

https://discuss.python.org/t/make-the-gettext-functions-accept-a-localedir-of-type-traversable/107330

Linked PRs
  • gh-149810

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the gettext.bindtextdomain, gettext.translation, and gettext.find entry points, then review linked PR gh-149810 and the referenced Discourse discussion. The change is complete when these functions accept a Traversable localedir for resources inside a ZipApp, with coverage for the demonstrated usage.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
internationalization
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.