Mercurial > babel > old > mirror
comparison babel/messages/catalog.py @ 122:03f106700f02
Added tests for `new_catalog` distutils command.
author | cmlenz |
---|---|
date | Fri, 15 Jun 2007 22:18:59 +0000 |
parents | 7a5a7bf39d3d |
children | 5b4f302abf53 |
comparison
equal
deleted
inserted
replaced
121:a5b4257812b9 | 122:03f106700f02 |
---|---|
108 """) | 108 """) |
109 | 109 |
110 | 110 |
111 DEFAULT_HEADER = u"""\ | 111 DEFAULT_HEADER = u"""\ |
112 # Translations template for PROJECT. | 112 # Translations template for PROJECT. |
113 # Copyright (C) YEAR COPYRIGHT HOLDER | 113 # Copyright (C) YEAR ORGANIZATION |
114 # This file is distributed under the same license as the PROJECT project. | 114 # This file is distributed under the same license as the PROJECT project. |
115 # FIRST AUTHOR <EMAIL@ADDRESS>, YEAR. | 115 # FIRST AUTHOR <EMAIL@ADDRESS>, YEAR. |
116 #""" | 116 #""" |
117 | 117 |
118 class Catalog(object): | 118 class Catalog(object): |
171 def _get_header_comment(self): | 171 def _get_header_comment(self): |
172 comment = self._header_comment | 172 comment = self._header_comment |
173 comment = comment.replace('PROJECT', self.project) \ | 173 comment = comment.replace('PROJECT', self.project) \ |
174 .replace('VERSION', self.version) \ | 174 .replace('VERSION', self.version) \ |
175 .replace('YEAR', self.revision_date.strftime('%Y')) \ | 175 .replace('YEAR', self.revision_date.strftime('%Y')) \ |
176 .replace('COPYRIGHT HOLDER', self.copyright_holder) | 176 .replace('ORGANIZATION', self.copyright_holder) |
177 if self.locale: | 177 if self.locale: |
178 comment = comment.replace('Translations template', '%s translations' | 178 comment = comment.replace('Translations template', '%s translations' |
179 % self.locale.english_name) | 179 % self.locale.english_name) |
180 return comment | 180 return comment |
181 | |
181 def _set_header_comment(self, string): | 182 def _set_header_comment(self, string): |
182 self._header_comment = string | 183 self._header_comment = string |
183 | 184 |
184 header_comment = property(_get_header_comment, _set_header_comment, doc="""\ | 185 header_comment = property(_get_header_comment, _set_header_comment, doc="""\ |
185 The header comment for the catalog. | 186 The header comment for the catalog. |
191 # Copyright (C) 2007 Foo Company | 192 # Copyright (C) 2007 Foo Company |
192 # This file is distributed under the same license as the Foobar project. | 193 # This file is distributed under the same license as the Foobar project. |
193 # FIRST AUTHOR <EMAIL@ADDRESS>, 2007. | 194 # FIRST AUTHOR <EMAIL@ADDRESS>, 2007. |
194 # | 195 # |
195 | 196 |
197 The header can also be set from a string. Any known upper-case variables | |
198 will be replaced when the header is retrieved again: | |
199 | |
200 >>> catalog = Catalog(project='Foobar', version='1.0', | |
201 ... copyright_holder='Foo Company') | |
202 >>> catalog.header_comment = '''\\ | |
203 ... # The POT for my really cool PROJECT project. | |
204 ... # Copyright (C) 1990-2003 ORGANIZATION | |
205 ... # This file is distributed under the same license as the PROJECT | |
206 ... # project. | |
207 ... #''' | |
208 >>> print catalog.header_comment | |
209 # The POT for my really cool Foobar project. | |
210 # Copyright (C) 1990-2003 Foo Company | |
211 # This file is distributed under the same license as the Foobar | |
212 # project. | |
213 # | |
214 | |
196 :type: `unicode` | 215 :type: `unicode` |
197 """) | 216 """) |
198 | 217 |
199 def _get_mime_headers(self): | 218 def _get_mime_headers(self): |
200 headers = [] | 219 headers = [] |
235 # FIXME: this should use dates.parse_datetime as soon as that | 254 # FIXME: this should use dates.parse_datetime as soon as that |
236 # is ready | 255 # is ready |
237 value, tzoffset, _ = re.split('[+-](\d{4})$', value, 1) | 256 value, tzoffset, _ = re.split('[+-](\d{4})$', value, 1) |
238 tt = time.strptime(value, '%Y-%m-%d %H:%M') | 257 tt = time.strptime(value, '%Y-%m-%d %H:%M') |
239 ts = time.mktime(tt) | 258 ts = time.mktime(tt) |
240 tzoffset = FixedOffsetTimezone(int(tzoffset)) | 259 tzoffset = FixedOffsetTimezone(int(tzoffset[:2]) * 60 + |
260 int(tzoffset[2:])) | |
241 self.creation_date = datetime.fromtimestamp(ts, tzoffset) | 261 self.creation_date = datetime.fromtimestamp(ts, tzoffset) |
242 | 262 |
243 mime_headers = property(_get_mime_headers, _set_mime_headers, doc="""\ | 263 mime_headers = property(_get_mime_headers, _set_mime_headers, doc="""\ |
244 The MIME headers of the catalog, used for the special ``msgid ""`` entry. | 264 The MIME headers of the catalog, used for the special ``msgid ""`` entry. |
245 | 265 |
409 message = current | 429 message = current |
410 elif id == '': | 430 elif id == '': |
411 # special treatment for the header message | 431 # special treatment for the header message |
412 headers = message_from_string(message.string.encode(self.charset)) | 432 headers = message_from_string(message.string.encode(self.charset)) |
413 self.mime_headers = headers.items() | 433 self.mime_headers = headers.items() |
434 self.header_comment = '\n'.join(['# %s' % comment for comment | |
435 in message.user_comments]) | |
414 else: | 436 else: |
415 if isinstance(id, (list, tuple)): | 437 if isinstance(id, (list, tuple)): |
416 assert isinstance(message.string, (list, tuple)) | 438 assert isinstance(message.string, (list, tuple)) |
417 self._messages[key] = message | 439 self._messages[key] = message |
418 | 440 |