Skip to main content

ResourceBundle

PyPI-Versions PyPI version License

ResourceBundle is a module that manages internationalization of string resources. It is inspired by javas ResourceBundle and accepts the same format as a java PropertyResourceBundle.


Installation

The ResourceBundle module can be downloaded from PyPI:

$  python -m pip install ResourceBundle

Usage

Each translation file you provide should have key-value pairs inside:

# This is a comment

key=value
another_key=Another value

Save the files of your ResourceBundle in the following structure and file name format:

./
├── BundleName.properties  # Recommended as a fallback
├── BundleName_languageCode_countryCode_variant.properties
└── ...

For example:

./
├── Strings.properties
├── Strings_en.properties
├── Strings_en_US.properties
└── ...

The recommended way to get a ResourceBundle instance is by using ResourceBundle.get_bundle(name, locale). This function also provides support for pythons builtin locale moudule.

import locale
import ResourceBundle

bundle = ResourceBundle.get_bundle("Strings", "en")
bundle = ResourceBundle.get_bundle("Strings", locale.getlocale())

# It is now possible to get a resource with the get() method
bundle.get("key")

If the key could not be found in the ResourceBundle the parent ResourceBundles will be searched until a matching key was found, or it is determined that the key is not present in any parent ResourceBundle.


Accessing the available key-value items in your code:

ResourceBundles can be converted into dict objects with dict(bundle). If you want to include the whole chain to get every accessible key and value, just iterate over the bundles parent.

import ResourceBundle

bundle = ResourceBundle.get_bundle("Strings")

everything = dict(bundle)
while bundle.parent is not None:
    bundle = bundle.parent
    everything.update(dict(bundle))

Metadata

Release files for ResourceBundle 2.0.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for ResourceBundle 2.0.1
File Size Uploaded Provenance Actions
ResourceBundle-2.0.1.tar.gz 5.1 kB Without provenance Details for ResourceBundle-2.0.1.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for ResourceBundle 2.0.1
File Interpreter ABI Platform Actions
ResourceBundle-2.0.1-py3-none-any.whl Python 3 none any Details for ResourceBundle-2.0.1-py3-none-any.whl

Total release size: 10.4 kB

Release files / ResourceBundle-2.0.1.tar.gz

Download URL ResourceBundle-2.0.1.tar.gz
Size 5.1 kB
Tags Source
SHA-256 checksum
How to use checksums
2a2b49e281211d4ce048e39023d1228268205cdad4d7831817d0309f69bf16a9
BLAKE2b-256 checksum
How to use checksums
a5da09e6f169b36299bb2731cb360afa5513ebcefe9e6fe2dcbb4b3273c747d4
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.1 CPython/3.9.15

Release files / ResourceBundle-2.0.1-py3-none-any.whl

Download URL ResourceBundle-2.0.1-py3-none-any.whl
Size 5.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
6e75f10c8b3fbf49c679b132597cdd5e46d8208c3e81abf17a91e5b6dd367ba5
BLAKE2b-256 checksum
How to use checksums
67e96c8a99a4f21a28c21bf289f743d66e2c121a0e23328221183a634bb16af9
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.1 CPython/3.9.15

Security for ResourceBundle 2.0.1

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page