当前位置: 首页>>代码示例>>Python>>正文


Python multistring.multistring函数代码示例

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


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

示例1: gettarget

 def gettarget(self):
     """Returns the unescaped msgstr"""
     if isinstance(self.msgstr, dict):
         multi = multistring(map(unquotefrompo, self.msgstr.values()), self._encoding)
     else:
         multi = multistring(unquotefrompo(self.msgstr), self._encoding)
     return multi
开发者ID:cc-archive,项目名称:pootle,代码行数:7,代码来源:pypo.py

示例2: settarget

    def settarget(self, text, lang='xx', append=False):
        self._rich_target = None
        if self.target == text:
            return
        if not self.hasplural():
            super(PoXliffUnit, self).settarget(text, lang, append)
            return
        if not isinstance(text, multistring):
            text = multistring(text)
        source = self.source
        sourcel = len(source.strings)
        targetl = len(text.strings)
        if sourcel < targetl:
            sources = source.strings + [source.strings[-1]] * (targetl - sourcel)
            targets = text.strings
            id = self.getid()
            self.source = multistring(sources)
            self.setid(id)
        elif targetl < sourcel:
            targets = text.strings + [""] * (sourcel - targetl)
        else:
            targets = text.strings

        for i in range(len(self.units)):
            self.units[i].target = targets[i]
开发者ID:anukat2015,项目名称:translate,代码行数:25,代码来源:poxliff.py

示例3: test_plurals

    def test_plurals(self):
        store = self.StoreClass()
        store.parse(JSON_I18NEXT)

        # Remove plurals
        store.units[2].target = 'Ahoj'
        store.units[3].target = 'Nazdar'
        out = BytesIO()
        store.serialize(out)

        assert out.getvalue() == JSON_I18NEXT_PLURAL

        # Bring back plurals
        store.units[2].target = multistring([
            "the singular",
            "the plural",
        ])
        store.units[3].target = multistring([
            "the plural form 0",
            "the plural form 1",
            "the plural form 2",
            "the plural form 3",
            "the plural form 4",
            "the plural form 5"
        ])
        out = BytesIO()
        store.serialize(out)

        assert out.getvalue() == JSON_I18NEXT
开发者ID:diorcety,项目名称:translate,代码行数:29,代码来源:test_jsonl10n.py

示例4: test_tp_tool_update

def test_tp_tool_update(po_directory, tp0, templates):
    new_lang = LanguageDBFactory()
    tp0_tool = TPTool(tp0.project)
    new_tp = tp0.project.translationproject_set.create(
        language=new_lang)

    # this will clone stores/directories as new_tp is empty
    tp0_tool.update_from_tp(tp0, new_tp)
    _test_tp_match(tp0, new_tp)
    tp0_tool.update_from_tp(tp0, new_tp)

    tp0.stores.first().delete()
    tp0.stores.first().units.first().delete()
    unit = tp0.stores.first().units.first()
    unit.source = multistring(["NEW TARGET", "NEW TARGETS"])
    unit.target = "NEW TARGET"
    unit.context = "something-else"
    unit.save()
    newunit = unit.__class__()
    newunit.source = multistring(["OTHER NEW TARGET", "OTHER NEW TARGETS"])
    newunit.target = "OTHER NEW TARGET"
    newunit.context = "something-else-again"
    unit.store.addunit(newunit)

    tp0_tool.update_from_tp(tp0, new_tp)
    _test_tp_match(tp0, new_tp)

    # doing another update does nothing
    tp0_tool.update_from_tp(tp0, new_tp)
    _test_tp_match(tp0, new_tp)
开发者ID:ainslied,项目名称:pootle,代码行数:30,代码来源:translationproject.py

示例5: test_unit_lifecycle_update_state_reviewed_by

def test_unit_lifecycle_update_state_reviewed_by(store0, system, member2):
    unit = store0.UnitClass()
    unit.store = store0
    unit.source_f = multistring("Foo")
    unit.target_f = multistring("Bar")
    unit.state = FUZZY
    unit.save(user=system)
    # force the unit to be refrozen
    unit = unit.__class__.objects.get(id=unit.id)
    unit.state = TRANSLATED
    unit.save(reviewed_by=member2)
    sub_state_update = lifecycle.get(Unit)(unit).sub_state_update()
    assert isinstance(sub_state_update, Submission)
    assert sub_state_update.unit == unit
    assert sub_state_update.translation_project == store0.translation_project
    assert sub_state_update.revision == unit.revision
    assert (
        sub_state_update.submitter
        == unit.change.reviewed_by
        == member2)
    assert sub_state_update.type == SubmissionTypes.SYSTEM
    assert sub_state_update.field == SubmissionFields.STATE
    assert sub_state_update.new_value == unit.state
    assert sub_state_update.old_value == unit._frozen.state
    assert not sub_state_update.pk
开发者ID:arky,项目名称:pootle,代码行数:25,代码来源:utils.py

示例6: to_python

 def to_python(self, value):
     if not value:
         return multistring("", encoding="UTF-8")
     elif isinstance(value, multistring):
         return value
     elif isinstance(value, basestring):
         return multistring(value.split(SEPERATOR), encoding="UTF-8")
     elif isinstance(value, dict):
         return multistring([val for key, val in sorted(value.items())], encoding="UTF-8")
     else:
         return multistring(value, encoding="UTF-8")
开发者ID:AndreasEisele,项目名称:wikitrans-pootle,代码行数:11,代码来源:fields.py

示例7: to_pypo

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

示例8: test_prevmsgid_parse

    def test_prevmsgid_parse(self):
        """checks that prevmsgid (i.e. #|) is parsed and saved correctly"""
        posource = r'''msgid ""
msgstr ""
"PO-Revision-Date: 2006-02-09 23:33+0200\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8-bit\n"

#, fuzzy
#| msgid "trea"
msgid "tree"
msgstr "boom"

#| msgid "trea"
#| msgid_plural "treas"
msgid "tree"
msgid_plural "trees"
msgstr[0] "boom"
msgstr[1] "bome"

#| msgctxt "context 1"
#| msgid "tast"
msgctxt "context 1a"
msgid "test"
msgstr "toets"

#| msgctxt "context 2"
#| msgid "tast"
#| msgid_plural "tasts"
msgctxt "context 2a"
msgid "test"
msgid_plural "tests"
msgstr[0] "toet"
msgstr[1] "toetse"
'''

        pofile = self.poparse(posource)

        assert pofile.units[1].prev_msgctxt == []
        assert pofile.units[1].prev_source == multistring([u"trea"])

        assert pofile.units[2].prev_msgctxt == []
        assert pofile.units[2].prev_source == multistring([u"trea", u"treas"])

        assert pofile.units[3].prev_msgctxt == [u'"context 1"']
        assert pofile.units[3].prev_source == multistring([u"tast"])

        assert pofile.units[4].prev_msgctxt == [u'"context 2"']
        assert pofile.units[4].prev_source == multistring([u"tast", u"tasts"])

        assert str(pofile) == posource
开发者ID:chhitz,项目名称:translate,代码行数:52,代码来源:test_pypo.py

示例9: to_python

def to_python(value):
    """Reconstruct a multistring from the database string representation."""
    if not value:
        return multistring("", encoding="UTF-8")
    elif isinstance(value, multistring):
        return value
    elif isinstance(value, basestring):
        return parse_multistring(value)
    elif isinstance(value, dict):
        return multistring([val for __, val in sorted(value.items())],
                           encoding="UTF-8")
    else:
        return multistring(value, encoding="UTF-8")
开发者ID:SafaAlfulaij,项目名称:pootle,代码行数:13,代码来源:fields.py

示例10: parse

 def parse(self, input):
     """parses the given file or file source string"""
     if hasattr(input, 'name'):
         self.filename = input.name
     elif not getattr(self, 'filename', ''):
         self.filename = ''
     if hasattr(input, "read"):
         mosrc = input.read()
         input.close()
         input = mosrc
     little, = struct.unpack("<L", input[:4])
     big, = struct.unpack(">L", input[:4])
     if little == MO_MAGIC_NUMBER:
         endian = "<"
     elif big == MO_MAGIC_NUMBER:
         endian = ">"
     else:
         raise ValueError("This is not an MO file")
     magic, version_maj, version_min, lenkeys, startkey, \
         startvalue, sizehash, offsethash = struct.unpack("%sLHHiiiii" % endian,
                                                          input[:(7 * 4)])
     if version_maj >= 1:
         raise base.ParseError("""Unable to process version %d.%d MO files""" % (version_maj, version_min))
     for i in range(lenkeys):
         nextkey = startkey + (i * 2 * 4)
         nextvalue = startvalue + (i * 2 * 4)
         klength, koffset = struct.unpack("%sii" % endian,
                                          input[nextkey:nextkey + (2 * 4)])
         vlength, voffset = struct.unpack("%sii" % endian,
                                          input[nextvalue:nextvalue + (2 * 4)])
         source = input[koffset:koffset + klength]
         context = None
         if b"\x04" in source:
             context, source = source.split(b"\x04")
         # Still need to handle KDE comments
         if source == "":
             charset = re.search(b"charset=([^\\s]+)",
                                 input[voffset:voffset + vlength])
             if charset:
                 self.encoding = charset.group(1)
         source = multistring([s.decode(self.encoding)
                               for s in source.split(b"\0")])
         target = multistring([s.decode(self.encoding)
                               for s in input[voffset:voffset + vlength].split(b"\0")])
         newunit = mounit(source)
         newunit.target = target
         if context is not None:
             newunit.msgctxt.append(context)
         self.addunit(newunit)
开发者ID:XLeonardo,项目名称:translate-1,代码行数:49,代码来源:mo.py

示例11: parse

 def parse(self, input):
     """parses the given file or file source string"""
     if hasattr(input, 'name'):
         self.filename = input.name
     elif not getattr(self, 'filename', ''):
         self.filename = ''
     if hasattr(input, "read"):
         mosrc = input.read()
         input.close()
         input = mosrc
     little, = struct.unpack("<L", input[:4])
     big, = struct.unpack(">L", input[:4])
     if little == MO_MAGIC_NUMBER:
         endian = "<"
     elif big == MO_MAGIC_NUMBER:
         endian = ">"
     else:
         raise ValueError("This is not an MO file")
     magic, version, lenkeys, startkey, \
     startvalue, sizehash, offsethash = struct.unpack("%sLiiiiii" % endian,
                                                      input[:(7 * 4)])
     if version > 1:
         raise ValueError("Unable to process MO files with versions > 1.  \
                          This is a %d version MO file" % version)
     for i in range(lenkeys):
         nextkey = startkey + (i * 2 * 4)
         nextvalue = startvalue + (i * 2 * 4)
         klength, koffset = struct.unpack("%sii" % endian,
                                          input[nextkey:nextkey + (2 * 4)])
         vlength, voffset = struct.unpack("%sii" % endian,
                                          input[nextvalue:nextvalue + (2 * 4)])
         source = input[koffset:koffset + klength]
         context = None
         if "\x04" in source:
             context, source = source.split("\x04")
         # Still need to handle KDE comments
         source = multistring(source.split("\0"), encoding=self._encoding)
         if source == "":
             charset = re.search("charset=([^\\s]+)",
                                 input[voffset:voffset + vlength])
             if charset:
                 self._encoding = po.encodingToUse(charset.group(1))
         target = multistring(input[voffset:voffset + vlength].split("\0"),
                              encoding=self._encoding)
         newunit = mounit(source)
         newunit.settarget(target)
         if context is not None:
             newunit.msgctxt.append(context)
         self.addunit(newunit)
开发者ID:lehmannro,项目名称:translate,代码行数:49,代码来源:mo.py

示例12: test_add_suggestion

def test_add_suggestion(client, request_users, settings):
    """Tests translation can be applied after suggestion is accepted."""
    settings.POOTLE_CAPTCHA_ENABLED = False
    user = request_users["user"]
    if user.username != "nobody":
        client.login(
            username=user.username,
            password=request_users["password"])

    unit = Unit.objects.all().first()
    url = '/xhr/units/%d/suggestions' % unit.id
    target = "%s TEST SUGGESTION" % unit.source
    response = client.post(
        url,
        {
            'target_f_0': target,
        },
        HTTP_X_REQUESTED_WITH='XMLHttpRequest'
    )

    assert response.status_code == 200
    changed = Unit.objects.get(id=unit.id)
    suggestion = changed.get_suggestions().order_by('id').last()
    assert suggestion.target == multistring(target)
    with pytest.raises(UnitChange.DoesNotExist):
        unit.change
开发者ID:claudep,项目名称:pootle,代码行数:26,代码来源:unit.py

示例13: handle_plurals

 def handle_plurals(self, plurals):
     if len(plurals) == 1:
         return self.string_filter(plurals[0])
     else:
         return multistring(
             [self.string_filter(plural) for plural in plurals]
         )
开发者ID:Yixf-Self,项目名称:weblate,代码行数:7,代码来源:exporters.py

示例14: gettarget

 def gettarget(self):
     if self.hasplural():
         plurals = []
         nplural = 0
         plural = gpo.po_message_msgstr_plural(self._gpo_message, nplural)
         while plural:
             plurals.append(plural.decode(self.CPO_ENC))
             nplural += 1
             plural = gpo.po_message_msgstr_plural(self._gpo_message, nplural)
         if plurals:
             multi = multistring(plurals, encoding=self.CPO_ENC)
         else:
             multi = multistring(u"")
     else:
         multi = (gpo.po_message_msgstr(self._gpo_message) or "").decode(self.CPO_ENC)
     return multi
开发者ID:flyeven,项目名称:translate,代码行数:16,代码来源:cpo.py

示例15: set_target

 def set_target(self, target):
     """Set translation unit target."""
     if 'target' in self.__dict__:
         del self.__dict__['target']
     if isinstance(target, list):
         target = multistring(target)
     self.unit.target = target
开发者ID:nijel,项目名称:weblate,代码行数:7,代码来源:ttkit.py


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