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'
True
>>> isinstance(robot, unicode)
True

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

>>> robot.default == u'${name} is a robot.'
True
>>> 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'
True
>>> new_robot.domain
'futurama'
>>> new_robot.default == u'${name} is a robot.'
True
>>> new_robot.mapping == {u'name': u'Bender'}
True

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'})
True
>>> fembot = Message(u'fembot')
>>> callable, args = fembot.__reduce__()
>>> callable is Message
True
>>> args == (u'fembot', None, None, None)
True

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.6.0 (unreleased)

3.5.3 (2010-08-10)

  • Made compilation of C extension optional again; 3.5.1 broke this inasmuch as this package become unusable on non-CPython platforms. Making the compilation of the C extension optional again implied removing setup.py code added in 3.5.1 which made the C extension a setuptools “Feature” and readding code from 3.5.0 which overrides the distutils build_ext command.

  • Move pickle equality tests into a unittest.TestCase test to make it easier to condition the tests on whether the C extension has been compiled. This also makes the tests pass on Jython.

3.5.2 (2010-04-30)

  • Removed use of ‘zope.testing.doctestunit’ in favor of stdlib’s ‘doctest.

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.

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.6.0.tar.gz (15.3 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.6.0.win-amd64-py2.7.exe (250.3 kB view details)

Uploaded Source

zope.i18nmessageid-3.6.0.win-amd64-py2.6.exe (250.3 kB view details)

Uploaded Source

zope.i18nmessageid-3.6.0.win32-py2.7.exe (222.8 kB view details)

Uploaded Source

zope.i18nmessageid-3.6.0.win32-py2.6.exe (222.8 kB view details)

Uploaded Source

zope.i18nmessageid-3.6.0-py2.7-win-amd64.egg (22.3 kB view details)

Uploaded Egg

zope.i18nmessageid-3.6.0-py2.7-win32.egg (22.5 kB view details)

Uploaded Egg

zope.i18nmessageid-3.6.0-py2.6-win-amd64.egg (22.4 kB view details)

Uploaded Egg

zope.i18nmessageid-3.6.0-py2.6-win32.egg (22.5 kB view details)

Uploaded Egg

zope.i18nmessageid-3.6.0-py2.5-win32.egg (22.1 kB view details)

Uploaded Egg

zope.i18nmessageid-3.6.0-py2.4-win32.egg (22.1 kB view details)

Uploaded Egg

File details

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

File metadata

File hashes

Hashes for zope.i18nmessageid-3.6.0.tar.gz
Algorithm Hash digest
SHA256 9095eb3d322c90a68a87c7e410926da0faf50d18845b2bdfcb0ca429e939a81f
MD5 33c25a9343a2768bf34e76056fff7e04
BLAKE2b-256 2ab868b8a243d2bd7d85595ca6a2d9236b74f80f2c6444a3dfc80dd3c5400bf4

See more details on using hashes here.

File details

Details for the file zope.i18nmessageid-3.6.0.win-amd64-py2.7.exe.

File metadata

File hashes

Hashes for zope.i18nmessageid-3.6.0.win-amd64-py2.7.exe
Algorithm Hash digest
SHA256 7fd29bcc50f9cbe74e96cfc3266f2b06a184cfe169fc7c6e2925426dff6019b9
MD5 fc3d748b9f53b67808bed7ce649dd1d1
BLAKE2b-256 b9504e90243e80dfe125ca0a6248cbb5a33e2c943b1ebf4a4577848111a9e012

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for zope.i18nmessageid-3.6.0.win-amd64-py2.6.exe
Algorithm Hash digest
SHA256 9d4cab9e83bf6e15e75b2aed651a0f0fc151ddd224ce35d4e151877c11534c31
MD5 4bd796b252a6c6c6c64cfb540823cdcb
BLAKE2b-256 a9c14db8cd50cb49ea4541a9f957e81bffff17a972585ceaf00b16330d8186c0

See more details on using hashes here.

File details

Details for the file zope.i18nmessageid-3.6.0.win32-py2.7.exe.

File metadata

File hashes

Hashes for zope.i18nmessageid-3.6.0.win32-py2.7.exe
Algorithm Hash digest
SHA256 80a42a49fbdd0bbc602cc272f5c4334d962de25ae03f4b8e6ea7097834b1353d
MD5 7193d217f279dab9edb91533fc4d6dd5
BLAKE2b-256 9b44b4b990a646d70c6010fbfa757966042c060bfd7a4c7cf6c6b7ba27477fe4

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for zope.i18nmessageid-3.6.0.win32-py2.6.exe
Algorithm Hash digest
SHA256 ebb65e231768f815b03a4f0d39fa9890611a5af48b48393dba5f83d9b97c1d10
MD5 11b0906502071b7805088dc8bb5c94d6
BLAKE2b-256 6927df9e29d5612d448511ac3ff4e526751d55216f444a9027a4fb11871f5cd1

See more details on using hashes here.

File details

Details for the file zope.i18nmessageid-3.6.0-py2.7-win-amd64.egg.

File metadata

File hashes

Hashes for zope.i18nmessageid-3.6.0-py2.7-win-amd64.egg
Algorithm Hash digest
SHA256 be4394111b840e30f1dae2062224708fd434f6a00fe8d6856b96f55e8e9a6ada
MD5 f75e7dd9d8c8bb0fe2dc0135950285ab
BLAKE2b-256 418037bd346c680a4fe63a48c9d0f4b49af98c7742f3974c7b9212dd89845d01

See more details on using hashes here.

File details

Details for the file zope.i18nmessageid-3.6.0-py2.7-win32.egg.

File metadata

File hashes

Hashes for zope.i18nmessageid-3.6.0-py2.7-win32.egg
Algorithm Hash digest
SHA256 ac00adf70356f4457d8927c762267db56504dac5d90e4e3b1efbc2798a4376f8
MD5 8c486a2a81560ca4ac47b090d81fecb0
BLAKE2b-256 860d48eedab203a64b459e6708fdf7d97c94095c079cf947cb2ac5bef74e697d

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for zope.i18nmessageid-3.6.0-py2.6-win-amd64.egg
Algorithm Hash digest
SHA256 49eb48404f19a41dd81d3a1a6c11ba08f864d0804de382797265ff82ffbca033
MD5 a05763660edf116c33ff8df5e5e1c427
BLAKE2b-256 1d546561302bba0ec35d4eb313d1c8b45f7ee580eb13d56b650bc0589ee26d3f

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for zope.i18nmessageid-3.6.0-py2.6-win32.egg
Algorithm Hash digest
SHA256 af206a1677e48fc3cdb723a5bbcffae8dd093fa04e3adb4d532382314892146c
MD5 1a99bc1ab793d2e264e90e3c14414fcb
BLAKE2b-256 a41ac21503aad32559ea4e12775417779c76a066dfa8cbd1889b932775a429f5

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for zope.i18nmessageid-3.6.0-py2.5-win32.egg
Algorithm Hash digest
SHA256 fc1a95ff9d496017233e867c54ab3b1805244c2eb65b3626ebfd72aac2c88cf3
MD5 59b9222503469c42f7bbfa6943e73e7e
BLAKE2b-256 06273a650e893af9563d74a4edadbf15a643afb82698b0a8fe601172e2004cbb

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for zope.i18nmessageid-3.6.0-py2.4-win32.egg
Algorithm Hash digest
SHA256 7ac3535a17c709b8fce06698572d242b06a2c1c90819a40733a9fa635498871e
MD5 0071a84cad69e765eaea223569a36a87
BLAKE2b-256 25a861ce2603e1383ebb6ac7c95634260d971361257e5c8c08de1f500248023a

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