|
6.25.3.4 Deferred translationsIn most coding situations, strings are translated were they are coded. Occasionally however, you need to mark strings for translation, but defer actual translation until later. A classic example is:
Here, you want to mark the strings in the Here is one way you can handle this situation:
This works because the dummy definition of _() simply returns the string unchanged. And this dummy definition will temporarily override any definition of _() in the built-in namespace (until the del command). Take care, though if you have a previous definition of _ in the local namespace. Note that the second use of _() will not identify ``a'' as being translatable to the pygettext program, since it is not a string. Another way to handle this is with the following example:
In this case, you are marking translatable strings with the function N_(),6.6 which won't conflict with any definition of _(). However, you will need to teach your message extraction program to look for translatable strings marked with N_(). pygettext and xpot both support this through the use of command line switches.
Footnotes
|