Package babel :: Module support :: Class Translations

# Class Translations

    gettext.NullTranslations --+
                               |
         gettext.GNUTranslations --+
                                   |
                          object --+
                                   |
                                  Translations

An extended translation catalog class.

Instance Methods

__init__(self, fileobj=None, domain=`'``messages``'`) Initialize the translations catalog. |

__repr__(self) repr(x) |

Translations

add(self, translations, merge=True) Add the given translations to the catalog. |

Translations

merge(self, translations) Merge the given translations into the catalog. |

dgettext(self, domain, message) Like `gettext()`, but look the message up in the specified domain. |

ldgettext(self, domain, message) Like `lgettext()`, but look the message up in the specified domain. |

dugettext(self, domain, message) Like `ugettext()`, but look the message up in the specified domain. |

dngettext(self, domain, singular, plural, num) Like `ngettext()`, but look the message up in the specified domain. |

ldngettext(self, domain, singular, plural, num) Like `lngettext()`, but look the message up in the specified domain. |

dungettext(self, domain, singular, plural, num) Like `ungettext()` but look the message up in the specified domain. |

Inherited from `gettext.GNUTranslations`: `gettext`, `lgettext`, `lngettext`, `ngettext`, `ugettext`, `ungettext`

Inherited from `gettext.NullTranslations`: `add_fallback`, `charset`, `info`, `install`, `output_charset`, `set_output_charset`

Inherited from `object`: `__delattr__`, `__format__`, `__getattribute__`, `__hash__`, `__new__`, `__reduce__`, `__reduce_ex__`, `__setattr__`, `__sizeof__`, `__str__`, `__subclasshook__`

Class Methods

Translations

load(cls, dirname=None, locales=None, domain=`'``messages``'`) Load translations from the given directory. |

Class Variables
| DEFAULT_DOMAIN = ``'``messages``'``
Inherited from `gettext.GNUTranslations`: `BE_MAGIC`, `LE_MAGIC`

Properties
Inherited from `object`: `__class__`

Method Details

### __init__(self, fileobj=None, domain=`'``messages``'`)
(Constructor)

Initialize the translations catalog.

Parameters:
  - `fileobj` - the file-like object the translation should be read from
Overrides: object.__init__

### load(cls, dirname=None, locales=None, domain=`'``messages``'`)
Class Method

Load translations from the given directory.

Parameters:
  - `dirname` - the directory containing the `MO` files
  - `locales` - the list of locales in order of preference (items in this list can be either Locale objects or locale strings)
  - `domain` - the message domain
Returns: Translations
  the loaded catalog, or a `NullTranslations` instance if no matching translations were found

### __repr__(self)
(Representation operator)

repr(x)

Overrides: object.__repr__
  (inherited documentation)

### add(self, translations, merge=True)

Add the given translations to the catalog.

If the domain of the translations is different than that of the current catalog, they are added as a catalog that is only accessible by the various `d*gettext` functions.

Parameters:
  - `translations` - the Translations instance with the messages to add
  - `merge` - whether translations for message domains that have already been added should be merged with the existing translations
Returns: Translations
  the Translations instance (`self`) so that merge calls can be easily chained

### merge(self, translations)

Merge the given translations into the catalog.

Message translations in the specified catalog override any messages with the same identifier in the existing catalog.

Parameters:
  - `translations` - the Translations instance with the messages to merge
Returns: Translations
  the Translations instance (`self`) so that merge calls can be easily chained