ResourceBundle

raw JSON →
2.2.0 verified Fri May 01 auth: no python

ResourceBundle is an i18n module for managing string resources in Python, supporting .properties, JSON, and YAML formats. Current version is 2.2.0, requiring Python >=3.5. It follows Java ResourceBundle patterns with locale fallback.

pip install resourcebundle
error AttributeError: 'NoneType' object has no attribute 'get'
cause ResourceBundle returns None when a key is not found and no default is provided.
fix
Use bundle.get(key, default='default_value') to avoid None.
error resourcebundle.exceptions.ResourceBundleError: No resource file found for base name 'messages'
cause The base name does not correspond to any existing resource file in the specified path.
fix
Verify the base name spelling and that the file exists in the base_path directory.
error ImportError: cannot import name 'ResourceBundle' from 'resourcebundle'
cause Missing or incorrect installation of the resourcebundle package.
fix
Run 'pip install resourcebundle' to install the package.
breaking v2.0.0 introduced breaking changes to the API and file format support. Code written for v1.x may require migration.
fix Check the changelog and update your code to use the new API (e.g., ResourceBundle constructor arguments changed).
deprecated Built-in XML support is deprecated and may be removed in a future release.
fix Use JSON or YAML format instead of XML.
gotcha ResourceBundle silently accepts non-existent base names (until v2.0.1). In v2.0.1+, an error is raised if no files found.
fix Upgrade to v2.0.1 or later, or ensure the base name exists.
gotcha Line continuations in .properties files (using backslash) are only supported from v2.0.5 onward.
fix Upgrade to v2.0.5+ if you use multi-line property values.

Create a ResourceBundle with base name 'messages', locale 'en', and get a string 'greeting'.

from resourcebundle import ResourceBundle
import os
# Create a bundle with base name 'messages' in current directory
bundle = ResourceBundle('messages', base_path='.', locale='en')
print(bundle.get('greeting', default='Hello'))
# Output: Hello (or translated value if 'messages_en.properties' exists)