ResourceBundle is a module that manages internationalization of string resources.
Project description
ResourceBundle
ResourceBundle is a package that manages internationalization / localization (i18n / l10n) of string resources.
It is inspired by Java's ResourceBundle and accepts the same format as a Java PropertyResourceBundle.
Note: ResourceBundle is not the pythonic way of internationalization / localization. This package is only intended to be used if you absolutely have to work with ResourceBundle files or need a quick working way when porting from Java.
For information on how to do internationalization in python, see the official documentation. You can use the
ResourceBundle.Converter.to_gettext()method to convert your ResourceBundle files to gettextpofiles.
Installation
The ResourceBundle module can be downloaded from PyPI:
# Linux / macOS
$ python3 -m pip install ResourceBundle
# Windows
> py -m pip install ResourceBundle
Usage
Assuming you come from Java, you are probably familiar with the ResourceBundle file format. If not, you can read about it here.
Get a ResourceBundle instance is by using ResourceBundle.get_bundle(name, locale).
import ResourceBundle
bundle = ResourceBundle.get_bundle("Strings", "en")
# 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.
If the key is not present in any of its parents a ResourceBundle.exceptions.NotInResourceBundleError will be raised.
gettext
The ResourceBundle module can convert ResourceBundle files to gettext pot / po files.
This can be done by using the ResourceBundle.Converter.to_gettext() method.
from ResourceBundle import Converter
# convert all .properties files in the current directory to .po files
Converter.to_gettext(".", ".")
Note however that this step is obsolete if you are using gettext properly
as this will include automatically extracting strings from your source code with the help of a library like
Babel with its pybabel tool.
The function is only intended as a head start to keep existing translations.
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file resourcebundle-2.2.0.tar.gz.
File metadata
- Download URL: resourcebundle-2.2.0.tar.gz
- Upload date:
- Size: 7.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.0.0 CPython/3.12.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
0b72659901082e46929e65e29bbe0ffe7fa16a209c2f4b551fb7be02ac7247f8
|
|
| MD5 |
ff9168b280c8743c2fb295d274a730ba
|
|
| BLAKE2b-256 |
de1b033b9f40c72561d76e7ce4e03a860b43b7deec4afd5a2f66af8d75200df4
|
File details
Details for the file ResourceBundle-2.2.0-py3-none-any.whl.
File metadata
- Download URL: ResourceBundle-2.2.0-py3-none-any.whl
- Upload date:
- Size: 7.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.0.0 CPython/3.12.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d5d817bb54a46fb27d91382ac3537a52aae6b7b0eb1eab0a5b9aedababa2d484
|
|
| MD5 |
f485d8f35459e55c29b01edf4db732aa
|
|
| BLAKE2b-256 |
cdce26159f42541bf572d213bc91978f01b913893f7013c930670b16da3dbf1d
|