Esempio n. 1
0
 def get_syntax_error(self, transfile):
     try:
         pouns = pypo.pofile(str(polib.pofile(transfile.filename)))
     except BaseException as e:
         yield ': (%s) %s' % (type(e).__name__, e.message)
     else:
         del pouns
Esempio n. 2
0
 def get_syntax_error(self, transfile):
     try:
         pouns = pypo.pofile(str(polib.pofile(transfile.filename)))
     except BaseException as e:
         yield ': (%s) %s' % (type(e).__name__, e.message)
     else:
         del pouns
Esempio n. 3
0
    def read(self, path=None):
        """
        Read pofile from the disk

        Returns translate.storage.pypo.pofile instance
        """
        assert self.type == "po"
        pofile = pypo.pofile()
        handle = open(path or self.getFilename("import.po"), "r")
        pofile.parse(handle)
        handle.close()
        return pofile
Esempio n. 4
0
 def to_pofile(self, pofile=None):
     """
     Export from database to (given or newly instantiated) pofile
     Headers are only set on pofile if no pofile was passed !!!
     """
     if not pofile:
         pofile = pypo.pofile()
         pofile.settargetlanguage(self.targetlanguage)
         if self.header:
             pofile.units = [self.header.to_pounit()]
     for unit in self.units.exclude_header().order_by("index"):
         pofile.addunit(unit.to_pounit())
     return pofile
Esempio n. 5
0
 def get_errors_wlno(self, transfile):
     try:
         polno = polib.pofile(transfile.filename)
         pouns = pypo.pofile(str(polno)).units[1:]
     except BaseException as e:
         pass
     else:
         for i in range(0, len(pouns)):
             unit = pouns[i]
             unit.linenum = polno[i].linenum
             if not unit.obsolete:
                 error = self.filterunit(unit)
                 if error:
                     for ename, e in error.items():
                         yield ':%s (%s) %s' % (unit.linenum, ename,
                                                e['message'].split('\n')[0])
Esempio n. 6
0
 def get_errors_wlno(self, transfile):
     try:
         polno = polib.pofile(transfile.filename)
         pouns = pypo.pofile(str(polno)).units[1:]
     except BaseException as e:
         pass
     else:
         for i in range(0, len(pouns)):
             unit = pouns[i]
             unit.linenum = polno[i].linenum
             if not unit.obsolete:
                 error = self.filterunit(unit)
                 if error:
                     for ename, e in error.items():
                         yield ':%s (%s) %s' % (unit.linenum, ename,
                                                e['message'].split('\n')[0])
Esempio n. 7
0
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 setup_method(self, method):
     self.term_po = pofile(BytesIO(self.TERMINOLOGY.encode("utf-8")))
     self.matcher = terminologymatcher(self.term_po)
     self.test_string = u"<b>Inpüt</b> file name thingy."
Esempio n. 9
0
 def setup_method(self, method):
     self.term_po = pofile(StringIO(self.TERMINOLOGY))
     self.matcher = terminologymatcher(self.term_po)
     self.test_string = u'<b>Inpüt</b> file name thingy.'
Esempio n. 10
0
 def setup_method(self, method):
     self.term_po = pofile(BytesIO(self.TERMINOLOGY.encode('utf-8')))
     self.matcher = terminologymatcher(self.term_po)
     self.test_string = u'<b>Inpüt</b> file name thingy.'
Esempio n. 11
0
 def headers(self):
     if self.header:
         pofile = pypo.pofile()
         pofile.units = [self.header.to_pounit()]
         return pofile.parseheader()
     return {}