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.1 (2011-07-20)

  • Correct metadata in this file for release date.

3.6.0 (2011-07-20)

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.1.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.1.win-amd64-py2.7.exe (250.4 kB view details)

Uploaded Source

zope.i18nmessageid-3.6.1.win-amd64-py2.6.exe (250.4 kB view details)

Uploaded Source

zope.i18nmessageid-3.6.1.win32-py2.7.exe (223.0 kB view details)

Uploaded Source

zope.i18nmessageid-3.6.1.win32-py2.6.exe (223.0 kB view details)

Uploaded Source

zope.i18nmessageid-3.6.1-py2.7-win-amd64.egg (22.4 kB view details)

Uploaded Egg

zope.i18nmessageid-3.6.1-py2.7-win32.egg (22.6 kB view details)

Uploaded Egg

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

Uploaded Egg

zope.i18nmessageid-3.6.1-py2.6-win32.egg (22.6 kB view details)

Uploaded Egg

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

Uploaded Egg

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

Uploaded Egg

File details

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

File metadata

File hashes

Hashes for zope.i18nmessageid-3.6.1.tar.gz
Algorithm Hash digest
SHA256 a551e90baa20079aaf96a8b11f685168a03e0964843d0c344a8bdd465649e47d
MD5 6716cd769c006b5e90af030f83592600
BLAKE2b-256 a602cebc3419d4712e58b7086e2a6a165b33f71aa08732f4295a202de04f0a40

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for zope.i18nmessageid-3.6.1.win-amd64-py2.7.exe
Algorithm Hash digest
SHA256 3af74a1fb2831afac5317a41c1b2d672876a1e84e965cefe2b8fe158d160dbe0
MD5 7b54c4597055f7ae204bde0f2af5284c
BLAKE2b-256 897b7958e961acf9ac2c05bd9cc4d2f709d9272e8dfc1eae6a902d4c79408344

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for zope.i18nmessageid-3.6.1.win-amd64-py2.6.exe
Algorithm Hash digest
SHA256 11db2f6f9895021a19ab58b59b9deb0834eb48a38461bdf553ad9ddaebf5813a
MD5 37d446fcb23b0c9c0e70e819c69b38cc
BLAKE2b-256 d677b27e231faae3aa35a6d1105bab75b5ff2a58f14086c1accce612d555b255

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for zope.i18nmessageid-3.6.1.win32-py2.7.exe
Algorithm Hash digest
SHA256 8204d2d152d9a621764d53d8e5a6f7e2d1b125f71592d2d8d119dfce5abedac0
MD5 4af49a758329478062df5bae1376694c
BLAKE2b-256 df21dfa1e40b8b85cf08567a6f0de9fb1416fd1b338b4037a3199b6bbf953c89

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for zope.i18nmessageid-3.6.1.win32-py2.6.exe
Algorithm Hash digest
SHA256 5e22d2ad2cf164739dc7388dd9b45c7d7a8fe5a57b8868be16a718ed1a1f5478
MD5 040db1bd3475cf8dc6a2d4256ca876e4
BLAKE2b-256 4c846e3fb6b25d1ef1a6f58f79974226dc41f901b44e75af15f52baa394a527a

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for zope.i18nmessageid-3.6.1-py2.7-win-amd64.egg
Algorithm Hash digest
SHA256 0e76197d9573a0695586e56552614c8bd4c4775b97080c468b065547d704524c
MD5 5302f538ee1631b3781fa656befb828b
BLAKE2b-256 6fa58a8f84e160126b7e1fd88db586b08f40e99cb38f35865fc7b1a975b37722

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for zope.i18nmessageid-3.6.1-py2.7-win32.egg
Algorithm Hash digest
SHA256 4ad6614ccea5c6c211b82a71d32bb129333c530c2ea2d99f990b6d5b1025dacd
MD5 ee14fc987005e479d307e246ed3ae219
BLAKE2b-256 49dbb4d853546cd8882d594741c0ab9304106e0001947e345e6e16b9e8a17bef

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for zope.i18nmessageid-3.6.1-py2.6-win-amd64.egg
Algorithm Hash digest
SHA256 ff358787ce0f80c1420b5aaf0734e7e9aaaa4754166b8605252e7db9efa100dc
MD5 995f6f1570074c96c6f80bb21fd9e859
BLAKE2b-256 0a49cfe25d42412cbea4ec6e2fa512a65584039fb58db1f635507af8b5a04bb3

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for zope.i18nmessageid-3.6.1-py2.6-win32.egg
Algorithm Hash digest
SHA256 3c3e41e0536f2d89496ea4ef37be4dc9f8aad91e0111b7fadff12fff22610419
MD5 ac27bdd4af6fe0a064f3af5b7ffccec4
BLAKE2b-256 7e6629422f5f0b4069a0d6d770289dc818493663c2ec29482f7a83148ad9dcb2

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for zope.i18nmessageid-3.6.1-py2.5-win32.egg
Algorithm Hash digest
SHA256 ff34a097fa98e7781816fa82e54728e94b6787e9293895c0713177851fea3736
MD5 4a96aa5587bdd4bef5bb73be969b8677
BLAKE2b-256 3660984a701d371df17101131e5ebca505e1fc6d54df86cbd5f90611545b5145

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for zope.i18nmessageid-3.6.1-py2.4-win32.egg
Algorithm Hash digest
SHA256 e1e93c3bb1dcc0e9a0de9c36fc31bb0acb1941172b6c0fbc91293cbd3546abc3
MD5 0bbb9779783d1d8aecbda8af9bda8d4c
BLAKE2b-256 9b3f11b04623d68f1a8c087989109f764bd5c2ca8bea50b2b2d3e5e620c6c0e0

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