i18n Message improvements

Registered by Mathew Odden

During the Oslo meeting on 2013-10-11 (http://eavesdrop.openstack.org/meetings/oslo/2013/) we discussed the integration of Messages into OpenStack vs other approaches, and also came up with some ideas for improving the current implementation.

Blueprint information

Doug Hellmann
Luis A. Garcia
Luis A. Garcia
Series goal:
Accepted for icehouse
Milestone target:
milestone icon 2014.1
Started by
Doug Hellmann
Completed by
Luis A. Garcia

Related branches



Changes that need to happen:
 - Add a translate() method to Messages to use instead of str() or unicode()
    - translation to system locale done via translate(None)
    - update log.py::ContextAdapter to use translate()

 - str() and unicode() should raise RuntimeErrors to enforce proper usage (translate())
  - and return and error message pointing users to use translate()

 - OpenStack projects should be changed to expect Message objects from _() and handle accordingly

 - catch any Messages and resolve to unicode (using translate()) before they exit any OpenStack code

 - Implement __repr__ for implicit printing cases i.e. print _("hello world") where _() returns non-ascii encodable utf8 bytes

 - support .format() on Messages for now to handle _('Something {0}").format('otherthing') cases
    - translate() needs to support having a Message instance passed as an arg to __mod__ or .format()

- We should NOT support:
  - both __add__ and __radd__ since it implies using translated strings in "improper" ways
  - similarly, __mul__

Related etherpad link: https://etherpad.openstack.org/p/i18nmessages

Some background on the original thinking behind https://review.openstack.org/#/c/46553/

This is a very simple example of what happens if you disable the __str__ method: http://paste.openstack.org/show/48440/

Gerrit topic: https://review.openstack.org/#q,topic:bp/i18n-messages,n,z

Addressed by: https://review.openstack.org/56093
    Translation Message improvements

Retargeting to i-2 because I think there is still some discussion to be held about the implementation. - dhellmann

Addressed by: https://review.openstack.org/59847
    Allow the Message class to have non-English default locales

Addressed by: https://review.openstack.org/62508
    Enable setting up translation handler via CONF

Addressed by: https://review.openstack.org/65385
    Add support for locales missing from babel

Addressed by: https://review.openstack.org/71362
    Return the unicode representation of an object


Work Items

Dependency tree

* Blueprints in grey have been implemented.

This blueprint contains Public information 
Everyone can see this information.