changeset 4707:6acb48a16e32

use i18n.strings for wikiutil.isSystemPage()
author Thomas Waldmann <tw AT waldmann-edv DOT de>
date Sat, 25 Apr 2009 00:29:46 +0200
parents 621c708ecddb
children 04c4fdfe48a9
files MoinMoin/i18n/__init__.py MoinMoin/wikiutil.py
diffstat 2 files changed, 25 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- a/MoinMoin/i18n/__init__.py	Mon Apr 20 20:32:49 2009 +0200
+++ b/MoinMoin/i18n/__init__.py	Sat Apr 25 00:29:46 2009 +0200
@@ -31,6 +31,7 @@
 logging = log.getLogger(__name__)
 
 from MoinMoin import caching
+from MoinMoin.i18n import strings
 
 # 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.
@@ -39,6 +40,11 @@
 # this gets loaded early and completely:
 languages = None
 
+# system_pages has a dictionary containing all english
+# system page names and also all translated system pages names as keys,
+# see also wikiutil.isSystemPage:
+system_pages = {}
+
 translations = {}
 
 def po_filename(request, language, domain, i18n_dir='i18n'):
@@ -68,6 +74,9 @@
         if meta_cache.needsUpdate(i18n_dir):
             logging.debug("cache needs update")
             _languages = {}
+            _system_pages = {}
+            for pagename in strings.all_pages:
+                _system_pages[pagename] = ('en', pagename)
             for lang_file in glob.glob(po_filename(request, language='*', domain='MoinMoin')): # XXX only MoinMoin domain for now
                 language, domain, ext = os.path.basename(lang_file).split('.')
                 t = Translation(language, domain)
@@ -80,18 +89,28 @@
                 for key, value in t.info.items():
                     #logging.debug("meta key %s value %r" % (key, value))
                     _languages[language][key] = value.decode(encoding)
+                for pagename in strings.all_pages:
+                    try:
+                        pagename_translated = t.translation._catalog[pagename]
+                    except KeyError:
+                        pass
+                    else:
+                        _system_pages[pagename_translated] = (language, pagename)
             logging.debug("dumping language metadata to disk cache")
             try:
-                meta_cache.update(_languages)
+                meta_cache.update({
+                    'languages': _languages,
+                    'system_pages': _system_pages,
+                })
             except caching.CacheError:
                 pass
 
         if languages is None: # another thread maybe has done it before us
             try:
                 logging.debug("loading language metadata from disk cache")
-                _languages = meta_cache.content()
+                d = meta_cache.content()
                 if languages is None:
-                    languages = _languages
+                    globals().update(d)
             except caching.CacheError:
                 pass
     request.clock.stop('i18n_init')
--- a/MoinMoin/wikiutil.py	Mon Apr 20 20:32:49 2009 +0200
+++ b/MoinMoin/wikiutil.py	Sat Apr 25 00:29:46 2009 +0200
@@ -611,15 +611,15 @@
 #############################################################################
 
 def isSystemPage(request, pagename):
-    """ Is this a system page? Uses AllSystemPagesGroup internally.
+    """ Is this a system page?
 
     @param request: the request object
     @param pagename: the page name
     @rtype: bool
     @return: true if page is a system page
     """
-    return (request.dicts.has_member('SystemPagesGroup', pagename) or
-        isTemplatePage(request, pagename))
+    from MoinMoin import i18n
+    return pagename in i18n.system_pages or isTemplatePage(request, pagename)
 
 
 def isTemplatePage(request, pagename):