| | 325 | def __repr__(self): |
| | 326 | return '<%s: "%s">' % (type(self).__name__, |
| | 327 | self._info.get('project-id-version')) |
| | 328 | |
| | 329 | def add(self, translations, merge=True): |
| | 330 | """Add the given translations to the catalog. |
| | 331 | |
| | 332 | If the domain of the translations is different than that of the |
| | 333 | current catalog, they are added as a catalog that is only accessible |
| | 334 | by the various ``d*gettext`` functions. |
| | 335 | |
| | 336 | :param translations: the `Translations` instance with the messages to |
| | 337 | add |
| | 338 | :param merge: whether translations for message domains that have |
| | 339 | already been added should be merged with the existing |
| | 340 | translations |
| | 341 | :return: the `Translations` instance (``self``) so that `merge` calls |
| | 342 | can be easily chained |
| | 343 | :rtype: `Translations` |
| | 344 | """ |
| | 345 | if merge and translations.domain == self.domain: |
| | 346 | return self.merge(translations) |
| | 347 | |
| | 348 | existing = self._domains.get(translations.domain) |
| | 349 | if merge and existing is not None: |
| | 350 | existing.merge(translations) |
| | 351 | else: |
| | 352 | translations.set_fallback(self) |
| | 353 | self._domains[translations.domain] = translations |
| | 354 | |
| | 355 | return self |
| | 356 | |
| 338 | | def __repr__(self): |
| 339 | | return '<%s: "%s">' % (type(self).__name__, |
| 340 | | self._info.get('project-id-version')) |
| | 374 | def dgettext(self, domain, message): |
| | 375 | """Like ``gettext()``, but look the message up in the specified |
| | 376 | domain. |
| | 377 | """ |
| | 378 | return self._domains.get(domain, self).gettext(message) |
| | 379 | |
| | 380 | def ldgettext(self, domain, message): |
| | 381 | """Like ``lgettext()``, but look the message up in the specified |
| | 382 | domain. |
| | 383 | """ |
| | 384 | return self._domains.get(domain, self).lgettext(message) |
| | 385 | |
| | 386 | def dugettext(self, domain, message): |
| | 387 | """Like ``ugettext()``, but look the message up in the specified |
| | 388 | domain. |
| | 389 | """ |
| | 390 | return self._domains.get(domain, self).ugettext(message) |
| | 391 | |
| | 392 | def dngettext(self, domain, singular, plural, num): |
| | 393 | """Like ``ngettext()``, but look the message up in the specified |
| | 394 | domain. |
| | 395 | """ |
| | 396 | return self._domains.get(domain, self).ngettext(singular, plural, num) |
| | 397 | |
| | 398 | def ldngettext(self, domain, singular, plural, num): |
| | 399 | """Like ``lngettext()``, but look the message up in the specified |
| | 400 | domain. |
| | 401 | """ |
| | 402 | return self._domains.get(domain, self).lngettext(singular, plural, num) |
| | 403 | |
| | 404 | def dungettext(self, domain, singular, plural, num): |
| | 405 | """Like ``ungettext()`` but look the message up in the specified |
| | 406 | domain. |
| | 407 | """ |
| | 408 | return self._domains.get(domain, self).ungettext(singular, plural, num) |