changeset 688:15c55ecd7ccb

fix some i18n bugs
author Thomas Waldmann <tw AT waldmann-edv DOT de>
date Tue, 23 May 2006 09:57:24 +0200
parents 80683dac4937
children ff56d9861a71 e61665a6a46f
files MoinMoin/i18n/__init__.py MoinMoin/macro/__init__.py MoinMoin/request/__init__.py MoinMoin/user.py MoinMoin/userform.py
diffstat 5 files changed, 22 insertions(+), 14 deletions(-) [+]
line wrap: on
line diff
--- a/MoinMoin/i18n/__init__.py	Mon May 22 00:55:40 2006 +0200
+++ b/MoinMoin/i18n/__init__.py	Tue May 23 09:57:24 2006 +0200
@@ -36,7 +36,6 @@
 PICKLE_PROTOCOL = pickle.HIGHEST_PROTOCOL
 
 from MoinMoin import caching
-from MoinMoin.Page import Page
 
 # This is a global for a reason: in persistent environments all languages in
 # use will be cached; Note: you have to restart if you update language data.
@@ -73,7 +72,12 @@
                 language, domain, ext = os.path.basename(mo_file).split('.')
                 t = Translation(language, domain)
                 t.load_mo(mo_file)
-                _languages[language] = t.info
+                request.log("load translation %r" % language)
+                encoding = 'utf-8'
+                _languages[language] = {}
+                for key, value in t.info.items():
+                    request.log("meta key %s value %r" % (key, value))
+                    _languages[language][key] = value.decode(encoding)
             meta_cache.update(pickle.dumps(_languages))
 
     if languages is None: # another tread maybe has done it before us
@@ -117,6 +121,7 @@
             pass
         currentStack.append(text)
 
+        from MoinMoin.Page import Page
         from MoinMoin.parser.text_moin_wiki import Parser as WikiParser
         from MoinMoin.formatter.text_html import Formatter
         import StringIO
@@ -191,6 +196,9 @@
 
 def getText(original, request, lang, formatted=True):
     """ Return a translation of text in the user's language. """
+    if original == u"":
+        return u"" # we don't want to get *.po files metadata!
+
     global translations
     if not lang in translations: # load translation if needed
         t = Translation(lang)
@@ -207,6 +215,7 @@
         translated = trans_table[original]
     except KeyError:
         try:
+            from MoinMoin.Page import Page
             language = languages[lang]['x-language-in-english']
             dictpagename = "%sDict" % language
             if Page(request, dictpagename).exists():
--- a/MoinMoin/macro/__init__.py	Mon May 22 00:55:40 2006 +0200
+++ b/MoinMoin/macro/__init__.py	Tue May 23 09:57:24 2006 +0200
@@ -43,7 +43,7 @@
         return cfg.macro_names
     else:
         lnames = names[:]
-        lnames.extend(i18n.languages.keys())
+        lnames.extend(i18n.wikiLanguages().keys())
         lnames.extend(wikiutil.getPlugins('macro', cfg))
         cfg.macro_names = lnames # remember it
         return lnames
@@ -93,7 +93,7 @@
 
     # we need the lang macros to execute when html is generated,
     # to have correct dir and lang html attributes
-    for lang in i18n.languages.keys():
+    for lang in i18n.wikiLanguages().keys():
         Dependencies[lang] = []
     
 
@@ -122,7 +122,7 @@
                 builtins = self.__class__
                 execute = getattr(builtins, '_macro_' + macro_name)
             except AttributeError:
-                if macro_name in i18n.languages:
+                if macro_name in i18n.wikiLanguages():
                     execute = builtins._m_lang
                 else:
                     raise ImportError("Cannot load macro %s" % macro_name)
--- a/MoinMoin/request/__init__.py	Mon May 22 00:55:40 2006 +0200
+++ b/MoinMoin/request/__init__.py	Tue May 23 09:57:24 2006 +0200
@@ -150,6 +150,10 @@
             rootname = u''
             self.rootpage = Page(self, rootname, is_rootpage=1)
 
+            from MoinMoin import i18n
+            self.i18n = i18n
+            i18n.i18n_init(self)
+
             self.user = self.get_user_from_form()
             
             if not self.query_string.startswith('action=xmlrpc'):
@@ -163,9 +167,6 @@
             self.mode_getpagelinks = 0
             self.no_closing_html_code = 0
 
-            from MoinMoin import i18n
-            self.i18n = i18n
-            i18n.i18n_init(self)
             self.lang = i18n.requestLanguage(self) 
             # Language for content. Page content should use the wiki default lang,
             # but generated content like search results should use the user language.
--- a/MoinMoin/user.py	Mon May 22 00:55:40 2006 +0200
+++ b/MoinMoin/user.py	Tue May 23 09:57:24 2006 +0200
@@ -16,7 +16,7 @@
 # Set pickle protocol, see http://docs.python.org/lib/node64.html
 PICKLE_PROTOCOL = pickle.HIGHEST_PROTOCOL
 
-from MoinMoin import config, caching, wikiutil
+from MoinMoin import config, caching, wikiutil, i18n
 from MoinMoin.util import filesys, timefuncs
 
 
@@ -282,8 +282,7 @@
             from security import Default
             self.may = Default(self)
         
-        from MoinMoin.i18n import languages
-        if self.language and not languages.has_key(self.language):
+        if self.language and not i18n.language_supported(self.language):
             self.language = 'en'
 
     def __repr__(self):
--- a/MoinMoin/userform.py	Mon May 22 00:55:40 2006 +0200
+++ b/MoinMoin/userform.py	Tue May 23 09:57:24 2006 +0200
@@ -395,14 +395,13 @@
     def _lang_select(self):
         """ Create language selection. """
         from MoinMoin import i18n
-        from MoinMoin.i18n import NAME
         _ = self._
         cur_lang = self.request.user.valid and self.request.user.language or ''
         langs = i18n.wikiLanguages().items()
-        langs.sort(lambda x,y,NAME=NAME: cmp(x[1][NAME], y[1][NAME]))
+        langs.sort(lambda x, y: cmp(x[1]['x-language'], y[1]['x-language']))
         options = [('', _('<Browser setting>', formatted=False))]
         for lang in langs:
-            name = lang[1][NAME]
+            name = lang[1]['x-language']
             options.append((lang[0], name))
                 
         return util.web.makeSelection('language', options, cur_lang)