コード例 #1
0
 def convertmessage(
     self,
     contextname,
     messagenum,
     source,
     target,
     disambiguation,
     msgcomments,
     transtype,
 ):
     """makes a pounit from the given message"""
     thepo = po.pounit(encoding="UTF-8")
     thepo.addlocation("%s#%d" % (contextname, messagenum))
     thepo.source = source
     if not self.pot:
         thepo.target = target
     if len(disambiguation) > 0:
         thepo.setcontext(disambiguation)
     if len(msgcomments) > 0:
         thepo.addnote(msgcomments)
     if transtype == "unfinished" and thepo.istranslated():
         thepo.markfuzzy()
     if transtype == "obsolete":
         # This should use the Gettext obsolete method but it would require quite a bit of work
         thepo.addnote("(obsolete)", origin="developer")
         # using the fact that -- quote -- "(this is nonsense)"
     return thepo
コード例 #2
0
 def convertmixedunit(self, labeldtd, accesskeydtd):
     labelpo = self.convertunit(labeldtd)
     accesskeypo = self.convertunit(accesskeydtd)
     if labelpo is None:
         return accesskeypo
     if accesskeypo is None:
         return labelpo
     thepo = po.pounit(encoding="UTF-8")
     thepo.addlocations(labelpo.getlocations())
     thepo.addlocations(accesskeypo.getlocations())
     thepo.msgidcomment = thepo._extract_msgidcomments() + labelpo._extract_msgidcomments()
     thepo.msgidcomment = thepo._extract_msgidcomments() + accesskeypo._extract_msgidcomments()
     thepo.addnote(labelpo.getnotes("developer"), "developer")
     thepo.addnote(accesskeypo.getnotes("developer"), "developer")
     thepo.addnote(labelpo.getnotes("translator"), "translator")
     thepo.addnote(accesskeypo.getnotes("translator"), "translator")
     # redo the strings from original dtd...
     label = dtd.unquotefromdtd(labeldtd.definition).decode('UTF-8')
     accesskey = dtd.unquotefromdtd(accesskeydtd.definition).decode('UTF-8')
     label = accesskeyfn.combine(label, accesskey)
     if label is None:
         return None
     thepo.source = label
     thepo.target = ""
     return thepo
コード例 #3
0
ファイル: xliff2po.py プロジェクト: Jobava/translate-toolkit
    def converttransunit(self, transunit):
        """makes a pounit from the given transunit"""
        thepo = po.pounit()

        # Header
        if transunit.getrestype() == "x-gettext-domain-header":
            thepo.source = ""
        else:
            thepo.source = transunit.source
        thepo.target = transunit.target

        # Location comments
        locations = transunit.getlocations()
        if locations:
            thepo.addlocations(locations)

        # NOTE: Supporting both <context> and <note> tags in xliff files
        # for comments
        # Translator comments
        trancomments = transunit.getnotes("translator")
        if trancomments:
            thepo.addnote(trancomments, origin="translator")

        # Automatic and Developer comments
        autocomments = transunit.getnotes("developer")
        if autocomments:
            thepo.addnote(autocomments, origin="developer")

        # See 5.6.1 of the spec. We should not check fuzzyness, but approved
        # attribute
        if transunit.isfuzzy():
            thepo.markfuzzy(True)

        return thepo
コード例 #4
0
ファイル: xliff2po.py プロジェクト: mozilla/markup-lib
    def converttransunit(self, transunit):
        """makes a pounit from the given transunit"""
        thepo = po.pounit()

        #Header
        if transunit.getrestype() == "x-gettext-domain-header":
            thepo.source = ""
        else:
            thepo.source = transunit.source
        thepo.target = transunit.target

        #Location comments
        locations = transunit.getlocations()
        if locations:
            thepo.addlocations(locations)

        #NOTE: Supporting both <context> and <note> tags in xliff files for comments
        #Translator comments
        trancomments = transunit.getnotes("translator")
        if trancomments:
            thepo.addnote(trancomments, origin="translator")

        #Automatic and Developer comments
        autocomments = transunit.getnotes("developer")
        if autocomments:
            thepo.addnote(autocomments, origin="developer")

        #See 5.6.1 of the spec. We should not check fuzzyness, but approved attribute
        if transunit.isfuzzy():
            thepo.markfuzzy(True)

        return thepo
コード例 #5
0
ファイル: dtd2po.py プロジェクト: AlexArgus/affiliates-lib
 def convertmixedunit(self, labeldtd, accesskeydtd):
     labelpo = self.convertunit(labeldtd)
     accesskeypo = self.convertunit(accesskeydtd)
     if labelpo is None:
         return accesskeypo
     if accesskeypo is None:
         return labelpo
     thepo = po.pounit(encoding="UTF-8")
     thepo.addlocations(labelpo.getlocations())
     thepo.addlocations(accesskeypo.getlocations())
     thepo.msgidcomment = thepo._extract_msgidcomments() + labelpo._extract_msgidcomments()
     thepo.msgidcomment = thepo._extract_msgidcomments() + accesskeypo._extract_msgidcomments()
     thepo.addnote(labelpo.getnotes("developer"), "developer")
     thepo.addnote(accesskeypo.getnotes("developer"), "developer")
     thepo.addnote(labelpo.getnotes("translator"), "translator")
     thepo.addnote(accesskeypo.getnotes("translator"), "translator")
     # redo the strings from original dtd...
     label = dtd.unquotefromdtd(labeldtd.definition).decode('UTF-8')
     accesskey = dtd.unquotefromdtd(accesskeydtd.definition).decode('UTF-8')
     label = accesskeyfn.combine(label, accesskey)
     if label is None:
         return None
     thepo.source = label
     thepo.target = ""
     return thepo
コード例 #6
0
ファイル: web2py2po.py プロジェクト: translate/translate
 def convertunit(self, source_str, target_str):
     pounit = po.pounit(encoding="UTF-8")
     pounit.settypecomment('python-format')
     pounit.source = source_str
     if target_str:
         pounit.target = target_str
     return pounit
コード例 #7
0
ファイル: poterminology.py プロジェクト: lambacck/translate
def create_termunit(term, unit, targets, locations, sourcenotes, transnotes,
                    filecounts):
    termunit = po.pounit(term)
    if unit is not None:
        termunit.merge(unit, overwrite=False, comments=False)
    if len(targets.keys()) > 1:
        txt = '; '.join([
            "%s {%s}" % (target, ', '.join(files))
            for target, files in six.iteritems(targets)
        ])
        if termunit.target.find('};') < 0:
            termunit.target = txt
            termunit.markfuzzy()
        else:
            # if annotated multiple terms already present, keep as-is
            termunit.addnote(txt, "translator")
    for location in locations:
        termunit.addlocation(location)
    for sourcenote in sourcenotes:
        termunit.addnote(sourcenote, "developer")
    for transnote in transnotes:
        termunit.addnote(transnote, "translator")
    for filename, count in six.iteritems(filecounts):
        termunit.addnote("(poterminology) %s (%d)\n" % (filename, count),
                         'translator')
    return termunit
コード例 #8
0
 def convertunit(self, source_str, target_str):
     pounit = po.pounit(encoding="UTF-8")
     pounit.settypecomment('python-format')
     pounit.source = source_str
     if target_str:
         pounit.target = target_str
     return pounit
コード例 #9
0
ファイル: csv2po.py プロジェクト: cc-archive/pootle
 def convertunit(self, csvunit):
     """converts csv unit to po unit"""
     pounit = po.pounit(encoding="UTF-8")
     if csvunit.location:
         pounit.addlocation(csvunit.location)
     pounit.source = csvunit.source
     pounit.target = csvunit.target
     return pounit
コード例 #10
0
ファイル: l20n2po.py プロジェクト: uniqx/translate
    def convert_l20nunit(self, unit):
        po_unit = po.pounit(encoding="UTF-8")
        po_unit.setid(unit.getid())
        po_unit.addlocation(unit.getid())
        po_unit.source = unit.value
        po_unit.addnote(unit.comment, "developer")

        return po_unit
コード例 #11
0
ファイル: php2po.py プロジェクト: imankulov/translate
 def convertunit(self, inputunit, origin):
     """Converts a .php unit to a .po unit"""
     outputunit = po.pounit(encoding="UTF-8")
     outputunit.addnote(inputunit.getnotes(origin), origin)
     outputunit.addlocation("".join(inputunit.getlocations()))
     outputunit.source = inputunit.source
     outputunit.target = ""
     return outputunit
コード例 #12
0
ファイル: l20n2po.py プロジェクト: diorcety/translate
    def convert_l20nunit(self, unit):
        po_unit = po.pounit(encoding="UTF-8")
        po_unit.setid(unit.getid())
        po_unit.addlocation(unit.getid())
        po_unit.source = unit.value
        po_unit.addnote(unit.comment, "developer")

        return po_unit
コード例 #13
0
ファイル: csv2po.py プロジェクト: slide333333/translate
 def convertunit(self, csvunit):
     """converts csv unit to po unit"""
     pounit = po.pounit(encoding="UTF-8")
     if csvunit.location:
         pounit.addlocation(csvunit.location)
     pounit.source = csvunit.source
     pounit.target = csvunit.target
     return pounit
コード例 #14
0
ファイル: php2po.py プロジェクト: denji/translate
 def convertunit(self, inputunit, origin):
     """Converts a .php unit to a .po unit"""
     outputunit = po.pounit(encoding="UTF-8")
     outputunit.addnote(inputunit.getnotes(origin), origin)
     outputunit.addlocation("".join(inputunit.getlocations()))
     outputunit.source = inputunit.source
     outputunit.target = ""
     return outputunit
コード例 #15
0
def xaml2po(node, store):
    for n in node.childNodes:
        if n.nodeType == Node.ELEMENT_NODE:
            if (n.hasAttribute('Text')):
                unit = po.pounit(n.getAttribute('Text'))
                unit.addlocation(f'{n.nodeName}:{n.getAttribute("Name")}')
                store.addunit(unit)
            xaml2po(n, store)
コード例 #16
0
ファイル: prop2po.py プロジェクト: wojtek555/translate
 def convertmixedunit(self, labelprop, accesskeyprop, commenttype):
     label_unit = self.convertunit(labelprop, commenttype)
     accesskey_unit = self.convertunit(accesskeyprop, commenttype)
     if label_unit is None:
         return accesskey_unit
     if accesskey_unit is None:
         return label_unit
     target_unit = po.pounit(encoding="UTF-8")
     return self.mixer.mix_units(label_unit, accesskey_unit, target_unit)
コード例 #17
0
ファイル: dtd2po.py プロジェクト: alghaamdi/translate
 def convertmixedunit(self, labeldtd, accesskeydtd):
     label_unit = self.convertunit(labeldtd)
     accesskey_unit = self.convertunit(accesskeydtd)
     if label_unit is None:
         return accesskey_unit
     if accesskey_unit is None:
         return label_unit
     target_unit = po.pounit(encoding="UTF-8")
     return self.mixer.mix_units(label_unit, accesskey_unit, target_unit)
コード例 #18
0
ファイル: prop2po.py プロジェクト: Alexinger/translate
 def convertmixedunit(self, labelprop, accesskeyprop, commenttype):
     label_unit = self.convertunit(labelprop, commenttype)
     accesskey_unit = self.convertunit(accesskeyprop, commenttype)
     if label_unit is None:
         return accesskey_unit
     if accesskey_unit is None:
         return label_unit
     target_unit = po.pounit(encoding="UTF-8")
     return self.mixer.mix_units(label_unit, accesskey_unit, target_unit)
コード例 #19
0
ファイル: dtd2po.py プロジェクト: lambacck/translate
 def convertmixedunit(self, labeldtd, accesskeydtd):
     label_unit = self.convertunit(labeldtd)
     accesskey_unit = self.convertunit(accesskeydtd)
     if label_unit is None:
         return accesskey_unit
     if accesskey_unit is None:
         return label_unit
     target_unit = po.pounit(encoding="UTF-8")
     return self.mixer.mix_units(label_unit, accesskey_unit, target_unit)
コード例 #20
0
ファイル: test_pocount.py プロジェクト: flyeven/translate
 def count(self, source, expectedsource, target=None, expectedtarget=None):
     """simple helper to check the respective word counts"""
     poelement = po.pounit(source)
     if target is not None:
         poelement.target = target
     wordssource, wordstarget = statsdb.wordsinunit(poelement)
     print('Source (expected=%d; actual=%d): "%s"' % (expectedsource, wordssource, source))
     assert wordssource == expectedsource
     if target is not None:
         print('Target (expected=%d; actual=%d): "%s"' % (expectedtarget, wordstarget, target))
         assert wordstarget == expectedtarget
コード例 #21
0
ファイル: rc2po.py プロジェクト: Jobava/translate-toolkit
 def convert_unit(self, input_unit, commenttype):
     """Converts a .rc unit to a .po unit. Returns None if empty
     or not for translation."""
     if input_unit is None:
         return None
     # escape unicode
     output_unit = po.pounit(encoding="UTF-8")
     output_unit.addlocation("".join(input_unit.getlocations()))
     output_unit.source = input_unit.source
     output_unit.target = ""
     return output_unit
コード例 #22
0
ファイル: extract.py プロジェクト: prabushi/fjord
def create_pounit(filename, lineno, message, comments):
    unit = po.pounit(encoding='UTF-8')
    context, msgid = split_context(message)
    unit.setsource(msgid)
    if context:
        unit.msgctxt = ['"%s"' % context]
    for comment in comments:
        unit.addnote(comment, 'developer')

    unit.addlocation('%s:%s' % (filename, lineno))
    return unit
コード例 #23
0
 def convert_unit(self, input_unit, commenttype):
     """Converts a .rc unit to a .po unit. Returns None if empty
     or not for translation."""
     if input_unit is None:
         return None
     # escape unicode
     output_unit = po.pounit(encoding="UTF-8")
     output_unit.addlocation("".join(input_unit.getlocations()))
     output_unit.source = input_unit.source
     output_unit.target = ""
     return output_unit
コード例 #24
0
ファイル: test_pocount.py プロジェクト: surli/translate
 def count(self, source, expectedsource, target=None, expectedtarget=None):
     """simple helper to check the respective word counts"""
     poelement = po.pounit(source)
     if target is not None:
         poelement.target = target
     wordssource, wordstarget = statsdb.wordsinunit(poelement)
     print('Source (expected=%d; actual=%d): "%s"' % (expectedsource, wordssource, source))
     assert wordssource == expectedsource
     if target is not None:
         print('Target (expected=%d; actual=%d): "%s"' % (expectedtarget, wordstarget, target))
         assert wordstarget == expectedtarget
コード例 #25
0
ファイル: extract.py プロジェクト: groovecoder/fjord
def create_pounit(filename, lineno, message, comments):
    unit = po.pounit(encoding='UTF-8')
    context, msgid = split_context(message)
    unit.setsource(msgid)
    if context:
        unit.msgctxt = ['"%s"' % context]
    for comment in comments:
        unit.addnote(comment, 'developer')

    unit.addlocation('%s:%s' % (filename, lineno))
    return unit
コード例 #26
0
ファイル: test_dtd2po.py プロジェクト: anderson916/translate
 def test_escaping_newline_tabs(self):
     """test that we handle all kinds of newline permutations"""
     dtdsource = '<!ENTITY  noupdatesfound.intro "A hard coded newline.\\nAnd tab\\t and a \\r carriage return.">\n'
     converter = dtd2po.dtd2po()
     thedtd = dtd.dtdunit()
     thedtd.parse(dtdsource)
     thepo = po.pounit()
     converter.convertstrings(thedtd, thepo)
     print(thedtd)
     print(thepo.source)
     # \n in a dtd should also appear as \n in the PO file
     assert thepo.source == r"A hard coded newline.\nAnd tab\t and a \r carriage return."
コード例 #27
0
 def test_escaping_newline_tabs(self):
     """test that we handle all kinds of newline permutations"""
     dtdsource = '<!ENTITY  noupdatesfound.intro "A hard coded newline.\\nAnd tab\\t and a \\r carriage return.">\n'
     converter = dtd2po.dtd2po()
     thedtd = dtd.dtdunit()
     thedtd.parse(dtdsource)
     thepo = po.pounit()
     converter.convertstrings(thedtd, thepo)
     print(thedtd)
     print(thepo.source)
     # \n in a dtd should also appear as \n in the PO file
     assert thepo.source == r"A hard coded newline.\nAnd tab\t and a \r carriage return."
コード例 #28
0
ファイル: json2po.py プロジェクト: asyschikov/translate
    def convert_unit(self, input_unit, commenttype):
        """Converts a JSON unit to a PO unit

        :return: None if empty or not for translation
        """
        if input_unit is None:
            return None
        # escape unicode
        output_unit = po.pounit(encoding="UTF-8")
        output_unit.addlocation(input_unit.getid())
        output_unit.source = input_unit.source
        output_unit.target = ""
        return output_unit
コード例 #29
0
ファイル: json2po.py プロジェクト: lambacck/translate
    def convert_unit(self, input_unit, commenttype):
        """Converts a JSON unit to a PO unit

        :return: None if empty or not for translation
        """
        if input_unit is None:
            return None
        # escape unicode
        output_unit = po.pounit(encoding="UTF-8")
        output_unit.addlocation(input_unit.getid())
        output_unit.source = input_unit.source
        output_unit.target = ""
        return output_unit
コード例 #30
0
    def convert_unit(self, input_unit, commenttype):
        """Converts a RESX unit to a PO unit
        @return: None if empty or not for translation
        """
        if input_unit is None:
            return None

        output_unit = po.pounit(encoding="UTF-8")
        output_unit.addlocation(input_unit.getid())
        output_unit.source = input_unit.source
        output_unit.addnote(input_unit.getnotes("developer"), "developer")
        output_unit.target = ""

        return output_unit
コード例 #31
0
 def convertfile(self, tbxfile):
     """Converts a tbxfile to a tbxfile, and returns it. uses templatepo if
     given at construction
     """
     self.pofile = po.pofile()
     for tbxunit in tbxfile.units:
         term = po.pounit()
         term.source = tbxunit.source
         term.target = tbxunit.target
         term.setcontext(tbxunit.getnotes('definition'))
         term.addnote("Part of speech: %s" % tbxunit.getnotes('pos'), 'developer')
         self.pofile.addunit(term)
     self.pofile.removeduplicates()
     return self.pofile
コード例 #32
0
ファイル: oo2po.py プロジェクト: 0101011/translate-1
    def maketargetunit(self, part1, part2, translators_comment, key, subkey):
        """makes a base unit (.po or XLIFF) out of a subkey of two parts"""
        #TODO: Do better
        text1 = getattr(part1, subkey)
        if text1 == "":
            return None
        text2 = getattr(part2, subkey)

        unit = po.pounit(text1, encoding="UTF-8")
        unit.target = text2
        unit.addlocation(key + "." + subkey)
        if getattr(translators_comment, subkey).strip() != "":
            unit.addnote(getattr(translators_comment, subkey), origin="developer")
        return unit
コード例 #33
0
ファイル: resx2po.py プロジェクト: PhoneixS/translate
    def convert_unit(self, input_unit, commenttype):
        """Converts a RESX unit to a PO unit
        @return: None if empty or not for translation
        """
        if input_unit is None:
            return None

        output_unit = po.pounit(encoding="UTF-8")
        output_unit.addlocation(input_unit.getid())
        output_unit.source = input_unit.source
        output_unit.addnote(input_unit.getnotes("developer"), "developer")
        output_unit.target = ""

        return output_unit
コード例 #34
0
ファイル: ts2po.py プロジェクト: jagg81/translate-toolkit
 def convertmessage(self, contextname, messagenum, source, target, msgcomments, transtype):
     """makes a pounit from the given message"""
     thepo = po.pounit(encoding="UTF-8")
     thepo.addlocation("%s#%d" % (contextname, messagenum))
     thepo.source = source
     thepo.target = target
     if len(msgcomments) > 0:
         thepo.addnote(msgcomments)
     if transtype == "unfinished" and thepo.istranslated():
         thepo.markfuzzy()
     if transtype == "obsolete":
         # This should use the Gettext obsolete method but it would require quite a bit of work
         thepo.addnote("(obsolete)", origin="developer")
         # using the fact that -- quote -- "(this is nonsense)"
     return thepo
コード例 #35
0
ファイル: dtd2po.py プロジェクト: alghaamdi/translate
    def convertunit(self, dtd_unit):
        """Converts a simple (non-mixed) dtd unit into a po unit.

        Returns None if empty or not for translation.
        """
        if dtd_unit is None:
            return None
        po_unit = po.pounit(encoding="UTF-8")
        # remove unwanted stuff
        for commentnum in range(len(dtd_unit.comments)):
            commenttype, locnote = dtd_unit.comments[commentnum]
            # if this is a localization note
            if commenttype == 'locnote':
                # parse the locnote into the entity and the actual note
                typeend = quote.findend(locnote, 'LOCALIZATION NOTE')
                # parse the id
                idstart = locnote.find('(', typeend)
                if idstart == -1:
                    continue
                idend = locnote.find(')', (idstart + 1))
                entity = locnote[idstart+1:idend].strip()
                # parse the actual note
                actualnotestart = locnote.find(':', (idend + 1))
                actualnoteend = locnote.find('-->', idend)
                actualnote = locnote[actualnotestart+1:actualnoteend].strip()
                # if it's for this entity, process it
                if dtd_unit.getid() == entity:
                    # if it says don't translate (and nothing more),
                    if actualnote.startswith("DONT_TRANSLATE"):
                        # take out the entity,definition and the
                        # DONT_TRANSLATE comment
                        dtd_unit.setid("")
                        dtd_unit.source = ""
                        del dtd_unit.comments[commentnum]
                        # finished this for loop
                        break
                    else:
                        # convert it into an automatic comment, to be
                        # processed by convertcomments
                        dtd_unit.comments[commentnum] = ("automaticcomment",
                                                       actualnote)
        # do a standard translation
        self.convertcomments(dtd_unit, po_unit)
        self.convertstrings(dtd_unit, po_unit)
        if po_unit.isblank() and not po_unit.getlocations():
            return None
        else:
            return po_unit
コード例 #36
0
ファイル: dtd2po.py プロジェクト: lambacck/translate
    def convertunit(self, dtd_unit):
        """Converts a simple (non-mixed) dtd unit into a po unit.

        Returns None if empty or not for translation.
        """
        if dtd_unit is None:
            return None
        po_unit = po.pounit(encoding="UTF-8")
        # remove unwanted stuff
        for commentnum in range(len(dtd_unit.comments)):
            commenttype, locnote = dtd_unit.comments[commentnum]
            # if this is a localization note
            if commenttype == 'locnote':
                # parse the locnote into the entity and the actual note
                typeend = quote.findend(locnote, 'LOCALIZATION NOTE')
                # parse the id
                idstart = locnote.find('(', typeend)
                if idstart == -1:
                    continue
                idend = locnote.find(')', (idstart + 1))
                entity = locnote[idstart + 1:idend].strip()
                # parse the actual note
                actualnotestart = locnote.find(':', (idend + 1))
                actualnoteend = locnote.find('-->', idend)
                actualnote = locnote[actualnotestart + 1:actualnoteend].strip()
                # if it's for this entity, process it
                if dtd_unit.getid() == entity:
                    # if it says don't translate (and nothing more),
                    if actualnote.startswith("DONT_TRANSLATE"):
                        # take out the entity,definition and the
                        # DONT_TRANSLATE comment
                        dtd_unit.setid("")
                        dtd_unit.source = ""
                        del dtd_unit.comments[commentnum]
                        # finished this for loop
                        break
                    else:
                        # convert it into an automatic comment, to be
                        # processed by convertcomments
                        dtd_unit.comments[commentnum] = ("automaticcomment",
                                                         actualnote)
        # do a standard translation
        self.convertcomments(dtd_unit, po_unit)
        self.convertstrings(dtd_unit, po_unit)
        if po_unit.isblank() and not po_unit.getlocations():
            return None
        else:
            return po_unit
コード例 #37
0
ファイル: dtd2po.py プロジェクト: davedash/translate
 def convertunit(self, thedtd):
     """converts a dtd unit to a po unit, returns None if empty or not for
     translation"""
     if thedtd is None:
         return None
     if getattr(thedtd, "entityparameter", None) == "SYSTEM":
         return None
     thepo = po.pounit(encoding="UTF-8")
     # remove unwanted stuff
     for commentnum in range(len(thedtd.comments)):
         commenttype, locnote = thedtd.comments[commentnum]
         # if this is a localization note
         if commenttype == 'locnote':
             # parse the locnote into the entity and the actual note
             typeend = quote.findend(locnote, 'LOCALIZATION NOTE')
             # parse the id
             idstart = locnote.find('(', typeend)
             if idstart == -1:
                 continue
             idend = locnote.find(')', (idstart + 1))
             entity = locnote[idstart+1:idend].strip()
             # parse the actual note
             actualnotestart = locnote.find(':', (idend + 1))
             actualnoteend = locnote.find('-->', idend)
             actualnote = locnote[actualnotestart+1:actualnoteend].strip()
             # if it's for this entity, process it
             if thedtd.entity == entity:
                 # if it says don't translate (and nothing more),
                 if actualnote.startswith("DONT_TRANSLATE"):
                     # take out the entity,definition and the
                     # DONT_TRANSLATE comment
                     thedtd.entity = ""
                     thedtd.definition = ""
                     del thedtd.comments[commentnum]
                     # finished this for loop
                     break
                 else:
                     # convert it into an automatic comment, to be
                     # processed by convertcomments
                     thedtd.comments[commentnum] = ("automaticcomment",
                                                    actualnote)
     # do a standard translation
     self.convertcomments(thedtd, thepo)
     self.convertstrings(thedtd, thepo)
     if thepo.isblank() and not thepo.getlocations():
         return None
     else:
         return thepo
コード例 #38
0
ファイル: extract.py プロジェクト: robhudson/puente
def create_pounit(filename, lineno, msgid, comments, context):
    # FIXME: Test context handling
    unit = po.pounit(encoding="UTF-8")
    unit.setsource(msgid)
    if context:
        unit.msgctxt = ['"%s"' % context]
    for comment in comments:
        unit.addnote(comment, "developer")

    unit.addlocation("%s:%s" % (filename, lineno))
    # FIXME: Add variable format flags
    # if python-format:
    #     unit.settypecomment('python-format', present=True)
    # if python-brace-format:
    #     unit.settypecomment('python-brace-format', present=True)
    return unit
 def buildunits(self, candidates):
     """Builds a list of units conforming to base API, with the score in the comment"""
     units = []
     for score, candidate in candidates:
         if hasattr(candidate, "orig_source"):
             candidate.source = candidate.orig_source
             candidate.target = candidate.orig_target
         newunit = po.pounit(candidate.source)
         newunit.target = candidate.target
         newunit.markfuzzy(candidate.fuzzy)
         candidatenotes = candidate.getnotes().strip()
         if candidatenotes:
             newunit.addnote(candidatenotes)
         if self.addpercentage:
             newunit.addnote("%d%%" % score)
         units.append(newunit)
     return units
コード例 #40
0
ファイル: match.py プロジェクト: lehmannro/translate
 def buildunits(self, candidates):
     """Builds a list of units conforming to base API, with the score in the comment"""
     units = []
     for score, candidate in candidates:
         if hasattr(candidate, "orig_source"):
             candidate.source = candidate.orig_source
             candidate.target = candidate.orig_target
         newunit = po.pounit(candidate.source)
         newunit.target = candidate.target
         newunit.markfuzzy(candidate.fuzzy)
         candidatenotes = candidate.getnotes().strip()
         if candidatenotes:
             newunit.addnote(candidatenotes)
         if self.addpercentage:
             newunit.addnote("%d%%" % score)
         units.append(newunit)
     return units
コード例 #41
0
 def convertunit(self, thedtd):
     """converts a dtd unit to a po unit, returns None if empty or not for translation"""
     if thedtd is None:
         return None
     if getattr(thedtd, "entityparameter", None) == "SYSTEM":
         return None
     thepo = po.pounit(encoding="UTF-8")
     # remove unwanted stuff
     for commentnum in range(len(thedtd.comments)):
         commenttype, locnote = thedtd.comments[commentnum]
         # if this is a localization note
         if commenttype == 'locnote':
             # parse the locnote into the entity and the actual note
             typeend = quote.findend(locnote, 'LOCALIZATION NOTE')
             # parse the id
             idstart = locnote.find('(', typeend)
             if idstart == -1:
                 continue
             idend = locnote.find(')', idstart + 1)
             entity = locnote[idstart + 1:idend].strip()
             # parse the actual note
             actualnotestart = locnote.find(':', idend + 1)
             actualnoteend = locnote.find('-->', idend)
             actualnote = locnote[actualnotestart + 1:actualnoteend].strip()
             # if it's for this entity, process it
             if thedtd.entity == entity:
                 # if it says don't translate (and nothing more),
                 if actualnote.startswith("DONT_TRANSLATE"):
                     # take out the entity,definition and the DONT_TRANSLATE comment
                     thedtd.entity = ""
                     thedtd.definition = ""
                     del thedtd.comments[commentnum]
                     # finished this for loop
                     break
                 else:
                     # convert it into an automatic comment, to be processed by convertcomments
                     thedtd.comments[commentnum] = ("automaticcomment",
                                                    actualnote)
     # do a standard translation
     self.convertcomments(thedtd, thepo)
     self.convertstrings(thedtd, thepo)
     if thepo.isblank() and not thepo.getlocations():
         return None
     else:
         return thepo
コード例 #42
0
ファイル: utils.py プロジェクト: ta2-1/pootle_fs
def _update_store(plugin, pootle_path):
    from django.contrib.auth import get_user_model

    from pootle_store.models import Store, Revision

    store = Store.objects.get(pootle_path=pootle_path)
    revision = Revision.incr()
    uid = uuid.uuid4().hex
    unitid = "New unit %s" % uid
    unit = pounit(unitid)
    unit.target = "Bar %s" % uid
    user = plugin.pootle_user
    if user is None:
        User = get_user_model()
        user = User.objects.get_system_user()
    unit.store = store
    unit = store.addunit(unit, user=user, update_revision=revision)
    store.save()
コード例 #43
0
ファイル: utils.py プロジェクト: ta2-1/pootle_fs
def _update_store(plugin, pootle_path):
    from django.contrib.auth import get_user_model

    from pootle_store.models import Store, Revision

    store = Store.objects.get(pootle_path=pootle_path)
    revision = Revision.incr()
    uid = uuid.uuid4().hex
    unitid = "New unit %s" % uid
    unit = pounit(unitid)
    unit.target = "Bar %s" % uid
    user = plugin.pootle_user
    if user is None:
        User = get_user_model()
        user = User.objects.get_system_user()
    unit.store = store
    unit = store.addunit(unit, user=user, update_revision=revision)
    store.save()
コード例 #44
0
ファイル: tiki2po.py プロジェクト: dwaynebailey/translate
    def convertstore(self, thetikifile):
        """Converts a given (parsed) tiki file to a po file.

        :param thetikifile: a tikifile pre-loaded with input data
        """
        thetargetfile = po.pofile()

        # For each lang unit, make the new po unit accordingly
        for unit in thetikifile.units:
            if not self.includeunused and "unused" in unit.getlocations():
                continue
            newunit = po.pounit()
            newunit.source = unit.source
            newunit.target = unit.target
            locations = unit.getlocations()
            if locations:
                newunit.addlocations(locations)
            thetargetfile.addunit(newunit)
        return thetargetfile
コード例 #45
0
ファイル: prop2po.py プロジェクト: cc-archive/pootle
 def convertunit(self, propunit, commenttype):
     """Converts a .properties unit to a .po unit. Returns None if empty
     or not for translation."""
     if propunit is None:
         return None
     # escape unicode
     pounit = po.pounit(encoding="UTF-8")
     if hasattr(propunit, "comments"):
         for comment in propunit.comments:
             if "DONT_TRANSLATE" in comment:
                 return "discard"
         pounit.addnote(u"".join(propunit.getnotes()).rstrip(), commenttype)
     # TODO: handle multiline msgid
     if propunit.isblank():
         return None
     pounit.addlocation(propunit.name)
     pounit.source = propunit.source
     pounit.target = u""
     return pounit
コード例 #46
0
ファイル: tiki2po.py プロジェクト: r-o-b-b-i-e/translate
    def convertstore(self, thetikifile):
        """Converts a given (parsed) tiki file to a po file.

        :param thetikifile: a tikifile pre-loaded with input data
        """
        thetargetfile = po.pofile()

        # For each lang unit, make the new po unit accordingly
        for unit in thetikifile.units:
            if not self.includeunused and "unused" in unit.getlocations():
                continue
            newunit = po.pounit()
            newunit.source = unit.source
            newunit.target = unit.target
            locations = unit.getlocations()
            if locations:
                newunit.addlocations(locations)
            thetargetfile.addunit(newunit)
        return thetargetfile
コード例 #47
0
 def convertunit(self, propunit, commenttype):
     """Converts a .properties unit to a .po unit. Returns None if empty
     or not for translation."""
     if propunit is None:
         return None
     # escape unicode
     pounit = po.pounit(encoding="UTF-8")
     if hasattr(propunit, "comments"):
         for comment in propunit.comments:
             if "DONT_TRANSLATE" in comment:
                 return "discard"
         pounit.addnote(u"".join(propunit.getnotes()).rstrip(), commenttype)
     # TODO: handle multiline msgid
     if propunit.isblank():
         return None
     pounit.addlocation(propunit.name)
     pounit.source = propunit.source
     pounit.target = u""
     return pounit
コード例 #48
0
ファイル: extract.py プロジェクト: guoyu07/tower-2
def create_pounit(filename, lineno, message, comments):
    unit = po.pounit(encoding="UTF-8")
    if isinstance(message, tuple):
        _, s = split_context(message[0])
        c, p = split_context(message[1])
        unit.setsource([s, p])
        # Workaround for http://bugs.locamotion.org/show_bug.cgi?id=1385
        unit.target = [u"", u""]
    else:
        c, m = split_context(message)
        unit.setsource(m)
    if c:
        unit.msgctxt = ['"%s"' % c]
    if comments:
        for comment in comments:
            unit.addnote(comment, "developer")

    unit.addlocation("%s:%s" % (filename, lineno))
    return unit
コード例 #49
0
ファイル: extract.py プロジェクト: xethorn/tower
def create_pounit(filename, lineno, message, comments):
    unit = po.pounit(encoding="UTF-8")
    if isinstance(message, tuple):
        _, s = split_context(message[0])
        c, p = split_context(message[1])
        unit.setsource([s, p])
        # Workaround for http://bugs.locamotion.org/show_bug.cgi?id=1385
        unit.target = [u"", u""]
    else:
        c, m = split_context(message)
        unit.setsource(m)
    if c:
        unit.msgctxt = ['"%s"' % c]
    if comments:
        for comment in comments:
            unit.addnote(comment, "developer")

    unit.addlocation("%s:%s" % (filename, lineno))
    return unit
コード例 #50
0
def create_termunit(term, unit, targets, locations, sourcenotes, transnotes, filecounts):
    termunit = po.pounit(term)
    if unit is not None:
        termunit.merge(unit, overwrite=False, comments=False)
    if len(targets.keys()) > 1:
        txt = "; ".join(["%s {%s}" % (target, ", ".join(files)) for target, files in targets.iteritems()])
        if termunit.target.find("};") < 0:
            termunit.target = txt
            termunit.markfuzzy()
        else:
            # if annotated multiple terms already present, keep as-is
            termunit.addnote(txt, "translator")
    for location in locations:
        termunit.addlocation(location)
    for sourcenote in sourcenotes:
        termunit.addnote(sourcenote, "developer")
    for transnote in transnotes:
        termunit.addnote(transnote, "translator")
    for filename, count in filecounts.iteritems():
        termunit.addnote("(poterminology) %s (%d)\n" % (filename, count), "translator")
    return termunit
コード例 #51
0
def xlf2po(inputfile, outputfile, pot):
  tree = etree.parse(inputfile)
  nodes = tree.xpath("//xlf:trans-unit", namespaces=namespaces)

  po = pofile()

  for tu in nodes:
    source = tu.xpath('xlf:source', namespaces=namespaces)[0]
    unit = pounit(source.text)
    unit.msgctxt.append('"{0}"'.format(tu.get('id')))

    if pot:
      unit.markfuzzy()
    else:
      target = tu.xpath('xlf:target', namespaces=namespaces)
      if len(target) == 1:
        target = target[0]
        unit.settarget(target.text)
    po.units.append(unit)
  po.removeduplicates()
  po.savefile(outputfile)
コード例 #52
0
 def convertunit(self, source_str, target_str):
     pounit = po.pounit(encoding="UTF-8")
     pounit.source = source_str
     if target_str:
         pounit.target = target_str
     return pounit
コード例 #53
0
ファイル: web2py2po.py プロジェクト: Esya/translate
 def convertunit(self, source_str, target_str):
     pounit = po.pounit(encoding="UTF-8")
     pounit.setsource(source_str)
     if target_str:
         pounit.settarget(target_str)
     return pounit
コード例 #54
0
ファイル: packages2po.py プロジェクト: lnussel/patterns
 def translate(name, msg):
     u = po.pounit(encoding="UTF-8")
     u.addlocation(name)
     u.source = msg
     u.target = ""
     pofile.addunit(u)
コード例 #55
0
 def convertunit(self, source_str, target_str):
     pounit = po.pounit(encoding="UTF-8")
     pounit.setsource(source_str)
     if target_str:
         pounit.settarget(target_str)
     return pounit