ResourceBundle
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.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| ResourceBundle-2.0.0.tar.gz | 5.0 kB | Without provenance | Details for ResourceBundle-2.0.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| ResourceBundle-2.0.0-py3-none-any.whl | Python 3 | none | any | Details for ResourceBundle-2.0.0-py3-none-any.whl |
Total release size: 10.4 kB
Release files / ResourceBundle-2.0.0.tar.gz
| Download URL | ResourceBundle-2.0.0.tar.gz |
|---|---|
| Size | 5.0 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
d816f69cb75698d864b0fa62cc290608d6c7817f2e57a7fc06cedf0b77087729
|
|
BLAKE2b-256 checksum How to use checksums |
1da672388b97c501b4d9af6500a3a5873726df86e8f2ed59cd2dc2c7492a8a07
|
| 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.0-py3-none-any.whl
| Download URL | ResourceBundle-2.0.0-py3-none-any.whl |
|---|---|
| Size | 5.3 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
1833f5b0a6e5c87e3f75b3f260a617e1b7794ecc2c008cd1d2841872865a28a6
|
|
BLAKE2b-256 checksum How to use checksums |
53f8673493973432f7365c245aeff52843f3c54bbae20fb13f0e3ff06b2331bf
|
| 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.0
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.