Metadata-Version: 2.1
Name: ResourceBundle
Version: 2.0.3
Summary: ResourceBundle is a module that manages internationalization of string resources
Home-page: https://felix-zenk.github.io/projects/ResourceBundle
Author: Felix Zenk
Author-email: felix.zenk@web.de
Project-URL: Bug Reports, https://github.com/felix-zenk/ResourceBundle/issues
Project-URL: Source, https://github.com/felix-zenk/ResourceBundle
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.6
Classifier: Programming Language :: Python :: 3.7
Classifier: Programming Language :: Python :: 3.8
Classifier: Programming Language :: Python :: 3.9
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Topic :: Utilities
Classifier: License :: OSI Approved :: MIT License
Classifier: Operating System :: OS Independent
Requires-Python: >=3.6
Description-Content-Type: text/markdown
License-File: LICENSE

# ResourceBundle

[![PyPI-Versions](https://img.shields.io/pypi/pyversions/ResourceBundle)](https://pypi.org/project/ResourceBundle)
[![PyPI version](https://badge.fury.io/py/ResourceBundle.svg)](https://pypi.org/project/ResourceBundle)
[![License](https://img.shields.io/github/license/felix-zenk/onboardapis)](https://github.com/felix-zenk/onboardapis/blob/main/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](https://pypi.org/project/ResourceBundle):

```bash
$  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.

```python
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.

```python
import ResourceBundle

bundle = ResourceBundle.get_bundle("Strings")

everything = dict(bundle)
while bundle.parent is not None:
    bundle = bundle.parent
    everything.update(dict(bundle))
```
