Description

I'm writing a theme containing strings not provided by default translation system. Then I came up with the idea of creating a personal po file for the theme, as suggested by Thomas Waldmann. I looked into MoinMoin/i18n module to learn how to load a personal translation. However the only way I've found to make it work is creating a translation object for a dummy language. If I use the real language code, default translation for that language is overwritten. It seems that domain is ignored by translation system.

Steps to reproduce

  1. Try loading your personal po under your actual language:
       1  t = Translation(lang_code, your_domain)
       2  t.loadLanguage(request, trans_dir=your_po_dir)
    

Example

Component selection

Details

MoinMoin Version

1.8.3

OS and Version

Python Version

Server Setup

Server Details

Language you are using the wiki in (set in the browser/UserPreferences)

pt-br

Workaround

This is the code I'm currently using to load personal translations for my theme:

   1     from MoinMoin.i18n import Translation, translations, po_filename
   2     import MoinMoin.i18n, os, glob
   3 
   4     # [...]
   5 
   6     def _ (self, text):
   7         lang = self.request.lang
   8         _translations = self._translations
   9         if lang in _translations:
  10             if text in _translations[lang]:
  11                 return _translations[lang][text]
  12         return self.request.getText(text, formatted=False)
  13 
  14     def __init__(self, request):
  15         ThemeBase.__init__(self, request)
  16         self._translations = self.theme_translations(append=True)
  17 
  18     def theme_translations(self, append=False):
  19         """Load personal translations to be used by this theme.
  20         
  21         @param append:  if True makes theme translation global by appending it to the default Moin translation system.
  22         @return: a dict (indexed by language) of translation dicts, or an empty dict if append=True.
  23         """
  24         _translations = {}
  25         request = self.request
  26         po_dir = os.path.join('i18n', 'themes', self.name)
  27         encoding = 'utf-8'
  28 
  29         for lang_file in glob.glob(po_filename(request, i18n_dir=po_dir, language='*', domain='Theme')):
  30             dummy_language, domain, ext = os.path.basename(lang_file).split('.')
  31             language = dummy_language.split('_')[0]
  32             t = Translation(dummy_language, domain)
  33             t.loadLanguage(request, trans_dir=po_dir)
  34 
  35             if append:
  36                 if not language in translations:
  37                     translations[language] = Translation(language)
  38                     translations[language].loadLanguage(request)
  39                 translations[language].raw.update(t.raw)
  40             else:
  41                 _translations[language] = {}
  42                 for key, text in t.raw.items():
  43                     _translations[language][key] = text         
  44 
  45         return _translations

Discussion

As you removed the translations = {} line (see bot_translations), you are modifying the global translations attribute so the overwriting behaviour you experience is due to a bug in your code.

I suggest you maybe use some easier (and more finished) parts of moinmoin first to get some more python training. As I already told you, the translation domain support stuff is rather unfinished/untested/experimental and thus needs more work.


I only created this page because dreimark from IRC asked me for doing that. I think that this may be a Moin bug because it seems that any call to Translation.loadLanguage will overwrite prior settings for the same language (although I'm not sure whether this happens or not in bot_translations). That's why I still need a dummy language: http://www.pastie.org/487675.

Plan


CategoryMoinMoinNoBug

MoinMoin: MoinMoinBugs/PersonalPosDontWork (last edited 2009-05-24 20:09:42 by RenatoSilva)