Exemplo n.º 1
0
    def test_busted_plural_forms(self):
        # https://bugzilla.redhat.com/show_bug.cgi?id=1283599
        moobj = polib.MOFile()
        moobj.metadata[
            "Plural-Forms"] = "nplurals=3; plural=(n%10==1 && n%100!=11 ? 0 : n%10>=2 && (n%100<10 or n%100>=20) ? 1 : 2)\n"

        with mofile(moobj) as m:
            self.assertRaises(Exception, test_usability, m.name)
Exemplo n.º 2
0
    def test_ok(self):
        # what lt's Plural-Forms is supposed to look like
        moobj = polib.MOFile()
        moobj.metadata[
            "Plural-Forms"] = "nplurals=3; plural=(n%10==1 && n%100!=11 ? 0 : n%10>=2 && (n%100<10 || n%100>=20) ? 1 : 2)\n"

        with mofile(moobj) as m:
            test_usability(m.name)
Exemplo n.º 3
0
def save_catalog(catalog: dict, zf: zipfile.ZipFile, name: str):
    mofile = polib.MOFile()
    for msgid, msgstr in catalog.items():
        entry = polib.POEntry(msgid=msgid, msgstr=msgstr)
        mofile.append(entry)

    # zf.writestr(name, mofile.to_binary())
    with tempfile.NamedTemporaryFile() as f:
        mofile.save(f.name)
        zf.write(f.name, name)
Exemplo n.º 4
0
 def test_dummy_methods(self):
     """
     This is stupid and just here for code coverage.
     """
     mo = polib.MOFile()
     self.assertEqual(mo.percent_translated(), 100)
     self.assertEqual(mo.translated_entries(), mo)
     self.assertEqual(mo.untranslated_entries(), [])
     self.assertEqual(mo.fuzzy_entries(), [])
     self.assertEqual(mo.obsolete_entries(), [])
Exemplo n.º 5
0
def mofile_from_entry(*args, **kwargs):
    moobj = polib.MOFile()
    moobj.append(polib.MOEntry(*args, **kwargs))
    return mofile(moobj)
Exemplo n.º 6
0
 def __getattr__(self, item):
     return self.cache.get(item, polib.MOFile())