Registry / serialization / zope-i18nmessageid

zope-i18nmessageid

JSON →
library8.2pypypi✓ verified 89d ago

zope.i18nmessageid is a Python library, currently at version 8.2, that provides facilities for declaring translatable message identifiers within program source text. These message IDs encapsulate the untranslated string, a translation domain, and optional default values or substitutions. While this package handles the *declaration* of messages, their actual *translation* is the responsibility of the complementary zope.i18n package. It is actively maintained by the Zope Foundation.

pip install zope.i18nmessageid
INSTALL
IMPORT
SIG · ZOPE-I18NMESSAGEID
Z
zope-i18nmessageid
serializationpythonv8.2
Install
1.8s avg
Import
—
Disk
18MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.9–3.13
musl
3.9–3.13
Install & Compatibility
Where this runs
tested against v8.2 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.10–3.920 runs
installs and imports cleanly · install 0.0s · import 0.000s · 19.8MB
glibc
py 3.10–3.920 runs
installs and imports cleanly · install 1.8s · import 0.000s · 21MB
18MB installed
● package 18MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

MessageFactory
✓ from zope.i18nmessageid import MessageFactory
✗ from zope.i18nmessageid.messageid import MessageIDFactory
The MessageIDFactory and MessageID APIs were deprecated in favor of MessageFactory and Message (from zope.i18nmessageid.message) in zope.i18nmessageid 3.2.0 (released 2006).
Message
✓ from zope.i18nmessageid.message import Message
✗ from zope.i18nmessageid.messageid import MessageID
The MessageIDFactory and MessageID APIs were deprecated in favor of MessageFactory and Message (from zope.i18nmessageid.message) in zope.i18nmessageid 3.2.0 (released 2006).

To use zope.i18nmessageid, you typically import `MessageFactory`, create an instance bound to your application's translation domain, and then use this factory to mark strings for translation. The resulting objects are `Message` instances, which carry the original string, domain, and any substitution mappings. Actual translation into a target language requires the `zope.i18n` package.

from zope.i18nmessageid import MessageFactory # Define a message factory for your application's domain # This is conventionally named '_' in many i18n contexts. _ = MessageFactory('my.application.domain') # Create a translatable message ID greeting_msg = _('Hello, world!') print(f"Raw Message ID: {greeting_msg!r}") # Expected output for MessageID: <MessageID u'Hello, world!' domain='my.application.domain'> # Message IDs can include variables for substitution variable_msg = _('Welcome, ${name}!', mapping={'name': 'User'}) print(f"Raw Message ID with mapping: {variable_msg!r}") # Expected output: <MessageID u'Welcome, ${name}!' domain='my.application.domain' mapping={'name': 'User'}>
Debug
Known issues
deprecatedThe `MessageID` and `MessageIDFactory` APIs from `zope.i18nmessageid.messageid` were deprecated in favor of `Message` and `MessageFactory` (imported directly from `zope.i18nmessageid` or `zope.i18nmessageid.message`).
fix
Update imports to use `from zope.i18nmessageid import MessageFactory` and directly create `Message` objects if needed, or rely on the factory to create them.
affects: < 3.2.0 (deprecated in 3.2.0, released 2006)
gotchaThis package only provides facilities for *declaring* message identifiers. It does not perform the actual translation of these messages into different languages. For translation, the `zope.i18n` package must be used in conjunction with message catalogs (e.g., PO/MO files).
fix
Ensure `zope.i18n` is installed and properly configured if runtime translation is desired. Understand that `zope.i18nmessageid` primarily serves as a way to mark and carry translatable strings with their context.
affects: All versions
gotchaWhen passing a `Message` object to `zope.i18n.translate` (the separate translation utility) along with an explicit `mapping` argument, the `mapping` provided directly to `translate` might override or not correctly merge with the mapping already present in the `Message` object, potentially leading to lost substitutions.
fix
If dynamic substitutions are needed, ensure the `Message` object is created with the *complete* desired `mapping` from the start, or create a new `Message` object with the combined mapping before passing it to `translate`. Directly passing `unicode(X)` to `translate` will lose domain and default message information.
affects: Potentially all versions when interacting with `zope.i18n.translate`
Errors
Common errors & fixes
ImportError: cannot import name 'MessageFactory' from 'zope.i18n'
The `MessageFactory` class is defined in the `zope.i18nmessageid` package, not in the `zope.i18n` package.
fix
from zope.i18nmessageid import MessageFactory
TypeError: MessageFactory.__init__() missing 1 required positional argument: 'domain'
The `MessageFactory` class constructor requires a string argument representing the translation domain.
fix
my_factory = MessageFactory('my.translation.domain')
TypeError: Message: 'text' argument must be str
The primary message argument passed to the message factory callable must be a string (or unicode in Python 2), but a different type was provided.
fix
my_factory = MessageFactory('my.domain')
my_factory('This is a string message')
AttributeError: 'Message' object has no attribute 'translate'
The `Message` object from `zope.i18nmessageid` is a declaration of a translatable string; actual translation functionality resides in the separate `zope.i18n` package.
fix
from zope.i18n import translate
# assuming 'msg' is a Message object and 'request' is available
translated_text = translate(msg, context=request)
TypeError: MessageFactory.__init__() got an unexpected keyword argument 'default'
The `default` argument, which provides a fallback message, should be passed when calling the message factory's generated function, not during the initialization of `MessageFactory` itself.
fix
my_factory = MessageFactory('my.domain')
message_obj = my_factory('Hello World', default='Hi There!')
Upgrade
Version history
8.2latest on PyPI · released Nov 18, 2025
Audit
Dependencies
zope.i18noptionalThis package declares message IDs; zope.i18n is required for performing actual translations.
Agent activity
47 hits · last 30 days
node
38
Anthropic
1
OpenAI (training)
1
Resources
zope-i18nmessageid — pip install zope-i18nmessageid · libregistry