• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Python po.pounit函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中translate.storage.po.pounit函数的典型用法代码示例。如果您正苦于以下问题:Python pounit函数的具体用法?Python pounit怎么用?Python pounit使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了pounit函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。

示例1: convertmixedunit

 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
开发者ID:AlexArgus,项目名称:affiliates-lib,代码行数:25,代码来源:dtd2po.py


示例2: converttransunit

    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
开发者ID:Jobava,项目名称:translate-toolkit,代码行数:34,代码来源:xliff2po.py


示例3: convertunit

 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
开发者ID:translate,项目名称:translate,代码行数:7,代码来源:web2py2po.py


示例4: convert_l20nunit

    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
开发者ID:diorcety,项目名称:translate,代码行数:8,代码来源:l20n2po.py


示例5: convertunit

 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
开发者ID:cc-archive,项目名称:pootle,代码行数:8,代码来源:csv2po.py


示例6: convertunit

 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
开发者ID:denji,项目名称:translate,代码行数:8,代码来源:php2po.py


示例7: convertmixedunit

 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)
开发者ID:alghaamdi,项目名称:translate,代码行数:9,代码来源:dtd2po.py


示例8: convertmixedunit

 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)
开发者ID:Alexinger,项目名称:translate,代码行数:9,代码来源:prop2po.py


示例9: count

 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
开发者ID:flyeven,项目名称:translate,代码行数:11,代码来源:test_pocount.py


示例10: convert_unit

 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
开发者ID:Jobava,项目名称:translate-toolkit,代码行数:11,代码来源:rc2po.py


示例11: create_pounit

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
开发者ID:prabushi,项目名称:fjord,代码行数:11,代码来源:extract.py


示例12: test_escaping_newline_tabs

 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."
开发者ID:anderson916,项目名称:translate,代码行数:12,代码来源:test_dtd2po.py


示例13: convert_unit

    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
开发者ID:asyschikov,项目名称:translate,代码行数:13,代码来源:json2po.py


示例14: convertfile

 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
开发者ID:Veterini,项目名称:translate,代码行数:14,代码来源:tbx2po.py


示例15: convert_unit

    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
开发者ID:PhoneixS,项目名称:translate,代码行数:14,代码来源:resx2po.py


示例16: maketargetunit

    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
开发者ID:diorcety,项目名称:translate,代码行数:14,代码来源:oo2po.py


示例17: convertmessage

 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
开发者ID:jagg81,项目名称:translate-toolkit,代码行数:15,代码来源:ts2po.py


示例18: convertunit

 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
开发者ID:davedash,项目名称:translate,代码行数:48,代码来源:dtd2po.py


示例19: convertunit

    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
开发者ID:alghaamdi,项目名称:translate,代码行数:48,代码来源:dtd2po.py


示例20: create_pounit

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
开发者ID:robhudson,项目名称:puente,代码行数:16,代码来源:extract.py



注:本文中的translate.storage.po.pounit函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python pocommon.encodingToUse函数代码示例发布时间:2022-05-27
下一篇:
Python po.pofile函数代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap