Translation for variable names

Description

Consider HomepageTemplate and its translation to pt-br TemplateDePáginaPessoal. Consider also that page_template_regex was updated to match the translated title. It would be nice if the Brazilian template contained @eu@ rather than @me@. This will make variables more user-friendly, since they will use names in their own language. Note that the English name would also be available, not affecting thus those users already used to that scheme.

Patch

This patch will make translated names additional keys to variable values. The N_ is for telling gettext to export the variable names to the po file, so that they can be translated. Note that _() gives you a translation in some language X, and that's the only language involved in the current request. So, the only case where an additional name would override an existing one is when the po file of that language X has the same msgstr for two or more msgids, and that's a translation problem whose solution is to fix the po file, not check key collision in the source code.

   1 --- Moin/Moin19/MoinMoin/PageEditor.py	2009-12-04 21:01:10 +0000
   2 +++ PageEditor.py	2009-12-04 21:01:03 +0000
   3 @@ -765,16 +765,19 @@
   4          u = request.user
   5          obfuscated_email_address = encodeSpamSafeEmail(u.email)
   6          signature = u.signature()
   7 +        _ = self._
   8 +        N_ = lambda x:x
   9          variables = {
  10 -            'PAGE': self.page_name,
  11 -            'TIME': "<<DateTime(%s)>>" % now,
  12 -            'DATE': "<<Date(%s)>>" % now,
  13 -            'ME': u.name,
  14 -            'USERNAME': signature,
  15 -            'USER': "-- %s" % signature,
  16 -            'SIG': "-- %s <<DateTime(%s)>>" % (signature, now),
  17 -            'EMAIL': "<<MailTo(%s)>>" % (obfuscated_email_address)
  18 +            N_('PAGE'): self.page_name,
  19 +            N_('TIME'): "<<DateTime(%s)>>" % now,
  20 +            N_('DATE'): "<<Date(%s)>>" % now,
  21 +            N_('ME'): u.name,
  22 +            N_('USERNAME'): signature,
  23 +            N_('USER'): "-- %s" % signature,
  24 +            N_('SIG'): "-- %s <<DateTime(%s)>>" % (signature, now),
  25 +            N_('EMAIL'): "<<MailTo(%s)>>" % (obfuscated_email_address)
  26          }
  27 +        variables.update(dict(zip([_(name) for name in variables], variables.values())))
  28  
  29          if u.valid and u.name:
  30              if u.email:

MoinMoin.PageEditor.patch


CategoryFeatureRejected

MoinMoin: FeatureRequests/TranslationForVariableNames (last edited 2010-01-21 23:54:28 by RenatoSilva)