comparison babel/messages/catalog.py @ 82:f421e5576d26

Added support for translator comments at the API and frontends levels.(See #12, item 1). Updated docs and tests accordingly.
author palgarvio
date Sun, 10 Jun 2007 14:21:01 +0000
parents 8e2e9d549693
children 8a703ecdba91
comparison
equal deleted inserted replaced
81:51f73a110a84 82:f421e5576d26
33 33
34 34
35 class Message(object): 35 class Message(object):
36 """Representation of a single message in a catalog.""" 36 """Representation of a single message in a catalog."""
37 37
38 def __init__(self, id, string='', locations=(), flags=()): 38 def __init__(self, id, string='', locations=(), flags=(), comments=[]):
39 """Create the message object. 39 """Create the message object.
40 40
41 :param id: the message ID, or a ``(singular, plural)`` tuple for 41 :param id: the message ID, or a ``(singular, plural)`` tuple for
42 pluralizable messages 42 pluralizable messages
43 :param string: the translated message string, or a 43 :param string: the translated message string, or a
44 ``(singular, plural)`` tuple for pluralizable messages 44 ``(singular, plural)`` tuple for pluralizable messages
45 :param locations: a sequence of ``(filenname, lineno)`` tuples 45 :param locations: a sequence of ``(filenname, lineno)`` tuples
46 :param flags: a set or sequence of flags 46 :param flags: a set or sequence of flags
47 :param comments: a list of comments for the msgid
47 """ 48 """
48 self.id = id 49 self.id = id
49 if not string and self.pluralizable: 50 if not string and self.pluralizable:
50 string = (u'', u'') 51 string = (u'', u'')
51 self.string = string 52 self.string = string
53 self.flags = set(flags) 54 self.flags = set(flags)
54 if id and self.python_format: 55 if id and self.python_format:
55 self.flags.add('python-format') 56 self.flags.add('python-format')
56 else: 57 else:
57 self.flags.discard('python-format') 58 self.flags.discard('python-format')
59 self.comments = comments
58 60
59 def __repr__(self): 61 def __repr__(self):
60 return '<%s %r>' % (type(self).__name__, self.id) 62 return '<%s %r>' % (type(self).__name__, self.id)
61 63
62 def fuzzy(self): 64 def fuzzy(self):
326 else: 328 else:
327 if isinstance(id, (list, tuple)): 329 if isinstance(id, (list, tuple)):
328 assert isinstance(message.string, (list, tuple)) 330 assert isinstance(message.string, (list, tuple))
329 self._messages[key] = message 331 self._messages[key] = message
330 332
331 def add(self, id, string=None, locations=(), flags=()): 333 def add(self, id, string=None, locations=(), flags=(), comments=[]):
332 """Add or update the message with the specified ID. 334 """Add or update the message with the specified ID.
333 335
334 >>> catalog = Catalog() 336 >>> catalog = Catalog()
335 >>> catalog.add(u'foo') 337 >>> catalog.add(u'foo')
336 >>> catalog[u'foo'] 338 >>> catalog[u'foo']
343 pluralizable messages 345 pluralizable messages
344 :param string: the translated message string, or a 346 :param string: the translated message string, or a
345 ``(singular, plural)`` tuple for pluralizable messages 347 ``(singular, plural)`` tuple for pluralizable messages
346 :param locations: a sequence of ``(filenname, lineno)`` tuples 348 :param locations: a sequence of ``(filenname, lineno)`` tuples
347 :param flags: a set or sequence of flags 349 :param flags: a set or sequence of flags
348 """ 350 :param comments: a list of comments for the msgid
349 self[id] = Message(id, string, list(locations), flags) 351 """
352 self[id] = Message(id, string, list(locations), flags, comments)
350 353
351 def _key_for(self, id): 354 def _key_for(self, id):
352 """The key for a message is just the singular ID even for pluralizable 355 """The key for a message is just the singular ID even for pluralizable
353 messages. 356 messages.
354 """ 357 """
Copyright (C) 2012-2017 Edgewall Software