classification
Title: Examples in documentation for 3.x in 23.1.3.4. Deferred translations are rather weak
Type: enhancement Stage:
Components: Documentation Versions: Python 3.3
process
Status: open Resolution:
Dependencies: Superseder:
Assigned To: docs@python Nosy List: carsten.klein@axn-software.de, docs@python, r.david.murray
Priority: normal Keywords:

Created on 2013-01-28 21:15 by carsten.klein@axn-software.de, last changed 2013-01-28 22:01 by r.david.murray.

Messages (3)
msg180882 - (view) Author: Carsten Klein (carsten.klein@axn-software.de) Date: 2013-01-28 21:15
The examples for the topic presented are rather weak. In fact, they merely present do nothing replacements for an actually working, deferred localization mechanism or some sort of prototypical implementation thereof.

As such I propose that they be replaced with something more meaningful,
for example such as 


class DeferredTranslation(object):

    def __init__(self, message, ...):

        self.message = message

    def __str__(self):

        return gettext.translation(...).lgettext(self.message)


def _(message, ...):

    return DeferredTranslation(message, ...)


MSG = _('localized message')


Or something else along that way other than the currently presented examples :D
msg180883 - (view) Author: R. David Murray (r.david.murray) * (Python committer) Date: 2013-01-28 22:00
Thanks for your suggestion, but...

The example currently in the docs is exactly how we do deferred translation in the project I am currently working on.  Your example is much more complex, and I don't see the benefit of it.

Specifically, using the example in the docs you can easily mix deferred translations with non-deferred translations, which what you generally end up wanting to do in real code.  (You use deferred translation with strings that are defined at import time, as in the example, and non-deferred with strings that are computed at runtime.)

Perhaps there is a need for additional text about how this works in practice, including an example of switching the language dynamically during runtime.
msg180884 - (view) Author: R. David Murray (r.david.murray) * (Python committer) Date: 2013-01-28 22:01
Sorry, I didn't mean "computed at runtime", I meant defined in code where the _ call is *executed* at runtime, rather than at import time.
History
Date User Action Args
2013-01-28 22:01:28r.david.murraysetmessages: + msg180884
2013-01-28 22:00:14r.david.murraysetnosy: + r.david.murray
messages: + msg180883
2013-01-28 21:15:45carsten.klein@axn-software.decreate