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.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.0.tar.gz (11.4 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.0.win-amd64-py2.6.exe (247.9 kB view details)

Uploaded Source

zope.i18nmessageid-3.5.0.win32-py2.6.exe (220.4 kB view details)

Uploaded Source

zope.i18nmessageid-3.5.0-py2.6-win-amd64.egg (20.5 kB view details)

Uploaded Egg

zope.i18nmessageid-3.5.0-py2.6-win32.egg (19.6 kB view details)

Uploaded Egg

zope.i18nmessageid-3.5.0-py2.5-win32.egg (19.6 kB view details)

Uploaded Egg

zope.i18nmessageid-3.5.0-py2.4-win32.egg (19.6 kB view details)

Uploaded Egg

File details

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

File metadata

File hashes

Hashes for zope.i18nmessageid-3.5.0.tar.gz
Algorithm Hash digest
SHA256 7172d9e7ac1f186070f306c864b218d28c556ba21dbbef24db7f34f99d608c30
MD5 1493049473c4e0418c42d32d33904e42
BLAKE2b-256 fb1fdb65f3f0355c0e7c8ed24fc036661900cc4069d3295d7d6ecb392f795055

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for zope.i18nmessageid-3.5.0.win-amd64-py2.6.exe
Algorithm Hash digest
SHA256 f9617e0767c2c5d5f643c1d6513607f0d56fb89645cd9fe333591c158640ca53
MD5 0cb77a517ba8285c19d429faf4141891
BLAKE2b-256 42276e112f197ea72fe00ccc621ac2daf75e20b7e0fafcb3d1db60db828da94c

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for zope.i18nmessageid-3.5.0.win32-py2.6.exe
Algorithm Hash digest
SHA256 df6e5272233c25ac320d923da271f6e545ddf8802e81519b98a69bff76832130
MD5 46578fd04e011364ff94236045920d00
BLAKE2b-256 5f306da3906bb903435d51ca42cd8d75ee4a95162c1b2ca67faf6c8c7fd6ce47

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for zope.i18nmessageid-3.5.0-py2.6-win-amd64.egg
Algorithm Hash digest
SHA256 36cb75389d4f7c64f25127a340e3648613f3a67e44897e435d03d292c817942b
MD5 2c7c88dd5297a34e682ac66cb88566ca
BLAKE2b-256 2d3c5f7d6168fb25e70e860b8c99aa20822fd7844db4c42f30dca6d5b9a33b93

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for zope.i18nmessageid-3.5.0-py2.6-win32.egg
Algorithm Hash digest
SHA256 06e1bbf3e377b2d78c631267f104b68e6fe7ad1549f824691036dda84506eda9
MD5 6f738af9ac5908b167087aff081789bf
BLAKE2b-256 98e8cdb735f6e0fe12990629de560daeac98f64473a248a3aab3fb2e1df45d52

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for zope.i18nmessageid-3.5.0-py2.5-win32.egg
Algorithm Hash digest
SHA256 52fab74247fad796907dae75e99db8b11210d549938c6a45312b16022741a72b
MD5 9235b91c4eaf51206c9732fa17795878
BLAKE2b-256 bcd54191c6f539b470b6298a3a0cd82d182946ad3253ed3e6fc99e52384fa16d

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for zope.i18nmessageid-3.5.0-py2.4-win32.egg
Algorithm Hash digest
SHA256 410c9d1b50a5b74fc7452ac177cc22cd4417965413e3d678b428bb352333e928
MD5 3ef7b5a0a6f0f00a0306b6b4923a3171
BLAKE2b-256 e40cfe5a67270a17bf181e062a56d068fea24849eae49977949453c5a3b74b16

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