Changeset 3734
- Timestamp:
- 11/19/07 18:25:24 (1 year ago)
- Files:
-
- branches/1.1/turbogears/command/i18n.py (modified) (11 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
branches/1.1/turbogears/command/i18n.py
r3700 r3734 36 36 data = open(src, 'rb').read() 37 37 open(dest, 'wb').write(data) 38 39 _str_literal = r"""(?:'((?:[^']|\\')*)'|"((?:[^"]|\\")*)")""" 40 _py_i18n_re = re.compile(r"\b_\s*\(\s*[uU]?[rR]?%s\s*\)" % _str_literal) 41 _js_i18n_re = re.compile(r"\b_\s*\(\s*%s\s*\)" % _str_literal) 38 42 39 43 class InternationalizationTool: … … 212 216 mf.close() 213 217 214 215 218 def clean_generated_files(self): 216 219 potfile = self.get_potfile_path() … … 239 242 print "File %s exists, use --force to override" % targetfile 240 243 241 242 244 def _copy_moduletranslation(self, sourcefile, targetdir, language): 243 245 modulefilename = os.path.basename(sourcefile) … … 247 249 else: 248 250 print "%s translation for language '%s' does not exist (file searched '%s').\nPlease consider to contribute a translation." % (modulefilename, language, sourcefile) 249 250 251 251 252 def add_languages(self, codes): … … 270 271 271 272 self._copy_file_withcheck(potfile, catalog_file) 272 273 274 275 273 276 274 def scan_source_files(self): … … 290 288 elif ext == '.kid': 291 289 kid_files.append(srcfile) 292 # DBR start293 290 elif ext == '.js': 294 291 js_files.append(srcfile) 295 # DBR end296 292 else: 297 293 pass # do nothing … … 326 322 tags_to_ignore = ['script', 'style'] 327 323 keys = [] 328 kid_expr_re = re.compile(r"_\(('(?P<texta>[^']*)'|\"(?P<textb>[^\"]*)\")\)")329 324 330 325 def process_text(is_attribute, k, tag): 331 key = None 332 s = kid_expr_re.search(k) 333 if s: 334 key = s.groupdict()['texta'] or s.groupdict()['textb'] 335 # DBR start 336 # we don't have a kid expression in there 337 # so it is "just" a text entry - which we want to 338 # be translated!! 339 elif not is_attribute: 340 import kid.codewriter as cw 341 parts = cw.interpolate(k) 342 if isinstance(parts, list) and len(parts) > 1: 343 print "Warning: Mixed content in tag <%s>: %s" % (tag, k) 344 elif isinstance(parts, basestring): 345 key = k 346 # DBR end 347 if key and (key not in keys) and (tag not in tags_to_ignore): 348 messages.append((tag, fname, key)) 349 keys.append(key) 326 key = None 327 s = _py_i18n_re.search(k) 328 if s: 329 key = s.group(1) or s.group(2) 330 elif not is_attribute: 331 # we don't have a kid expression in there, so it is 332 # "just" a text entry - which we want to be translated! 333 import kid.codewriter as cw 334 parts = cw.interpolate(k) 335 if isinstance(parts, list) and len(parts) > 1: 336 print "Warning: Mixed content in tag <%s>: %s" % (tag, k) 337 elif isinstance(parts, basestring): 338 key = k 339 if key and (key not in keys) and (tag not in tags_to_ignore): 340 messages.append((tag, fname, key)) 341 keys.append(key) 350 342 351 343 for fname in files: … … 397 389 398 390 def get_strings_in_js(self, fname): 399 gettext_expr_re = re.compile(r"_\(('(?P<texta>[^']*)'|\"(?P<textb>[^\"]*)\")\)")400 391 messages = [] 401 392 keys = [] 402 393 for i, line in enumerate(open(fname)): 403 s = gettext_expr_re.search(line)394 s = _js_i18n_re.search(line) 404 395 while s: 405 key = s.group dict()['texta'] or s.groupdict()['textb']396 key = s.group(1) or s.group(2) 406 397 pos = s.end() 407 398 if key and (key not in keys): 408 399 messages.append((i + 1, fname, key)) 409 400 keys.append(key) 410 s = gettext_expr_re.search(line, pos)401 s = _js_i18n_re.search(line, pos) 411 402 return keys, messages 412 403 … … 414 405 messages = [] 415 406 keys = [] 416 gettext_expr_re = re.compile(r"_\(('(?P<texta>[^']*)'|\"(?P<textb>[^\"]*)\")\)")417 407 for fname in files: 418 408 print 'Working on', fname … … 429 419 fd.close() 430 420 431 432 433 434 421 def get_potfile_path(self): 435 422 return os.path.join(self.locale_dir, '%s.pot' % self.domain) 423 436 424 def get_locale_catalog(self, code): 437 425 return os.path.join(self.locale_dir, code, 'LC_MESSAGES', '%s.po' % self.domain) 426 438 427 def list_message_catalogs(self): 439 428 files = [] … … 444 433 files.append(fname) 445 434 return files 435 446 436 def fix_tzinfo(self, potfile): 447 437 """