Skip to content

Make the gettext functions accept a localedir of type Traversable #149809

@Jesse205

Description

@Jesse205

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    stdlibStandard Library Python modules in the Lib/ directorytype-featureA feature request or enhancement

    Projects

    Status

    No status

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions