def test_missing_in_dictionary(self): u = pounit() u.setsource("Absinthe") u.settarget("Absints") self.c.substitute(u) self.assertEqual(u.target, "Absints") self.assertEqual(u.isfuzzy(), True)
def test_exclude_variables(self): u = pounit() u.setsource("%s Windows") u.settarget("%s Logs") self.c.substitute(u) self.assertEqual(u.target, "%s Lūgs") self.assertEqual(u.isfuzzy(), False)
def test_one_found_in_dictionary(self): u = pounit() u.setsource("The window opens the file") u.settarget("Logs atver datni") self.c.substitute(u) self.assertEqual(u.target, "Lūgs atvar datni") self.assertEqual(u.isfuzzy(), True)
def test_abbreviation(self): u = pounit() u.setsource("VHS") u.settarget("VHS") self.c.substitute(u) self.assertEqual(u.target, "VHS") self.assertEqual(u.isfuzzy(), False)
def test_found_in_dictionary(self): u = pounit() u.setsource("open") u.settarget("atver") self.c.substitute(u) self.assertEqual(u.target, "atvar") self.assertEqual(u.isfuzzy(), False)
def test_unit_po_plurals(store_po): unit = Unit(store=store_po) unit_po = pounit('bar') unit_po.msgid_plural = ['bars'] unit.update(unit_po) assert unit.hasplural() unit.save() assert unit.hasplural()
def test_unit_po_plurals(store_po): unit = Unit(store=store_po, index=1) unit_po = pounit('bar') unit_po.msgid_plural = ['bars'] unit.update(unit_po) assert unit.hasplural() unit.save() assert unit.hasplural()
def to_pypo(unit): pounit = pypo.pounit( source=multistring(unit.msgid) if unit.hasplural() else (unit.msgid[0] if len(unit.msgid) else "") ) pounit.target = multistring(unit.msgstr) if unit.hasplural() else unit.msgstr[0] if unit.comments: ps = poparser.ParseState(cStringIO.StringIO(unit.comments.encode("utf8")), pypo.pounit, encoding="utf-8") poparser.parse_comments(ps, pounit) return pounit
def europarl_make_pofile(sourcefn, targetfn, limit=None): """ Make a pofile (pypo.pofile instance) out of two europarl text files """ from translate.storage import pypo source = open(sourcefn, 'r') target = open(targetfn, 'r') pofile = pypo.pofile() i = 0 while True: sline = source.readline() tline = target.readline() # EOF, break if sline == '': break sline = sline.strip() tline = tline.strip() # empty line, continue if not sline or not tline: continue pounit = pypo.pounit(source=sline) pounit.target = tline pofile.addunit(pounit) # limit reached, break i += 1 if limit and i >= limit: break source.close() target.close() return pofile
def test_accelerator_first_letter(self): u = pounit() u.setsource("%s Fil_e") u.settarget("%s Datn_e") self.c.substitute(u) self.assertEqual(u.target, "%s_ Fails")
def test_accelerator_source_letter(self): u = pounit() u.setsource("Fi_le") u.settarget("_Datne") self.c.substitute(u) self.assertEqual(u.target, "Fai_ls")
def test_accelerator_same_letter(self): u = pounit() u.setsource("Win_dow") u.settarget("Lo_gs") self.c.substitute(u) self.assertEqual(u.target, "Lū_gs")
def test_garbage(self): u = pounit() u.setsource("... ?") u.settarget("... ?") self.c.substitute(u) self.assertEqual(u.target, "... ?")
def test_untranslated(self): u = pounit() u.setsource("Some string") u.settarget("") # untranslated self.c.substitute(u) self.assertEqual(u.target, "")
def test_empty(self): u = pounit() self.c.substitute(u) self.assertEqual(u.target, "")
def test_exclude_named_variables(self): u = pounit() u.setsource("%(file)s file") u.settarget("%(file)s datne") self.c.substitute(u) self.assertEqual(u.target, "%(file)s fails")