This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

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

Created on 2013-01-28 21:15 by carsten.klein@axn-software.de, last changed 2022-04-11 14:57 by admin. This issue is now closed.

Messages (4)
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.
msg404582 - (view) Author: Irit Katriel (iritkatriel) * (Python committer) Date: 2021-10-21 11:16
I can't find DeferredTranslation in the current codebase, and in any case the response from 8 years ago seems to be leaning towards reject.
History
Date User Action Args
2022-04-11 14:57:41adminsetgithub: 61269
2021-10-21 11:16:47iritkatrielsetstatus: open -> closed

nosy: + iritkatriel
messages: + msg404582

resolution: out of date
stage: resolved
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