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.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.2.zip (20.8 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.2.win-amd64-py2.6.exe (248.3 kB view details)

Uploaded Source

zope.i18nmessageid-3.5.2.win32-py2.6.exe (220.9 kB view details)

Uploaded Source

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

Uploaded Egg

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

Uploaded Egg

zope.i18nmessageid-3.5.2-py2.5-win32.egg (20.4 kB view details)

Uploaded Egg

zope.i18nmessageid-3.5.2-py2.4-win32.egg (20.4 kB view details)

Uploaded Egg

File details

Details for the file zope.i18nmessageid-3.5.2.zip.

File metadata

File hashes

Hashes for zope.i18nmessageid-3.5.2.zip
Algorithm Hash digest
SHA256 edf5bce452e4b4b4a0920cd5b6f852946865d9ca66e1a611d6ba0a8ffb9b8fa7
MD5 4a56aaf3510c0124b6128ed341efe76d
BLAKE2b-256 4eb64015897c68e3790cdeb4db3dc126dc521a522e7fc888bc52c31e4a29ee13

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for zope.i18nmessageid-3.5.2.win-amd64-py2.6.exe
Algorithm Hash digest
SHA256 27539f076685fc2d887d96177b27eccb211d98de253468501c704db5a718e3c9
MD5 3c965cba168d71dfa5d38c2b6c209bf5
BLAKE2b-256 abce82b3b070853910963600bf5f7cdc79693988be2b75bf38b890ff0864cad6

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for zope.i18nmessageid-3.5.2.win32-py2.6.exe
Algorithm Hash digest
SHA256 51febf0278e921825bfda255b624b2a681a322a92d044e0a951217adc5493732
MD5 ef0a88ce9a4ec46bf43279b477694d13
BLAKE2b-256 81baaa3b89e5a1ca74e1797d09914f2a2003156a43776bf1396ee514fabab67b

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for zope.i18nmessageid-3.5.2-py2.6-win-amd64.egg
Algorithm Hash digest
SHA256 d0fadc3f203e701319531e3b80554ec1b5fe921ee232470cc662a37517999da3
MD5 9175bb4f1adf8712ff895db58490b8d6
BLAKE2b-256 488292019348f6680376c138e04f87c7f8dae296cd6720c41bd41e0d4c156322

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for zope.i18nmessageid-3.5.2-py2.6-win32.egg
Algorithm Hash digest
SHA256 dd4d3094c1633d9c57c4cc097770d2ab6883687a6a708d25aa7afbd1baa020a6
MD5 cb5294c6ad0bb74a993dd49222ca6e31
BLAKE2b-256 f9ca5f3673710ff020a5d1c760f8976657011710bd65b9a3fd096e9d09396ddd

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for zope.i18nmessageid-3.5.2-py2.5-win32.egg
Algorithm Hash digest
SHA256 c6c80255e7a1cec38ecd0a4b1e156716e955c721e439e16d807595ed5ab2779b
MD5 a27532639ed055067d326be86b04a08a
BLAKE2b-256 cc1a8011667cf9a19715cb111ece8155b2a38b9596697b4aff6ee389f235ff6d

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for zope.i18nmessageid-3.5.2-py2.4-win32.egg
Algorithm Hash digest
SHA256 bbe14472d733f15354ccd74e48127a87320d887dab85afb3b560654fdb4ddd8c
MD5 b421470d204412594dcbf2f5fbfeb344
BLAKE2b-256 27fa1447c6bb3e3d7148e19e7563c43f1b84421a70cb616451e77d99b4f461d9

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