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.3

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.3
File Size Uploaded Provenance Actions
ResourceBundle-2.0.3.tar.gz 5.4 kB Without provenance Details for ResourceBundle-2.0.3.tar.gz

Built distribution (wheel)

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

Total release size: 11.1 kB

Release files / ResourceBundle-2.0.3.tar.gz

Download URL ResourceBundle-2.0.3.tar.gz
Size 5.4 kB
Tags Source
SHA-256 checksum
How to use checksums
7c72448852304be61053a37ba1311f5580f81bda77d61627ef0408c4d191251e
BLAKE2b-256 checksum
How to use checksums
6b5fa29c5e1d89f9a74ad57f9bc0968cca0eab4883ed24bd1dcdc3548d659466
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.3-py3-none-any.whl

Download URL ResourceBundle-2.0.3-py3-none-any.whl
Size 5.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
97188f6ebe83566be7f695038a26a53dd2210e67d1a17825c0c737cf7ce9b7a9
BLAKE2b-256 checksum
How to use checksums
ab9fb238fd97fe8aadc8106e994614c8de60544714bb628145cd583b88c64c85
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.3

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