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

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.5
File Size Uploaded Provenance Actions
ResourceBundle-2.0.5.tar.gz 5.8 kB Without provenance Details for ResourceBundle-2.0.5.tar.gz

Built distribution (wheel)

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

Total release size: 12.0 kB

Release files / ResourceBundle-2.0.5.tar.gz

Download URL ResourceBundle-2.0.5.tar.gz
Size 5.8 kB
Tags Source
SHA-256 checksum
How to use checksums
3dc128d9a1fa9bcfe4960f74ce9a07f1b885364a0cf884381135f05600a04176
BLAKE2b-256 checksum
How to use checksums
95f129b356effe5de078d1b636f0a3c83c9902347fc09e63e3cb9d1f8963b773
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.5-py3-none-any.whl

Download URL ResourceBundle-2.0.5-py3-none-any.whl
Size 6.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
46ce338b7185701d761ad36949ecc833d182bfa5495179edd6cce46c59f96858
BLAKE2b-256 checksum
How to use checksums
8be42fb9880b4f26f9dd0444b37ca9f7aae7f40d8ab546108aaae10775234fba
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.5

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