[Moin-user] Theme translations

Renato Silva br.renatosilva at gmail.com
Fri May 22 15:54:29 EDT 2009


Hi.

I'm writing a theme and I need to print a string which doesn't exist in
default po files.

Thomas Waldmann told me to look at MoinMoin/i18n/__init__.py to learn how to
add new translations. I didn't understand it very well, but I wrote the
following code, and it's not working. Instead of adding theme translations
to the translation system (*.MoinMoin.po + *.mytheme.po), it is replacing it
completely (only *.mytheme.po is being used). What's wrong with the
following code?

def __init__(self, request):
    ThemeBase.__init__(self, request)
    self.load_personal_translations()

def load_personal_translations(self):
    """Load personal translations to be used by this theme"""

    request = self.request
    po_dir = os.path.join('i18n', 'themes', self.name)
    encoding = 'utf-8'

    for lang_file in glob.glob(po_filename(request, i18n_dir=po_dir,
language='*', domain=self.name)):
        language, domain, ext = os.path.basename(lang_file).split('.')
        t = Translation(language, domain)
        f = file(lang_file)
        t.load_po(f)
        f.close()
        t.loadLanguage(request, trans_dir=po_dir)
        personal_translation = {}

        for key, text in t.raw.items():
            personal_translation[key] = text

        if not translations.has_key(language):
            translations[language] = t
        else:
            append = translations[language].raw.update
            append(t.raw)
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/moin-user/attachments/20090522/210ad809/attachment.html>


More information about the Moin-user mailing list