[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[OpenTAL-checkins] CVSROOT: /cvsroot/opental
From: |
Godefroid Chapelle |
Subject: |
[OpenTAL-checkins] CVSROOT: /cvsroot/opental |
Date: |
Mon, 22 Sep 2003 15:23:53 -0400 |
Module name: opental
Branch: no_more_readconflict
Changes by: Godefroid Chapelle <address@hidden> 03/09/22 15:23:53
Reply-to: address@hidden
CVSROOT: /cvsroot/opental
Module name: opental
Branch: no_more_readconflict
Changes by: Godefroid Chapelle <address@hidden> 03/09/22 15:23:53
Modified files:
PlacelessTranslationService: GettextMessageCatalog.py
Log message:
improved logging of missing message ids/strings
CVSWeb URLs:
http://savannah.gnu.org/cgi-bin/viewcvs/opental/opental/PlacelessTranslationService/GettextMessageCatalog.py.diff?only_with_tag=no_more_readconflict&tr1=1.14.2.2&tr2=1.14.2.3&r1=text&r2=text
Patches:
Index: opental/PlacelessTranslationService/GettextMessageCatalog.py
diff -u opental/PlacelessTranslationService/GettextMessageCatalog.py:1.14.2.2
opental/PlacelessTranslationService/GettextMessageCatalog.py:1.14.2.3
--- opental/PlacelessTranslationService/GettextMessageCatalog.py:1.14.2.2
Sun Sep 14 21:05:34 2003
+++ opental/PlacelessTranslationService/GettextMessageCatalog.py Mon Sep
22 15:23:53 2003
@@ -17,7 +17,7 @@
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA
"""A simple implementation of a Message Catalog.
-$Id: GettextMessageCatalog.py,v 1.14.2.2 2003/09/15 01:05:34 dreamcatcher Exp $
+$Id: GettextMessageCatalog.py,v 1.14.2.3 2003/09/22 19:23:53 gotcha Exp $
"""
from gettext import GNUTranslations
@@ -27,7 +27,9 @@
from Persistence import Persistent
from Acquisition import Implicit
from App.Management import Tabs
+import re
from PlacelessTranslationService import log, Registry
+
try:
True
except NameError:
@@ -110,8 +112,10 @@
self.name = unicode(tro._info.get('language-name', ''),
tro._charset)
self.default_zope_data_encoding = tro._charset
translationRegistry[self.id] = self._v_tro = tro
- self._missing = self._path_to_file[:-1] + 'issing'
- if not os.access(self._missing, os.W_OK):
+ missingFileName = self._path_to_file[:-1] + 'issing'
+ if os.access(missingFileName, os.W_OK):
+ self._missing = MissingIds(missingFileName,
self._v_tro._charset)
+ else:
self._missing = None
if self.name:
self.title = '%s language (%s) for %s' % (self._language,
self.name, self._domain)
@@ -130,19 +134,13 @@
self._prepareTranslations()
log('reloading %s: %s' % (self.id, self.title))
if hasattr(REQUEST, 'RESPONSE'):
- REQUEST.RESPONSE.redirect(self.absolute_url())
+ if not REQUEST.form.has_key('noredir'):
+ REQUEST.RESPONSE.redirect(self.absolute_url())
def _log_missing(self, id, orig_text):
if self._missing is None:
return
- if getattr(self, '_v_missing', None) is None:
- self._v_missing = codecs.open(self._missing, 'a',
- self._v_tro._charset)
- if orig_text:
- orig_text = orig_text_line_joiner.join(orig_text.split('\n'))
- self._v_missing.write(orig_text_template % {'text': orig_text})
- self._v_missing.write(missing_template % {'id':id.replace('"', r'\"')})
- self._v_missing.flush()
+ self._missing.log(id, orig_text)
def getMessage(self, id, orig_text=None, testing=False):
"""
@@ -243,4 +241,32 @@
#
############################################################
+class MissingIds(Persistent):
+ def __init__(self, fileName, charset):
+ self._fileName = fileName
+ self._charset = charset
+ self._ids = {}
+ self._pattern = re.compile('msgid "(.*)"$')
+ self.parseFile()
+ self._v_file = None
+
+ def parseFile(self):
+ file = codecs.open(self._fileName, 'r', self._charset)
+ for line in file.xreadlines():
+ match = self._pattern.search(line)
+ if match:
+ msgid = match.group(1)
+ self._ids[msgid] = 1
+ file.close()
+
+ def log(self, msgid, orig_text):
+ if not self._ids.has_key(msgid):
+ if getattr(self, '_v_file', None) is None:
+ self._v_file = codecs.open(self._fileName, 'a', self._charset)
+ if orig_text:
+ orig_text = orig_text_line_joiner.join(orig_text.split('\n'))
+ self._v_file.write(orig_text_template % {'text': orig_text})
+ self._v_file.write(missing_template % {'id':msgid.replace('"',
r'\"')})
+ self._v_file.flush()
+ self._ids[msgid]=1