Skip to main content

Message Identifiers for internationalization

Project description

To translate any text, we must be able to discover the source domain of the text. A source domain is an identifier that identifies a project that produces program source strings. Source strings occur as literals in python programs, text in templates, and some text in XML data. The project implies a source language and an application context.

We can think of a source domain as a collection of messages and associated translation strings.

We often need to create unicode strings that will be displayed by separate views. The view cannot translate the string without knowing its source domain. A string or unicode literal carries no domain information, therefore we use messages. Messages are unicode strings which carry a translation source domain and possibly a default translation. They are created by a message factory. The message factory is created by calling MessageFactory with the source domain.

This package provides facilities for declaring such messages within program source text; translation of the messages is the responsiblitiy of the ‘zope.i18n’ package.

I18n Messages

Rationale

To translate any text, we must be able to discover the source domain of the text. A source domain is an identifier that identifies a project that produces program source strings. Source strings occur as literals in python programs, text in templates, and some text in XML data. The project implies a source language and an application context.

We can think of a source domain as a collection of messages and associated translation strings.

We often need to create unicode strings that will be displayed by separate views. The view cannot translate the string without knowing its source domain. A string or unicode literal carries no domain information, therefore we use messages. Messages are unicode strings which carry a translation source domain and possibly a default translation. They are created by a message factory. The message factory is created by calling MessageFactory with the source domain.

ZopeMessageFactory

>>> from zope.i18nmessageid import ZopeMessageFactory as _z_
>>> foo = _z_('foo')
>>> foo.domain
'zope'

Example

In this example, we create a message factory and assign it to _. By convention, we use _ as the name of our factory to be compatible with translatable string extraction tools such as xgettext. We then call _ with a string that needs to be translatable:

>>> from zope.i18nmessageid import MessageFactory, Message
>>> _ = MessageFactory("futurama")
>>> robot = _(u"robot-message", u"${name} is a robot.")

Messages at first seem like they are unicode strings:

>>> robot
u'robot-message'
>>> isinstance(robot, unicode)
True

The additional domain, default and mapping information is available through attributes:

>>> robot.default
u'${name} is a robot.'
>>> robot.mapping
>>> robot.domain
'futurama'

The message’s attributes are considered part of the immutable message object. They cannot be changed once the message id is created:

>>> robot.domain = "planetexpress"
Traceback (most recent call last):
...
TypeError: readonly attribute
>>> robot.default = u"${name} is not a robot."
Traceback (most recent call last):
...
TypeError: readonly attribute
>>> robot.mapping = {u'name': u'Bender'}
Traceback (most recent call last):
...
TypeError: readonly attribute

If you need to change their information, you’ll have to make a new message id object:

>>> new_robot = Message(robot, mapping={u'name': u'Bender'})
>>> new_robot
u'robot-message'
>>> new_robot.domain
'futurama'
>>> new_robot.default
u'${name} is a robot.'
>>> new_robot.mapping
{u'name': u'Bender'}

Last but not least, messages are reduceable for pickling:

>>> callable, args = new_robot.__reduce__()
>>> callable is Message
True
>>> args
(u'robot-message', 'futurama', u'${name} is a robot.', {u'name': u'Bender'})
>>> fembot = Message(u'fembot')
>>> callable, args = fembot.__reduce__()
>>> callable is Message
True
>>> args
(u'fembot', None, None, None)

Message IDs and backward compatability

The change to immutability is not a simple refactoring that can be coped with backward compatible APIs–it is a change in semantics. Because immutability is one of those “you either have it or you don’t” things (like pregnancy or death), we will not be able to support both in one implementation.

The proposed solution for backward compatability is to support both implementations in parallel, deprecating the mutable one. A separate factory, MessageFactory, instantiates immutable messages, while the deprecated old one continues to work like before.

The roadmap to immutable-only message ids is proposed as follows:

Zope 3.1: Immutable message ids are introduced. Security declarations for mutable message ids are provided to make the stripping of security proxies unnecessary.

Zope 3.2: Mutable message ids are deprecated.

Zope 3.3: Mutable message ids are removed.

CHANGES

3.5.1 (2010-04-10)

  • LP #257657 / 489529: Fix memory leak in C extension.

  • Fixed the compilation of the C extension with python 2.6: refactored it as a setuptools Feature.

3.5.0 (2009-06-27)

  • Made compilation of C extension optional.

  • Added support to bootstrap on Jython.

  • Changed package’s mailing list address from zope3-dev at zope.org to zope-dev at zope.org, because zope3-dev is now retired.

  • Reformatted change log to common formatting style.

  • Update package description and docs a little.

  • Remove old .cfg files for zpkg.

3.4.3 (2007-09-26)

  • Make PyPI the home URL.

3.4.2 (2007-09-25)

  • Moved the ZopeMessageFactory from zope.app.i18n to this package.

3.4.0 (2007-07-19)

  • Remove incorrect dependency.

  • Create final release to reflect package status.

3.2.0 (2006-01-05)

  • Corresponds to the verison of the zope.i18nmessageid package shipped as part of the Zope 3.2.0 release.

  • Implemented ‘zope.i18nmessageid.message’ as a C extension.

  • Deprecated ‘zope.i18nmessageid.messageid’ APIs (‘MessageID’, ‘MessageIDFactory’) in favor of replacements in ‘zope.i18nmessageid.message’ (‘Message’, ‘MessageFactory’). Deprecated items are scheduled for removal in Zope 3.3.

3.0.0 (2004-11-07)

  • Corresponds to the verison of the zope.i18nmessageid package shipped as part of the Zope X3.0.0 release.

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

zope.i18nmessageid-3.5.1.tar.gz (9.5 kB view details)

Uploaded Source

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

zope.i18nmessageid-3.5.1.win-amd64-py2.6.exe (248.1 kB view details)

Uploaded Source

zope.i18nmessageid-3.5.1.win32-py2.6.exe (220.7 kB view details)

Uploaded Source

zope.i18nmessageid-3.5.1-py2.6-win-amd64.egg (20.6 kB view details)

Uploaded Egg

zope.i18nmessageid-3.5.1-py2.6-win32.egg (20.8 kB view details)

Uploaded Egg

zope.i18nmessageid-3.5.1-py2.5-win32.egg (19.8 kB view details)

Uploaded Egg

zope.i18nmessageid-3.5.1-py2.4-win32.egg (19.8 kB view details)

Uploaded Egg

File details

Details for the file zope.i18nmessageid-3.5.1.tar.gz.

File metadata

File hashes

Hashes for zope.i18nmessageid-3.5.1.tar.gz
Algorithm Hash digest
SHA256 62d65939f69371d5aa8ff6e5f951cb28df8883a9fe6f86cd886062b924731d37
MD5 2739ef71ab6f3745b5db265336b68384
BLAKE2b-256 fded36aa304aafaa5d802bb2a5e4f514afcbe6b1769a7b003244b5d9c321ed41

See more details on using hashes here.

File details

Details for the file zope.i18nmessageid-3.5.1.win-amd64-py2.6.exe.

File metadata

File hashes

Hashes for zope.i18nmessageid-3.5.1.win-amd64-py2.6.exe
Algorithm Hash digest
SHA256 29028dd4daea9a567839278739d59815dc5ebb463866657f0ae8f5e93f0ba458
MD5 01eaafc39687db3284f4fd69a97f9a8d
BLAKE2b-256 080b23c6a7a3382a834779f9a7d0099de3aebb778f3ddce2c8a1abe5b43562cb

See more details on using hashes here.

File details

Details for the file zope.i18nmessageid-3.5.1.win32-py2.6.exe.

File metadata

File hashes

Hashes for zope.i18nmessageid-3.5.1.win32-py2.6.exe
Algorithm Hash digest
SHA256 41b6c10de72e40a3d4cd57dadaa6559951000b8c2e3ef976e914f8dde2dd76d6
MD5 4790303457be85034a86c138db421fa7
BLAKE2b-256 32d58cdc5dc7bc033f49d0ad95eb9c60c8ea5af855233a97874b0cbd9b3eb8a6

See more details on using hashes here.

File details

Details for the file zope.i18nmessageid-3.5.1-py2.6-win-amd64.egg.

File metadata

File hashes

Hashes for zope.i18nmessageid-3.5.1-py2.6-win-amd64.egg
Algorithm Hash digest
SHA256 c6e31ccd0d2fde468abf16bdea20ca1766e8c229ba6f96277136922ce6be6c0a
MD5 ae2c1d2aa78f9a0e3cc2ee32b2127728
BLAKE2b-256 c968db55a09a4c8889698d3eb21d1f490e6aa4e3e29315159d71ab97c75b08ae

See more details on using hashes here.

File details

Details for the file zope.i18nmessageid-3.5.1-py2.6-win32.egg.

File metadata

File hashes

Hashes for zope.i18nmessageid-3.5.1-py2.6-win32.egg
Algorithm Hash digest
SHA256 9f7a7f999db956a5d8e345b268b5b6cb301017361f7f38e0dfa5776ceddb6413
MD5 89855c9c90d848a5aa662f5f43f5136d
BLAKE2b-256 5cf6fa24a9d01d22c5c90612abe5b2dd156706053528f12b381608f76f89168b

See more details on using hashes here.

File details

Details for the file zope.i18nmessageid-3.5.1-py2.5-win32.egg.

File metadata

File hashes

Hashes for zope.i18nmessageid-3.5.1-py2.5-win32.egg
Algorithm Hash digest
SHA256 82014140c9e3f801b624cdcf87f4cd2f5b9573b378881bd9b84148aacafef719
MD5 2e11fea7171363c5b097077510028cb6
BLAKE2b-256 c4264bc42655f79e9a65ce021a1568c3ab94f25ea73d0f7d26b46d304d79e1d3

See more details on using hashes here.

File details

Details for the file zope.i18nmessageid-3.5.1-py2.4-win32.egg.

File metadata

File hashes

Hashes for zope.i18nmessageid-3.5.1-py2.4-win32.egg
Algorithm Hash digest
SHA256 330bf1400e752c3f09e3177442bae4310a0d5023b856c44f2bcc2551e0df06d0
MD5 c5aaca8039dae7f5b7aac73e506c5074
BLAKE2b-256 83114d2e79450c32272e0e8413c28d8a95ac9842cbd74d5cd0be0105853669dc

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page