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.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.

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.3.tar.gz (13.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.5.3.win-amd64-py2.7.exe (249.6 kB view details)

Uploaded Source

zope.i18nmessageid-3.5.3.win-amd64-py2.6.exe (249.6 kB view details)

Uploaded Source

zope.i18nmessageid-3.5.3.win32-py2.7.exe (222.2 kB view details)

Uploaded Source

zope.i18nmessageid-3.5.3.win32-py2.6.exe (222.2 kB view details)

Uploaded Source

zope.i18nmessageid-3.5.3-py2.7-win-amd64.egg (21.9 kB view details)

Uploaded Egg

zope.i18nmessageid-3.5.3-py2.7-win32.egg (22.1 kB view details)

Uploaded Egg

zope.i18nmessageid-3.5.3-py2.6-win-amd64.egg (21.9 kB view details)

Uploaded Egg

zope.i18nmessageid-3.5.3-py2.6-win32.egg (22.1 kB view details)

Uploaded Egg

zope.i18nmessageid-3.5.3-py2.5-win32.egg (21.6 kB view details)

Uploaded Egg

zope.i18nmessageid-3.5.3-py2.4-win32.egg (21.7 kB view details)

Uploaded Egg

File details

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

File metadata

File hashes

Hashes for zope.i18nmessageid-3.5.3.tar.gz
Algorithm Hash digest
SHA256 7f423e40969de31ad9b93e7e0241ff1d9d9e02ff15c3309fa9fa69daedd9c71b
MD5 cb84bf61c2b7353e3b7578057fbaa264
BLAKE2b-256 1ecb3478d8ce7683d359dfdeedba289d05aec1418940136ed32f4c2b4e368793

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for zope.i18nmessageid-3.5.3.win-amd64-py2.7.exe
Algorithm Hash digest
SHA256 7fb86fc34cb1b6bcc38a087c8e91ed21a2eb39f490b9852a91676f3354e22e64
MD5 8a5ff48724ef83863545914d3775b91f
BLAKE2b-256 6c1ca651f56e9fd55ef25201cd7af881f4ce6a8af68c844b6ee3911f3790c050

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for zope.i18nmessageid-3.5.3.win-amd64-py2.6.exe
Algorithm Hash digest
SHA256 5b0dcbfe668dce4fae504e129e802d698f54c03a8343e8ab926e3f5df1837f1d
MD5 4f2fc6c6e6a73264e454ee258dfe6509
BLAKE2b-256 e7f15c24913f52099c5182ca8fe68b1f81312e5c938363cd653e020165f47c97

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for zope.i18nmessageid-3.5.3.win32-py2.7.exe
Algorithm Hash digest
SHA256 7e07191e25418ded2c986397f17f12a6416514f8605f0b6cbeacdce1a5eb8ebd
MD5 34d7c9090d6f81454b41feb436320f3a
BLAKE2b-256 e1007e267f006bbf47c87997d5c5ef31373caf698d5de2f7021f8134d70bf1a7

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for zope.i18nmessageid-3.5.3.win32-py2.6.exe
Algorithm Hash digest
SHA256 6b89d15e3c28c394fd3f53ac938e9df1633f4b6a0c96775120a85e557d406f54
MD5 5b647056797f0758b980f7b5a8217a73
BLAKE2b-256 25ef8e8f37767ff778eb0a7db07fd892e2c9475bf900db25001cabc3d9c1895c

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for zope.i18nmessageid-3.5.3-py2.7-win-amd64.egg
Algorithm Hash digest
SHA256 283517fa73479da0209436d0522e1dd7e93a293a4318a0548ce9f7361415db29
MD5 890fef2f024d22e5ae139ed9d2dc51d1
BLAKE2b-256 68ea71e78def5be8f4e3e41505f6cac04e2cbfcf10e4071da4e438f67bc72bef

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for zope.i18nmessageid-3.5.3-py2.7-win32.egg
Algorithm Hash digest
SHA256 1510940ad55fa4ab67249bbcf770ea842f1bed00748f56592fd84521d44c3ed2
MD5 ce779e387560142b84c4e80a846da614
BLAKE2b-256 8dd66d59f54f43697ff93a8ea3b4a5b6b1302180d137512b1519e3551b3ee015

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for zope.i18nmessageid-3.5.3-py2.6-win-amd64.egg
Algorithm Hash digest
SHA256 8787875fe0802448a3a89b83380452170266d48b2b348a724c53ba51a1f07bc6
MD5 961c6a8375773fd5ea9d14040d0b384a
BLAKE2b-256 767c6212f1b090649b8b5394683852a08b8ae38e87dca5d9d7a0dfff6dfda35d

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for zope.i18nmessageid-3.5.3-py2.6-win32.egg
Algorithm Hash digest
SHA256 f9b84dc34b87314f6c504c4328d5c2a0a13e7b3eae6c74cab8f9a022eed83c4c
MD5 5cd7cc2518dd6b7cdd1eab62c8c52354
BLAKE2b-256 3f685cda342fc95ec1fbfea68d4f0ec1253a92b7e06c4eba61f677a43c116e1d

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for zope.i18nmessageid-3.5.3-py2.5-win32.egg
Algorithm Hash digest
SHA256 641fb1e9a616c083736035325e4e34d14a16d37849e7a39231aeb0aa227bed59
MD5 e2c084b06b9c23c5af85773e34d9df9d
BLAKE2b-256 0a55330a0ee642d92515261536557419e082fcdf751a89f1b41a43ad07b01c73

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for zope.i18nmessageid-3.5.3-py2.4-win32.egg
Algorithm Hash digest
SHA256 dddb3195c01c52d56b3fa72ee127f491e964b29ae458afe55c60dd88a8ec38c7
MD5 a30c57126f800bcf17d068fae0703ae5
BLAKE2b-256 f9124525d45a92713aec35239da85f16b0d722df291234b3298015c844868230

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