comparison MoinMoin/i18n/__init__.py @ 3075:8f7097ad7755

i18n: improved debug logging
author Thomas Waldmann <tw AT waldmann-edv DOT de>
date Sun, 21 Oct 2007 22:22:04 +0200
parents 18cba7defa5a
children 3fec4c9c0bf8
comparison
equal deleted inserted replaced
3074:18cba7defa5a 3075:8f7097ad7755
21 21
22 @copyright: 2001-2004 Juergen Hermann <jh@web.de>, 22 @copyright: 2001-2004 Juergen Hermann <jh@web.de>,
23 2005-2006 MoinMoin:ThomasWaldmann 23 2005-2006 MoinMoin:ThomasWaldmann
24 @license: GNU GPL, see COPYING for details. 24 @license: GNU GPL, see COPYING for details.
25 """ 25 """
26 debug = 0
27 26
28 import os, gettext, glob 27 import os, gettext, glob
29 import logging 28 import logging
30 29
31 from MoinMoin import caching 30 from MoinMoin import caching
65 language, domain, ext = os.path.basename(lang_file).split('.') 64 language, domain, ext = os.path.basename(lang_file).split('.')
66 t = Translation(language, domain) 65 t = Translation(language, domain)
67 f = file(lang_file) 66 f = file(lang_file)
68 t.load_po(f) 67 t.load_po(f)
69 f.close() 68 f.close()
70 #request.log("load translation %r" % language) 69 logging.debug("i18n_init: loading translation %r" % language)
71 encoding = 'utf-8' 70 encoding = 'utf-8'
72 _languages[language] = {} 71 _languages[language] = {}
73 for key, value in t.info.items(): 72 for key, value in t.info.items():
74 #request.log("meta key %s value %r" % (key, value)) 73 #logging.debug("i18n_init: meta key %s value %r" % (key, value))
75 _languages[language][key] = value.decode(encoding) 74 _languages[language][key] = value.decode(encoding)
76 try: 75 try:
77 meta_cache.update(_languages) 76 meta_cache.update(_languages)
78 except caching.CacheError: 77 except caching.CacheError:
79 pass 78 pass
194 def loadLanguage(self, request, trans_dir="i18n"): 193 def loadLanguage(self, request, trans_dir="i18n"):
195 request.clock.start('loadLanguage') 194 request.clock.start('loadLanguage')
196 cache = caching.CacheEntry(request, arena='i18n', key=self.language, scope='farm', use_pickle=True) 195 cache = caching.CacheEntry(request, arena='i18n', key=self.language, scope='farm', use_pickle=True)
197 langfilename = po_filename(request, self.language, self.domain, i18n_dir=trans_dir) 196 langfilename = po_filename(request, self.language, self.domain, i18n_dir=trans_dir)
198 needsupdate = cache.needsUpdate(langfilename) 197 needsupdate = cache.needsUpdate(langfilename)
199 if debug: 198 logging.debug("loadLanguage: langfilename %s needsupdate %d" % (langfilename, needsupdate))
200 request.log("i18n: langfilename %s needsupdate %d" % (langfilename, needsupdate))
201 if not needsupdate: 199 if not needsupdate:
202 try: 200 try:
203 uc_texts, uc_unformatted = cache.content() 201 uc_texts, uc_unformatted = cache.content()
202 logging.debug("loadLanguage: pickle %s load success" % self.language)
204 except caching.CacheError: 203 except caching.CacheError:
205 if debug: 204 logging.debug("loadLanguage: pickle %s load failed" % self.language)
206 request.log("i18n: pickle %s load failed" % self.language)
207 needsupdate = 1 205 needsupdate = 1
208 206
209 if needsupdate: 207 if needsupdate:
210 f = file(langfilename) 208 f = file(langfilename)
211 self.load_po(f) 209 self.load_po(f)
212 f.close() 210 f.close()
213 trans = self.translation 211 trans = self.translation
214 texts = trans._catalog 212 texts = trans._catalog
215 has_wikimarkup = self.info.get('x-haswikimarkup', 'False') == 'True' 213 has_wikimarkup = self.info.get('x-haswikimarkup', 'False') == 'True'
216 # convert to unicode 214 # convert to unicode
217 if debug: 215 logging.debug("loadLanguage: processing unformatted texts of lang %s" % self.language)
218 request.log("i18n: processing unformatted texts of lang %s" % self.language)
219 uc_unformatted = {} 216 uc_unformatted = {}
220 uc_texts = {} 217 uc_texts = {}
218 counter = 0
221 for ukey, utext in texts.items(): 219 for ukey, utext in texts.items():
220 if counter % 25 == 0:
221 logging.debug("Processed %d messages for %s..." % (counter, self.language))
222 uc_unformatted[ukey] = utext 222 uc_unformatted[ukey] = utext
223 if has_wikimarkup: 223 if has_wikimarkup:
224 # use the wiki parser now to replace some wiki markup with html 224 # use the wiki parser now to replace some wiki markup with html
225 try: 225 try:
226 uc_texts[ukey] = self.formatMarkup(request, utext) # XXX RECURSION!!! Calls gettext via markup 226 uc_texts[ukey] = self.formatMarkup(request, utext) # XXX RECURSION!!! Calls gettext via markup
227 except: # infinite recursion or crash 227 except Exception, err: # infinite recursion or crash
228 if debug: 228 logging.debug("loadLanguage: crashes in language %s on string: %s [%s]" % (self.language, utext, str(err)))
229 request.log("i18n: crashes in language %s on string: %s" % (self.language, utext))
230 uc_texts[ukey] = u"%s*" % utext 229 uc_texts[ukey] = u"%s*" % utext
231 if debug: 230 counter += 1
232 request.log("i18n: dumping lang %s" % self.language) 231 logging.debug("loadLanguage: dumping lang %s" % self.language)
233 try: 232 try:
234 cache.update((uc_texts, uc_unformatted)) 233 cache.update((uc_texts, uc_unformatted))
235 except caching.CacheError: 234 except caching.CacheError:
236 pass 235 pass
237 236