本文整理汇总了Python中translate.storage.xliff.xlifffile函数的典型用法代码示例。如果您正苦于以下问题:Python xlifffile函数的具体用法?Python xlifffile怎么用?Python xlifffile使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了xlifffile函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: test_notes
def test_notes(self):
xlifffile = xliff.xlifffile()
unit = xlifffile.addsourceunit("Concept")
# We don't want to add unnecessary notes
assert not "note" in str(xlifffile)
unit.addnote(None)
assert not "note" in str(xlifffile)
unit.addnote("")
assert not "note" in str(xlifffile)
unit.addnote("Please buy bread")
assert unit.getnotes() == "Please buy bread"
notenodes = unit.xmlelement.findall(".//%s" % unit.namespaced("note"))
assert len(notenodes) == 1
unit.addnote("Please buy milk", origin="Mom")
notenodes = unit.xmlelement.findall(".//%s" % unit.namespaced("note"))
assert len(notenodes) == 2
assert not "from" in notenodes[0].attrib
assert notenodes[1].get("from") == "Mom"
assert unit.getnotes(origin="Mom") == "Please buy milk"
unit.addnote("Don't forget the beer", origin="Dad")
notenodes = unit.xmlelement.findall(".//%s" % unit.namespaced("note"))
assert len(notenodes) == 3
assert notenodes[1].get("from") == "Mom"
assert notenodes[2].get("from") == "Dad"
assert unit.getnotes(origin="Dad") == "Don't forget the beer"
assert not unit.getnotes(origin="Bob") == "Please buy bread\nPlease buy milk\nDon't forget the beer"
assert not notenodes[2].get("from") == "Mom"
assert not "from" in notenodes[0].attrib
assert unit.getnotes() == "Please buy bread\nPlease buy milk\nDon't forget the beer"
assert unit.correctorigin(notenodes[2], "ad") == True
assert unit.correctorigin(notenodes[2], "om") == False
开发者ID:AndreasEisele,项目名称:wikitrans-pootle,代码行数:35,代码来源:test_xliff.py
示例2: test_rich_target
def test_rich_target(self):
xlifffile = xliff.xlifffile()
xliffunit = xlifffile.addsourceunit(u'')
# Test 1
xliffunit.set_rich_target([StringElem([u'foo', X(id='bar'), u'baz'])], u'fr')
target_dom_node = xliffunit.getlanguageNode(None, 1)
x_placeable = target_dom_node[0]
assert target_dom_node.text == 'foo'
assert x_placeable.tag == u'x'
assert x_placeable.attrib['id'] == 'bar'
assert x_placeable.tail == 'baz'
# Test 2
xliffunit.set_rich_target([StringElem([u'foo', u'baz', G(id='oof', sub=[G(id='zab', sub=[u'bar', u'rab'])])])], u'fr')
target_dom_node = xliffunit.getlanguageNode(None, 1)
g_placeable = target_dom_node[0]
nested_g_placeable = g_placeable[0]
assert target_dom_node.text == u'foobaz'
assert g_placeable.tag == u'g'
print 'g_placeable.text: %s (%s)' % (g_placeable.text, type(g_placeable.text))
assert g_placeable.text is None
assert g_placeable.attrib[u'id'] == u'oof'
assert g_placeable.tail is None
assert nested_g_placeable.tag == u'g'
assert nested_g_placeable.text == u'barrab'
assert nested_g_placeable.attrib[u'id'] == u'zab'
assert nested_g_placeable.tail is None
xliffunit.rich_target[0].print_tree(2)
assert xliffunit.rich_target == [StringElem([u'foobaz', G(id='oof', sub=[G(id='zab', sub=[u'barrab'])])])]
开发者ID:AndreasEisele,项目名称:wikitrans-pootle,代码行数:35,代码来源:test_xliff.py
示例3: test_target
def test_target(self):
xlifffile = xliff.xlifffile()
xliffunit = xlifffile.addsourceunit("Concept")
xliffunit.target = "Konsep"
newfile = xliff.xlifffile.parsestring(str(xlifffile))
print str(xlifffile)
assert newfile.findunit("Concept").target == "Konsep"
开发者ID:AndreasEisele,项目名称:wikitrans-pootle,代码行数:7,代码来源:test_xliff.py
示例4: test_source
def test_source(self):
xlifffile = xliff.xlifffile()
xliffunit = xlifffile.addsourceunit("Concept")
xliffunit.source = "Term"
newfile = xliff.xlifffile.parsestring(str(xlifffile))
print str(xlifffile)
assert newfile.findunit("Concept") is None
assert newfile.findunit("Term") is not None
开发者ID:AndreasEisele,项目名称:wikitrans-pootle,代码行数:8,代码来源:test_xliff.py
示例5: mergexliff
def mergexliff(self, templatesource, inputsource):
"""merges the sources of the given files and returns a new xlifffile object"""
templatefile = wStringIO.StringIO(templatesource)
inputfile = wStringIO.StringIO(inputsource)
outputfile = wStringIO.StringIO()
assert pomerge.mergestore(inputfile, outputfile, templatefile)
outputxliffstring = outputfile.getvalue()
print "Generated XML:"
print outputxliffstring
outputxlifffile = xliff.xlifffile(outputxliffstring)
return outputxlifffile
开发者ID:AndryulE,项目名称:kitsune,代码行数:11,代码来源:test_pomerge.py
示例6: test_preserve_filename
def test_preserve_filename(self):
"""Ensures that the filename is preserved."""
xliffsource = self.xliffskeleton % '''<trans-unit xml:space="preserve">
<source>nonsense</source>
<target>matlhapolosa</target>
</trans-unit>'''
self.create_testfile("snippet.xlf", xliffsource)
xlifffile = xliff.xlifffile(self.open_testfile("snippet.xlf"))
assert xlifffile.filename.endswith("snippet.xlf")
xlifffile.parse(xliffsource)
assert xlifffile.filename.endswith("snippet.xlf")
开发者ID:Veterini,项目名称:translate,代码行数:11,代码来源:test_xliff2po.py
示例7: test_basic
def test_basic(self):
xlifffile = xliff.xlifffile()
assert xlifffile.units == []
xlifffile.addsourceunit("Bla")
assert len(xlifffile.units) == 1
newfile = xliff.xlifffile.parsestring(str(xlifffile))
print str(xlifffile)
assert len(newfile.units) == 1
assert newfile.units[0].source == "Bla"
assert newfile.findunit("Bla").source == "Bla"
assert newfile.findunit("dit") is None
开发者ID:AndreasEisele,项目名称:wikitrans-pootle,代码行数:11,代码来源:test_xliff.py
示例8: pretranslatexliff
def pretranslatexliff(self, input_source, template_source=None):
"""helper that converts strings to po source without requiring files"""
input_file = wStringIO.StringIO(input_source)
if template_source:
template_file = wStringIO.StringIO(template_source)
else:
template_file = None
output_file = wStringIO.StringIO()
pretranslate.pretranslate_file(input_file, output_file, template_file)
output_file.seek(0)
return xliff.xlifffile(output_file.read())
开发者ID:XLeonardo,项目名称:translate-1,代码行数:12,代码来源:test_pretranslate.py
示例9: convertstore
def convertstore(self, theoofile, duplicatestyle="msgctxt"):
"""converts an entire oo file to a base class format (.po or XLIFF)"""
thetargetfile = xliff.xlifffile()
thetargetfile.setsourcelanguage(self.sourcelanguage)
thetargetfile.settargetlanguage(self.targetlanguage)
# create a header for the file
bug_url = 'http://qa.openoffice.org/issues/enter_bug.cgi' + ('''?subcomponent=ui&comment=&short_desc=Localization issue in file: %(filename)s&component=l10n&form_name=enter_issue''' % {"filename": theoofile.filename}).replace(" ", "%20").replace(":", "%3A")
# go through the oo and convert each element
for theoo in theoofile.units:
unitlist = self.convertelement(theoo)
for unit in unitlist:
thetargetfile.addunit(unit)
return thetargetfile
开发者ID:AlexArgus,项目名称:affiliates-lib,代码行数:13,代码来源:oo2xliff.py
示例10: dump_xliff
def dump_xliff(project, locale, relative_path):
"""Dump .xliff file with relative path from database."""
locale_directory_path = get_locale_directory(project, locale)["path"]
path = os.path.join(locale_directory_path, relative_path)
resource = Resource.objects.filter(project=project, path=relative_path)
entities = Entity.objects.filter(resource=resource, obsolete=False)
with open(path, 'r+') as f:
xf = xliff.xlifffile(f)
# Update target-language attribute in file nodes
for node in xf.document.getroot().iterchildren(xf.namespaced("file")):
node.set("target-language", locale.code)
for unit in xf.units:
key = unit.getid()
try:
entity = Entity.objects.get(resource=resource, key=key)
except Entity.DoesNotExist as e:
log.error('%s: Entity "%s" does not exist' % (path, original))
continue
try:
translation = Translation.objects.filter(
entity=entity, locale=locale, approved=True) \
.latest('date').string
unit.settarget(translation)
except Translation.DoesNotExist as e:
# Remove "approved" attribute
try:
del unit.xmlelement.attrib['approved']
except KeyError:
pass
# Remove "target" element
target = unit.xmlelement.find(unit.namespaced("target"))
if target:
unit.xmlelement.remove(target)
# Erase file and then write, otherwise content gets appended
f.seek(0)
f.truncate()
f.writelines(xf.__str__())
log.debug("File updated: " + path)
开发者ID:vivekanand1101,项目名称:pontoon,代码行数:48,代码来源:files.py
示例11: test_alttrans
def test_alttrans(self):
"""Test xliff <alt-trans> accessors"""
xlifffile = xliff.xlifffile()
unit = xlifffile.addsourceunit("Testing")
unit.addalttrans("ginmi")
unit.addalttrans("shikenki")
alternatives = unit.getalttrans()
assert alternatives[0].source == "Testing"
assert alternatives[0].target == "ginmi"
assert alternatives[1].target == "shikenki"
assert not unit.target
unit.addalttrans("Tasting", origin="bob", lang="eng")
alternatives = unit.getalttrans()
assert alternatives[2].target == "Tasting"
alternatives = unit.getalttrans(origin="bob")
assert alternatives[0].target == "Tasting"
unit.delalttrans(alternatives[0])
assert len(unit.getalttrans(origin="bob")) == 0
alternatives = unit.getalttrans()
assert len(alternatives) == 2
assert alternatives[0].target == "ginmi"
assert alternatives[1].target == "shikenki"
#clean up:
alternatives = unit.getalttrans()
for alt in alternatives:
unit.delalttrans(alt)
unit.addalttrans("targetx", sourcetxt="sourcex")
# test that the source node is before the target node:
alt = unit.getalttrans()[0]
altformat = etree.tostring(alt.xmlelement)
if isinstance(altformat, bytes):
altformat=altformat.decode('utf-8')
print(altformat)
assert altformat.find("<source") < altformat.find("<target")
# test that a new target is still before alt-trans (bug 1098)
unit.target = "newester target"
unitformat = str(unit)
print(unitformat)
assert unitformat.find("<source") < unitformat.find("<target") < unitformat.find("<alt-trans")
开发者ID:onia,项目名称:translate,代码行数:46,代码来源:test_xliff.py
示例12: mergexliff
def mergexliff(self, templatesource, inputsource, mergeblanks="yes",
mergefuzzy="yes",
mergecomments="yes"):
"""merges the sources of the given files and returns a new xlifffile
object"""
templatefile = wStringIO.StringIO(templatesource)
inputfile = wStringIO.StringIO(inputsource)
outputfile = wStringIO.StringIO()
assert pomerge.mergestore(inputfile, outputfile, templatefile,
mergeblanks=mergeblanks,
mergefuzzy=mergefuzzy,
mergecomments=mergecomments)
outputxliffstring = outputfile.getvalue()
print("Generated XML:")
print(outputxliffstring)
outputxlifffile = xliff.xlifffile(outputxliffstring)
return outputxlifffile
开发者ID:onia,项目名称:translate,代码行数:17,代码来源:test_pomerge.py
示例13: convertstore
def convertstore(self, theoofile, duplicatestyle="msgctxt"):
"""converts an entire oo file to a base class format (.po or XLIFF)"""
thetargetfile = xliff.xlifffile()
thetargetfile.setsourcelanguage(self.sourcelanguage)
thetargetfile.settargetlanguage(self.targetlanguage)
# create a header for the file
bug_url = 'http://qa.openoffice.org/issues/enter_bug.cgi?%s' % \
urlencode({"subcomponent": "ui",
"comment": "",
"short_desc": "Localization issue in file: %s" % \
theoofile.filename,
"component": "l10n",
"form_name": "enter_issue",
})
# go through the oo and convert each element
for theoo in theoofile.units:
unitlist = self.convertelement(theoo)
for unit in unitlist:
thetargetfile.addunit(unit)
return thetargetfile
开发者ID:ANKIT-KS,项目名称:fjord,代码行数:20,代码来源:oo2xliff.py
示例14: test_rich_source
def test_rich_source(self):
xlifffile = xliff.xlifffile()
xliffunit = xlifffile.addsourceunit(u'')
# Test 1
xliffunit.rich_source = [StringElem([u'foo', X(id='bar'), u'baz'])]
source_dom_node = xliffunit.getlanguageNode(None, 0)
x_placeable = source_dom_node[0]
assert source_dom_node.text == 'foo'
assert x_placeable.tag == u'x'
assert x_placeable.attrib['id'] == 'bar'
assert x_placeable.tail == 'baz'
xliffunit.rich_source[0].print_tree(2)
print xliffunit.rich_source
assert xliffunit.rich_source == [StringElem([StringElem(u'foo'), X(id='bar'), StringElem(u'baz')])]
# Test 2
xliffunit.rich_source = [StringElem([u'foo', u'baz', G(id='oof', sub=[G(id='zab', sub=[u'bar', u'rab'])])])]
source_dom_node = xliffunit.getlanguageNode(None, 0)
g_placeable = source_dom_node[0]
nested_g_placeable = g_placeable[0]
assert source_dom_node.text == u'foobaz'
assert g_placeable.tag == u'g'
assert g_placeable.text is None
assert g_placeable.attrib[u'id'] == u'oof'
assert g_placeable.tail is None
assert nested_g_placeable.tag == u'g'
assert nested_g_placeable.text == u'barrab'
assert nested_g_placeable.attrib[u'id'] == u'zab'
assert nested_g_placeable.tail is None
rich_source = xliffunit.rich_source
rich_source[0].print_tree(2)
assert rich_source == [StringElem([u'foobaz', G(id='oof', sub=[G(id='zab', sub=[u'barrab'])])])]
开发者ID:AndreasEisele,项目名称:wikitrans-pootle,代码行数:40,代码来源:test_xliff.py
示例15: test_multiple_filenodes
def test_multiple_filenodes(self):
xlfsource = '''<?xml version="1.0" encoding="utf-8"?>
<xliff version="1.1" xmlns="urn:oasis:names:tc:xliff:document:1.1">
<file original="file0" source-language="en" datatype="plaintext">
<body>
<trans-unit id="hello" approved="yes">
<source>Hello</source>
</trans-unit>
</body>
</file>
<file original="file1" source-language="en" datatype="plaintext">
<body>
<trans-unit id="world" approved="yes">
<source>World</source>
</trans-unit>
</body>
</file>
</xliff>'''
xfile = xliff.xlifffile.parsestring(xlfsource)
assert len(xfile.units) == 2
assert xfile.units[0].getid() == "file0\x04hello"
assert xfile.units[1].getid() == "file1\x04world"
xunit = xliff.xlifffile.UnitClass(source="goodbye")
xunit.setid("file2\x04goodbye")
xfile.addunit(xunit)
assert xfile.units[2].getid() == "file2\x04goodbye"
# if there is no file set it will use the active context
xunit = xliff.xlifffile.UnitClass(source="lastfile")
xunit.setid("lastfile")
xfile.addunit(xunit)
assert xfile.units[3].getid() == "file2\x04lastfile"
newxfile = xliff.xlifffile()
newxfile.addunit(xfile.units[0])
newxfile.addunit(xfile.units[1])
assert newxfile.units[0].getid() == "file0\x04hello"
assert newxfile.units[1].getid() == "file1\x04world"
assert newxfile.getfilenode("file0") is not None
assert newxfile.getfilenode("file1") is not None
assert not newxfile.getfilenode("foo")
开发者ID:diorcety,项目名称:translate,代码行数:39,代码来源:test_xliff.py
示例16: test_fuzzy
def test_fuzzy(self):
xlifffile = xliff.xlifffile()
unit = xlifffile.addsourceunit("Concept")
unit.markfuzzy()
assert unit.isfuzzy()
unit.target = "Konsep"
assert unit.isfuzzy()
unit.markfuzzy()
assert unit.isfuzzy()
unit.markfuzzy(False)
assert not unit.isfuzzy()
unit.markfuzzy(True)
assert unit.isfuzzy()
#If there is no target, we can't really indicate fuzzyness, so we set
#approved to "no". If we want isfuzzy() to reflect that, the line can
#be uncommented
unit.target = None
assert unit.target is None
print unit
unit.markfuzzy(True)
assert 'approved="no"' in str(unit)
开发者ID:AndreasEisele,项目名称:wikitrans-pootle,代码行数:22,代码来源:test_xliff.py
示例17: extract_xliff
def extract_xliff(project, locale, path, entities=False):
"""Extract .xliff file with path and save or update in DB."""
with open(path) as f:
xf = xliff.xlifffile(f)
relative_path = get_relative_path(path, locale)
resource, created = Resource.objects.get_or_create(
project=project, path=relative_path, format='xliff')
if entities:
for order, unit in enumerate(xf.units):
save_entity(
resource=resource,
string=unicode(unit.get_rich_source()[0]),
key=unit.getid(),
comment=unit.getnotes(),
order=order)
update_entity_count(resource)
else:
for unit in xf.units:
translation = unicode(unit.get_rich_target()[0])
if translation:
try:
e = Entity.objects.get(
resource=resource, key=unit.getid())
save_translation(
entity=e, locale=locale, string=translation)
except Entity.DoesNotExist:
continue
update_stats(resource, locale)
log.debug("[" + locale.code + "]: " + path + " saved to DB.")
开发者ID:vivekanand1101,项目名称:pontoon,代码行数:37,代码来源:files.py
示例18: test_sourcelanguage
def test_sourcelanguage(self):
xlifffile = xliff.xlifffile(sourcelanguage="xh")
xmltext = bytes(xlifffile).decode('utf-8')
print(xmltext)
assert xmltext.find('source-language="xh"') > 0
开发者ID:XLeonardo,项目名称:translate-1,代码行数:5,代码来源:test_xliff.py
示例19: parse
def parse(path, source_path=None):
with open(path) as f:
xliff_file = xliff.xlifffile(f)
return XLIFFResource(path, xliff_file)
开发者ID:dsaumyajit007,项目名称:pontoon,代码行数:4,代码来源:xliff.py
示例20: setup_method
def setup_method(self, method):
self.postore = po.pofile(PO_DOC.encode('utf-8'))
self.xliffstore = xliff.xlifffile(XLIFF_DOC.encode('utf-8'))
开发者ID:Jobava,项目名称:translate-toolkit,代码行数:3,代码来源:test_podebug.py
注:本文中的translate.storage.xliff.xlifffile函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论