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

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

Built distribution (wheel)

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

Total release size: 11.0 kB

Release files / ResourceBundle-2.0.2.tar.gz

Download URL ResourceBundle-2.0.2.tar.gz
Size 5.4 kB
Tags Source
SHA-256 checksum
How to use checksums
c02e811642013028768afac47d5467113853b46d04c68fa61380f3900d492786
BLAKE2b-256 checksum
How to use checksums
aaa84be9b4216c2e3c6cfe5b80138e32bd4dc5730ed83fc6b6fe5b9db04c1d34
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.2-py3-none-any.whl

Download URL ResourceBundle-2.0.2-py3-none-any.whl
Size 5.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
e7bdfc1fa89c3ed6fb5d84464c0c7c9baf727fc3e3a4639fe78d99e4e62e955b
BLAKE2b-256 checksum
How to use checksums
338b5630d0b1537951ec4a3a78df02d6680101cb0b581841e3fe4ff9a07cfdcc
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.2

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