Mercurial > babel > old > mirror
comparison babel/messages/catalog.py @ 183:e927dffc9ab4
The frontends now provide ways to update existing translations catalogs from a template. Closes #22.
author | cmlenz |
---|---|
date | Thu, 28 Jun 2007 10:28:25 +0000 |
parents | 47f6c31e9a24 |
children | f5780e72eefc |
comparison
equal
deleted
inserted
replaced
181:5c85c0ec4ef8 | 183:e927dffc9ab4 |
---|---|
174 if revision_date is None: | 174 if revision_date is None: |
175 revision_date = datetime.now(LOCALTZ) | 175 revision_date = datetime.now(LOCALTZ) |
176 elif isinstance(revision_date, datetime) and not revision_date.tzinfo: | 176 elif isinstance(revision_date, datetime) and not revision_date.tzinfo: |
177 revision_date = revision_date.replace(tzinfo=LOCALTZ) | 177 revision_date = revision_date.replace(tzinfo=LOCALTZ) |
178 self.revision_date = revision_date #: Last revision date of the catalog | 178 self.revision_date = revision_date #: Last revision date of the catalog |
179 self.fuzzy = fuzzy #: Catalog Header fuzzy bit(True or False) | 179 self.fuzzy = fuzzy #: Catalog header fuzzy bit (`True` or `False`) |
180 | |
181 self.obsolete = odict() #: Dictionary of obsolete messages | |
180 | 182 |
181 def _get_header_comment(self): | 183 def _get_header_comment(self): |
182 comment = self._header_comment | 184 comment = self._header_comment |
183 comment = comment.replace('PROJECT', self.project) \ | 185 comment = comment.replace('PROJECT', self.project) \ |
184 .replace('VERSION', self.version) \ | 186 .replace('VERSION', self.version) \ |
494 >>> catalog.add('blue', u'blau', locations=[('main.py', 98)]) | 496 >>> catalog.add('blue', u'blau', locations=[('main.py', 98)]) |
495 >>> catalog.add('head', u'Kopf', locations=[('util.py', 33)]) | 497 >>> catalog.add('head', u'Kopf', locations=[('util.py', 33)]) |
496 >>> catalog.add(('salad', 'salads'), (u'Salat', u'Salate'), | 498 >>> catalog.add(('salad', 'salads'), (u'Salat', u'Salate'), |
497 ... locations=[('util.py', 38)]) | 499 ... locations=[('util.py', 38)]) |
498 | 500 |
499 >>> rest = catalog.update(template) | 501 >>> catalog.update(template) |
500 >>> len(catalog) | 502 >>> len(catalog) |
501 2 | 503 2 |
502 | 504 |
503 >>> msg1 = catalog['blue'] | 505 >>> msg1 = catalog['blue'] |
504 >>> msg1.string | 506 >>> msg1.string |
510 >>> msg2.string | 512 >>> msg2.string |
511 (u'Salat', u'Salate') | 513 (u'Salat', u'Salate') |
512 >>> msg2.locations | 514 >>> msg2.locations |
513 [('util.py', 42)] | 515 [('util.py', 42)] |
514 | 516 |
517 Messages that are in the catalog but not in the template are removed | |
518 from the main collection, but can still be accessed via the `obsolete` | |
519 member: | |
520 | |
515 >>> 'head' in catalog | 521 >>> 'head' in catalog |
516 False | 522 False |
517 >>> rest | 523 >>> catalog.obsolete.values() |
518 [<Message 'head' (Flags: '')>] | 524 [<Message 'head' (Flags: '')>] |
519 | 525 |
520 :param template: the reference catalog, usually read from a POT file | 526 :param template: the reference catalog, usually read from a POT file |
521 :param fuzzy_matching: whether to use fuzzy matching of message IDs | 527 :param fuzzy_matching: whether to use fuzzy matching of message IDs |
522 :return: a list of `Message` objects that the catalog contained before | |
523 the updated, but couldn't be found in the template | |
524 """ | 528 """ |
525 messages = self._messages | 529 messages = self._messages |
526 self._messages = odict() | 530 self._messages = odict() |
527 | 531 |
528 for message in template: | 532 for message in template: |
546 self[message.id] = message | 550 self[message.id] = message |
547 continue | 551 continue |
548 | 552 |
549 self[message.id] = message | 553 self[message.id] = message |
550 | 554 |
551 return messages.values() | 555 self.obsolete = messages |
552 | 556 |
553 def _key_for(self, id): | 557 def _key_for(self, id): |
554 """The key for a message is just the singular ID even for pluralizable | 558 """The key for a message is just the singular ID even for pluralizable |
555 messages. | 559 messages. |
556 """ | 560 """ |