本文整理汇总了Python中translate.storage.tmx.tmxfile函数的典型用法代码示例。如果您正苦于以下问题:Python tmxfile函数的具体用法?Python tmxfile怎么用?Python tmxfile使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了tmxfile函数的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: po2tmx
def po2tmx(self, posource, sourcelanguage='en', targetlanguage='af'):
"""helper that converts po source to tmx source without requiring files"""
inputfile = wStringIO.StringIO(posource)
outputfile = wStringIO.StringIO()
outputfile.tmxfile = tmx.tmxfile(inputfile=None, sourcelanguage=sourcelanguage)
po2tmx.convertpo(inputfile, outputfile, templatefile=None, sourcelanguage=sourcelanguage, targetlanguage=targetlanguage)
return outputfile.tmxfile
开发者ID:AshishNamdev,项目名称:verbatim,代码行数:7,代码来源:test_po2tmx.py
示例2: test_addtranslation
def test_addtranslation(self):
"""tests that addtranslation() stores strings correctly"""
tmxfile = tmx.tmxfile()
tmxfile.addtranslation("A string of characters", "en", "'n String karakters", "af")
newfile = self.tmxparse(str(tmxfile))
print(str(tmxfile))
assert newfile.translate("A string of characters") == "'n String karakters"
开发者ID:anderson916,项目名称:translate,代码行数:7,代码来源:test_tmx.py
示例3: test_withnewlines
def test_withnewlines(self):
"""test addtranslation() with newlines"""
tmxfile = tmx.tmxfile()
tmxfile.addtranslation("First line\nSecond line", "en", "Eerste lyn\nTweede lyn", "af")
newfile = self.tmxparse(str(tmxfile))
print(str(tmxfile))
assert newfile.translate("First line\nSecond line") == "Eerste lyn\nTweede lyn"
开发者ID:anderson916,项目名称:translate,代码行数:7,代码来源:test_tmx.py
示例4: export
def export(self, rotate=False):
source_language = self.context.project.source_language.code
target_language = self.context.language.code
if not os.path.exists(self.directory):
os.makedirs(self.directory)
tmxfile = tmx.tmxfile()
for store in self.context.stores.live().iterator():
for unit in store.units.filter(state=TRANSLATED):
tmxfile.addtranslation(unit.source, source_language,
unit.target, target_language,
unit.developer_comment)
bs = BytesIO()
tmxfile.serialize(bs)
with open(self.abs_filepath, "wb") as f:
with ZipFile(f, "w") as zf:
zf.writestr(self.filename.rstrip('.zip'), bs.getvalue())
last_exported_filepath = self.last_exported_file_path
self.update_exported_revision()
removed = []
if rotate:
for fn in os.listdir(self.directory):
# Skip files from other projects.
if not self.check_tp(fn):
continue
filepath = os.path.join(self.directory, fn)
if filepath not in [self.abs_filepath, last_exported_filepath]:
removed.append(filepath)
os.remove(filepath)
return self.abs_filepath, removed
开发者ID:claudep,项目名称:pootle,代码行数:35,代码来源:utils.py
示例5: test_withcomment
def test_withcomment(self):
"""tests that addtranslation() stores string's comments correctly"""
tmxfile = tmx.tmxfile()
tmxfile.addtranslation("A string of chars",
"en", "'n String karakters", "af", "comment")
newfile = self.tmxparse(str(tmxfile))
print(str(tmxfile))
assert newfile.findunit("A string of chars").getnotes() == "comment"
开发者ID:anderson916,项目名称:translate,代码行数:8,代码来源:test_tmx.py
示例6: po2tmx
def po2tmx(self, posource, sourcelanguage='en', targetlanguage='af',
comment=None):
"""helper that converts po source to tmx source without requiring files"""
inputfile = BytesIO(posource.encode('utf-8'))
outputfile = BytesIO()
outputfile.tmxfile = tmx.tmxfile(inputfile=None, sourcelanguage=sourcelanguage)
po2tmx.convertpo(inputfile, outputfile, templatefile=None,
sourcelanguage=sourcelanguage,
targetlanguage=targetlanguage, comment=comment)
return outputfile.tmxfile
开发者ID:diorcety,项目名称:translate,代码行数:10,代码来源:test_po2tmx.py
示例7: __init__
def __init__(self, filename, mode=None):
"""initialises tmxmultifile from a seekable inputfile or writable outputfile"""
self.filename = filename
if mode is None:
if os.path.exists(filename):
mode = 'r'
else:
mode = 'w'
self.mode = mode
# self.multifilestyle = multifilestyle
self.multifilename = os.path.splitext(filename)[0]
# self.multifile = open(filename, mode)
self.tmxfile = tmx.tmxfile()
开发者ID:ANKIT-KS,项目名称:fjord,代码行数:13,代码来源:po2tmx.py
示例8: test_xmlentities
def test_xmlentities(self):
"""Test that the xml entities '&' and '<' are escaped correctly"""
tmxfile = tmx.tmxfile()
tmxfile.addtranslation("Mail & News", "en", "Nuus & pos", "af")
tmxfile.addtranslation("Five < ten", "en", "Vyf < tien", "af")
xmltext = str(tmxfile)
print("The generated xml:")
print(xmltext)
assert tmxfile.translate('Mail & News') == 'Nuus & pos'
assert xmltext.index('Mail & News')
assert xmltext.find('Mail & News') == -1
assert tmxfile.translate('Five < ten') == 'Vyf < tien'
assert xmltext.index('Five < ten')
assert xmltext.find('Five < ten') == -1
开发者ID:anderson916,项目名称:translate,代码行数:14,代码来源:test_tmx.py
示例9: get_storage
def get_storage(self):
return tmxfile()
开发者ID:nijel,项目名称:weblate,代码行数:2,代码来源:exporters.py
示例10: inittmx
def inittmx(inputfile, columnorder=None):
return tmx.tmxfile(inputfile)
开发者ID:AndryulE,项目名称:kitsune,代码行数:2,代码来源:lookupservice.py
示例11: test_translate
def test_translate(self):
tmxfile = tmx.tmxfile()
assert tmxfile.translate("Anything") is None
tmxfile.addtranslation("A string of characters", "en", "'n String karakters", "af")
assert tmxfile.translate("A string of characters") == "'n String karakters"
开发者ID:anderson916,项目名称:translate,代码行数:5,代码来源:test_tmx.py
示例12: tmxparse
def tmxparse(self, tmxsource):
"""helper that parses tmx source without requiring files"""
dummyfile = wStringIO.StringIO(tmxsource)
print(tmxsource)
tmxfile = tmx.tmxfile(dummyfile)
return tmxfile
开发者ID:anderson916,项目名称:translate,代码行数:6,代码来源:test_tmx.py
注:本文中的translate.storage.tmx.tmxfile函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论