babel.messages.mofile
Writing of files in the gettext MO (machine object) format.
since: version 0.9 see: The Format of MO Files read_mo(fileobj)Read a binary MO file from the given file-like object and return a corresponding Catalog object.
param fileobj: the file-like object to read the MO file from return: a catalog object representing the parsed MO file rtype: Catalog note: The implementation of this function is heavily based on the GNUTranslations._parse method of the gettext module in the standard library. write_mo(fileobj, catalog, use_fuzzy=False)Write a catalog to the specified file-like object using the GNU MO file format.
>>> from babel.messages import Catalog >>> from gettext import GNUTranslations >>> from StringIO import StringIO
>>> catalog = Catalog(locale='en_US') >>> catalog.add('foo', 'Voh') >>> catalog.add((u'bar', u'baz'), (u'Bahr', u'Batz')) >>> catalog.add('fuz', 'Futz', flags=['fuzzy']) >>> catalog.add('Fizz', '') >>> catalog.add(('Fuzz', 'Fuzzes'), ('', '')) >>> buf = StringIO()>>> write_mo(buf, catalog) >>> buf.seek(0) >>> translations = GNUTranslations(fp=buf) >>> translations.ugettext('foo') u'Voh' >>> translations.ungettext('bar', 'baz', 1) u'Bahr' >>> translations.ungettext('bar', 'baz', 2) u'Batz' >>> translations.ugettext('fuz') u'fuz' >>> translations.ugettext('Fizz') u'Fizz' >>> translations.ugettext('Fuzz') u'Fuzz' >>> translations.ugettext('Fuzzes') u'Fuzzes'param fileobj: the file-like object to write to param catalog: the Catalog instance param use_fuzzy: whether translations marked as "fuzzy" should be included in the output
See ApiDocs, Documentation
