27 |
from Persistence import Persistent |
from Persistence import Persistent |
28 |
from Acquisition import Implicit |
from Acquisition import Implicit |
29 |
from App.Management import Tabs |
from App.Management import Tabs |
30 |
|
import re |
31 |
from PlacelessTranslationService import log, Registry |
from PlacelessTranslationService import log, Registry |
32 |
|
|
33 |
try: |
try: |
34 |
True |
True |
35 |
except NameError: |
except NameError: |
112 |
self.name = unicode(tro._info.get('language-name', ''), tro._charset) |
self.name = unicode(tro._info.get('language-name', ''), tro._charset) |
113 |
self.default_zope_data_encoding = tro._charset |
self.default_zope_data_encoding = tro._charset |
114 |
translationRegistry[self.id] = self._v_tro = tro |
translationRegistry[self.id] = self._v_tro = tro |
115 |
self._missing = self._path_to_file[:-1] + 'issing' |
missingFileName = self._path_to_file[:-1] + 'issing' |
116 |
if not os.access(self._missing, os.W_OK): |
if os.access(missingFileName, os.W_OK): |
117 |
|
self._missing = MissingIds(missingFileName, self._v_tro._charset) |
118 |
|
else: |
119 |
self._missing = None |
self._missing = None |
120 |
if self.name: |
if self.name: |
121 |
self.title = '%s language (%s) for %s' % (self._language, self.name, self._domain) |
self.title = '%s language (%s) for %s' % (self._language, self.name, self._domain) |
134 |
self._prepareTranslations() |
self._prepareTranslations() |
135 |
log('reloading %s: %s' % (self.id, self.title)) |
log('reloading %s: %s' % (self.id, self.title)) |
136 |
if hasattr(REQUEST, 'RESPONSE'): |
if hasattr(REQUEST, 'RESPONSE'): |
137 |
REQUEST.RESPONSE.redirect(self.absolute_url()) |
if not REQUEST.form.has_key('noredir'): |
138 |
|
REQUEST.RESPONSE.redirect(self.absolute_url()) |
139 |
|
|
140 |
def _log_missing(self, id, orig_text): |
def _log_missing(self, id, orig_text): |
141 |
if self._missing is None: |
if self._missing is None: |
142 |
return |
return |
143 |
if getattr(self, '_v_missing', None) is None: |
self._missing.log(id, orig_text) |
|
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() |
|
144 |
|
|
145 |
def getMessage(self, id, orig_text=None, testing=False): |
def getMessage(self, id, orig_text=None, testing=False): |
146 |
""" |
""" |
241 |
# |
# |
242 |
############################################################ |
############################################################ |
243 |
|
|
244 |
|
class MissingIds(Persistent): |
245 |
|
def __init__(self, fileName, charset): |
246 |
|
self._fileName = fileName |
247 |
|
self._charset = charset |
248 |
|
self._ids = {} |
249 |
|
self._pattern = re.compile('msgid "(.*)"$') |
250 |
|
self.parseFile() |
251 |
|
self._v_file = None |
252 |
|
|
253 |
|
def parseFile(self): |
254 |
|
file = codecs.open(self._fileName, 'r', self._charset) |
255 |
|
for line in file.xreadlines(): |
256 |
|
match = self._pattern.search(line) |
257 |
|
if match: |
258 |
|
msgid = match.group(1) |
259 |
|
self._ids[msgid] = 1 |
260 |
|
file.close() |
261 |
|
|
262 |
|
def log(self, msgid, orig_text): |
263 |
|
if not self._ids.has_key(msgid): |
264 |
|
if getattr(self, '_v_file', None) is None: |
265 |
|
self._v_file = codecs.open(self._fileName, 'a', self._charset) |
266 |
|
if orig_text: |
267 |
|
orig_text = orig_text_line_joiner.join(orig_text.split('\n')) |
268 |
|
self._v_file.write(orig_text_template % {'text': orig_text}) |
269 |
|
self._v_file.write(missing_template % {'id':msgid.replace('"', r'\"')}) |
270 |
|
self._v_file.flush() |
271 |
|
self._ids[msgid]=1 |
272 |
|
|