本文整理汇总了Python中translate.storage.po.pofile函数的典型用法代码示例。如果您正苦于以下问题:Python pofile函数的具体用法?Python pofile怎么用?Python pofile使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了pofile函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: convertpo
def convertpo(inputfile, outputfile, templatefile):
"""reads in stdin using fromfileclass, converts using convertorclass, writes to stdout"""
engstore = po.pofile(inputfile)
forstore = po.pofile(templatefile)
convertor = amo2po()
outputstore = convertor.convertstore(engstore, forstore)
if outputstore.isempty():
return 0
outputfile.write(str(outputstore))
return 1
开发者ID:AndreasEisele,项目名称:wikitrans-pootle,代码行数:10,代码来源:monopo2po.py
示例2: create_pofile_from_babel
def create_pofile_from_babel(extracted):
try:
if settings.TOWER_ADD_HEADERS:
catalog = po.pofile()
else:
catalog = po.pofile(inputfile="")
except AttributeError:
catalog = po.pofile(inputfile="")
for filename, lineno, message, comments in extracted:
unit = create_pounit(filename, lineno, message, comments)
catalog.addunit(unit)
catalog.removeduplicates()
return catalog
开发者ID:magopian,项目名称:tower,代码行数:13,代码来源:extract.py
示例3: po2xlf
def po2xlf(inputfile, originalfile, outputfile, lang = None):
tree = etree.parse(originalfile)
po = pofile()
po.parse(open(inputfile))
if lang is not None:
fileNode = tree.xpath("//xlf:file", namespaces=namespaces)[0]
fileNode.attrib['target-language'] = lang
for po_unit in po.units:
if po_unit.obsolete or len(po_unit.msgctxt) != 1:
continue
msgctxt = po_unit.msgctxt[0]
nodes = tree.xpath('//xlf:trans-unit[@id={0}]'.format(msgctxt), namespaces=namespaces)
if len(nodes) != 1:
print 'WARNING: XLIFF file missing trans-unit with id {0}.'.format(msgctxt)
continue
tu = nodes[0]
target = tu.xpath('xlf:target', namespaces=namespaces)
if len(target) == 0:
target = etree.Element('target', nsmap=namespaces)
tu.append(target)
else:
target = target[0]
target_text = unicode(po_unit.gettarget())
if target_text is not None:
target.text = target_text
tree.write(outputfile, encoding='UTF-8')
开发者ID:asgeirf,项目名称:spacewalk-translations,代码行数:29,代码来源:poxlf.py
示例4: po2dtd
def po2dtd(self, posource, remove_untranslated=False):
"""helper that converts po source to dtd source without requiring files"""
inputfile = wStringIO.StringIO(posource)
inputpo = po.pofile(inputfile)
convertor = po2dtd.po2dtd(remove_untranslated=remove_untranslated)
outputdtd = convertor.convertstore(inputpo)
return outputdtd
开发者ID:ANKIT-KS,项目名称:fjord,代码行数:7,代码来源:test_po2dtd.py
示例5: outputconflicts
def outputconflicts(self, options):
"""saves the result of the conflict match"""
print("%d/%d different strings have conflicts" % (len(self.conflictmap), len(self.textmap)))
reducedmap = {}
def str_len(x):
return len(x)
for source, translations in six.iteritems(self.conflictmap):
words = source.split()
words.sort(key=str_len)
source = words[-1]
reducedmap.setdefault(source, []).extend(translations)
# reduce plurals
plurals = {}
for word in reducedmap:
if word + "s" in reducedmap:
plurals[word] = word + "s"
for word, pluralword in six.iteritems(plurals):
reducedmap[word].extend(reducedmap.pop(pluralword))
for source, translations in six.iteritems(reducedmap):
flatsource = self.flatten(source, "-")
fulloutputpath = os.path.join(options.output, flatsource + os.extsep + "po")
conflictfile = po.pofile()
for target, unit, filename in translations:
unit.othercomments.append("# (poconflicts) %s\n" % filename)
conflictfile.units.append(unit)
with open(fulloutputpath, "wb") as fh:
conflictfile.serialize(fh)
开发者ID:anukat2015,项目名称:translate,代码行数:29,代码来源:poconflicts.py
示例6: mergestore
def mergestore(self, origpropfile, translatedpropfile, personality="java",
blankmsgstr=False, duplicatestyle="msgctxt"):
"""converts two .properties files to a .po file..."""
self.personality = personality
thetargetfile = po.pofile()
if self.personality in ("mozilla", "skype"):
targetheader = thetargetfile.init_headers(
x_accelerator_marker="&",
x_merge_on="location",
)
else:
targetheader = thetargetfile.header()
targetheader.addnote("extracted from %s, %s" % (origpropfile.filename, translatedpropfile.filename),
"developer")
translatedpropfile.makeindex()
# we try and merge the header po with any comments at the start of
# the properties file
appendedheader = False
waitingcomments = []
# loop through the original file, looking at units one by one
for origprop in origpropfile.units:
origpo = self.convertunit(origprop, "developer")
if origpo is None:
waitingcomments.extend(origprop.comments)
# FIXME the storage class should not be creating blank units
if origpo is "discard":
continue
# handle the header case specially...
if not appendedheader:
if origprop.isblank():
targetheader.addnote("".join(waitingcomments).rstrip(),
"developer", position="prepend")
waitingcomments = []
origpo = None
appendedheader = True
# try and find a translation of the same name...
if origprop.name in translatedpropfile.locationindex:
translatedprop = translatedpropfile.locationindex[origprop.name]
# Need to check that this comment is not a copy of the
# developer comments
translatedpo = self.convertunit(translatedprop, "translator")
if translatedpo is "discard":
continue
else:
translatedpo = None
# if we have a valid po unit, get the translation and add it...
if origpo is not None:
if translatedpo is not None and not blankmsgstr:
origpo.target = translatedpo.source
origpo.addnote("".join(waitingcomments).rstrip(),
"developer", position="prepend")
waitingcomments = []
thetargetfile.addunit(origpo)
elif translatedpo is not None:
logger.error("didn't convert original property definition '%s'",
origprop.name)
if self.personality == "gaia":
thetargetfile = self.fold_gaia_plurals(thetargetfile)
thetargetfile.removeduplicates(duplicatestyle)
return thetargetfile
开发者ID:onia,项目名称:translate,代码行数:60,代码来源:prop2po.py
示例7: po2lang
def po2lang(self, posource):
"""helper that converts po source to .lang source without requiring files"""
inputfile = wStringIO.StringIO(posource)
inputpo = po.pofile(inputfile)
convertor = po2mozlang.po2lang()
outputlang = convertor.convertstore(inputpo)
return outputlang
开发者ID:cc-archive,项目名称:pootle,代码行数:7,代码来源:test_po2mozlang.py
示例8: test_simplegrep_comments
def test_simplegrep_comments(self):
"""grep for a string in the comments"""
posource = '# (review) comment\n#: test.c\nmsgid "test"\nmsgstr "rest"\n'
poresult = self.pogrep(posource, "review", ["--search=comment"])
assert poresult.index(posource) >= 0
poresult = self.pogrep(posource, "test", ["--search=comment"])
assert headerless_len(po.pofile(poresult).units) == 0
开发者ID:onia,项目名称:translate,代码行数:7,代码来源:test_pogrep.py
示例9: test_simplegrep_msgstr
def test_simplegrep_msgstr(self):
"""grep for a string in the target"""
posource = '#: test.c\nmsgid "test"\nmsgstr "rest"\n'
poresult = self.pogrep(posource, "rest", ["--search=msgstr"])
assert poresult.index(posource) >= 0
poresult = self.pogrep(posource, "test", ["--search=msgstr"])
assert headerless_len(po.pofile(poresult).units) == 0
开发者ID:onia,项目名称:translate,代码行数:7,代码来源:test_pogrep.py
示例10: convertstore
def convertstore(self, inputfile, duplicatestyle="msgctxt"):
"""Converts a .xliff file to .po format"""
# XXX: The inputfile is converted to string because Pootle supplies
# XXX: a PootleFile object as input which cannot be sent to PoXliffFile
# XXX: The better way would be to have a consistent conversion API.
if not isinstance(inputfile, (io.IOBase, wStringIO.StringIO)):
inputfile = str(inputfile)
XliffFile = xliff.xlifffile.parsestring(inputfile)
thetargetfile = po.pofile()
targetheader = thetargetfile.header()
# TODO: support multiple files
for transunit in XliffFile.units:
if transunit.isheader():
thetargetfile.updateheader(add=True, **XliffFile.parseheader())
if transunit.getnotes('translator'):
targetheader.addnote(transunit.getnotes('translator'),
origin='translator',
position='replace')
if transunit.getnotes('developer'):
targetheader.addnote(transunit.getnotes('developer'),
origin='developer',
position='replace')
targetheader.markfuzzy(transunit.isfuzzy())
continue
thepo = self.converttransunit(transunit)
thetargetfile.addunit(thepo)
thetargetfile.removeduplicates(duplicatestyle)
return thetargetfile
开发者ID:onia,项目名称:translate,代码行数:28,代码来源:xliff2po.py
示例11: merge_store
def merge_store(self, template_store, input_store, blankmsgstr=False,
duplicatestyle="msgctxt"):
"""Converts two JSON files to a PO file"""
output_store = po.pofile()
output_header = output_store.init_headers(charset="UTF-8",
encoding="8bit")
output_header.addnote("extracted from %s, %s" % (template_store.filename,
input_store.filename),
"developer")
input_store.makeindex()
for template_unit in template_store.units:
origpo = self.convert_unit(template_unit, "developer")
# try and find a translation of the same name...
template_unit_name = "".join(template_unit.getlocations())
if template_unit_name in input_store.locationindex:
translatedjson = input_store.locationindex[template_unit_name]
translatedpo = self.convert_unit(translatedjson, "translator")
else:
translatedpo = None
# if we have a valid po unit, get the translation and add it...
if origpo is not None:
if translatedpo is not None and not blankmsgstr:
origpo.target = translatedpo.source
output_store.addunit(origpo)
elif translatedpo is not None:
print >> sys.stderr, "Error converting original JSON definition %s" % origpo.name
output_store.removeduplicates(duplicatestyle)
return output_store
开发者ID:davedash,项目名称:translate,代码行数:29,代码来源:json2po.py
示例12: po2lang
def po2lang(self, posource):
"""helper that converts po source to .lang source without requiring files"""
inputfile = wStringIO.StringIO(posource)
inputpo = po.pofile(inputfile)
convertor = po2mozlang.po2lang(mark_active=False)
outputlang = convertor.convertstore(inputpo)
return bytes(outputlang).decode('utf-8')
开发者ID:Veterini,项目名称:translate,代码行数:7,代码来源:test_po2mozlang.py
示例13: po2web2py
def po2web2py(self, po_source):
"""helper that converts po source to web2py source without requiring files"""
input_file = wStringIO.StringIO(po_source)
input_po = po.pofile(input_file)
convertor = po2web2py.po2pydict()
output_web2py = convertor.convertstore(input_po, False)
return output_web2py.read()
开发者ID:translate,项目名称:translate,代码行数:7,代码来源:test_po2web2py.py
示例14: test_convertphpempty
def test_convertphpempty(self):
"""checks that the convertphp function is working with empty template"""
phpsource = ''
phptemplate = ''
posource = self.convertphp(phpsource, phptemplate, 0)
pofile = po.pofile(wStringIO.StringIO(posource))
assert len(pofile.units) == 0
开发者ID:diorcety,项目名称:translate,代码行数:7,代码来源:test_php2po.py
示例15: create_pofile_from_babel
def create_pofile_from_babel(extracted):
catalog = po.pofile(inputfile="")
for filename, lineno, message, comments in extracted:
unit = create_pounit(filename, lineno, message, comments)
catalog.addunit(unit)
catalog.removeduplicates()
return catalog
开发者ID:mccammos,项目名称:zamboni,代码行数:7,代码来源:extract.py
示例16: test_timezones
def test_timezones():
pofile = po.pofile()
# The following will only work on Unix because of tzset() and %z
if 'tzset' in time.__dict__:
os.environ['TZ'] = 'Asia/Kabul'
time.tzset()
assert time.timezone == -16200
# Typically "+0430"
assert poheader.tzstring() == time.strftime("%z")
os.environ['TZ'] = 'Asia/Seoul'
time.tzset()
assert time.timezone == -32400
# Typically "+0900"
assert poheader.tzstring() == time.strftime("%z")
os.environ['TZ'] = 'Africa/Johannesburg'
time.tzset()
assert time.timezone == -7200
# Typically "+0200"
assert poheader.tzstring() == time.strftime("%z")
os.environ['TZ'] = 'Africa/Windhoek'
time.tzset()
assert time.timezone == -3600
# Typically "+0100"
# For some reason python's %z doesn't know about Windhoek DST
#assert poheader.tzstring() == time.strftime("%z")
os.environ['TZ'] = 'UTC'
time.tzset()
assert time.timezone == 0
# Typically "+0000"
assert poheader.tzstring() == time.strftime("%z")
开发者ID:dupuy,项目名称:translate,代码行数:35,代码来源:test_poheader.py
示例17: convertstore
def convertstore(self, thecsvfile):
"""converts a csvfile to a pofile, and returns it. uses templatepo if given at construction"""
self.csvfile = thecsvfile
if self.pofile is None:
self.pofile = po.pofile()
mergemode = False
else:
mergemode = True
if self.pofile.units and self.pofile.units[0].isheader():
targetheader = self.pofile.units[0]
self.pofile.updateheader(content_type="text/plain; charset=UTF-8", content_transfer_encoding="8bit")
else:
targetheader = self.pofile.makeheader(charset="UTF-8", encoding="8bit")
targetheader.addnote("extracted from %s" % self.csvfile.filename, "developer")
mightbeheader = True
for csvunit in self.csvfile.units:
#if self.charset is not None:
# csvunit.source = csvunit.source.decode(self.charset)
# csvunit.target = csvunit.target.decode(self.charset)
if mightbeheader:
# ignore typical header strings...
mightbeheader = False
if csvunit.match_header():
continue
if len(csvunit.location.strip()) == 0 and csvunit.source.find("Content-Type:") != -1:
continue
if mergemode:
self.handlecsvunit(csvunit)
else:
pounit = self.convertunit(csvunit)
self.pofile.addunit(pounit)
self.pofile.removeduplicates(self.duplicatestyle)
return self.pofile
开发者ID:cc-archive,项目名称:pootle,代码行数:33,代码来源:csv2po.py
示例18: po2ini
def po2ini(self, posource):
"""helper that converts po source to .ini source without requiring files"""
inputfile = wStringIO.StringIO(posource)
inputpo = po.pofile(inputfile)
convertor = po2ini.reini()
outputini = convertor.convertstore(inputpo)
return outputini
开发者ID:ANKIT-KS,项目名称:fjord,代码行数:7,代码来源:test_po2ini.py
示例19: test_simplegrep_locations
def test_simplegrep_locations(self):
"""grep for a string in the location comments"""
posource = '#: test.c\nmsgid "test"\nmsgstr "rest"\n'
poresult = self.pogrep(posource, "test.c", ["--search=locations"])
assert poresult.index(posource) >= 0
poresult = self.pogrep(posource, "rest.c", ["--search=locations"])
assert headerless_len(po.pofile(poresult).units) == 0
开发者ID:onia,项目名称:translate,代码行数:7,代码来源:test_pogrep.py
示例20: import_file
def import_file(file):
pofile = po.pofile(file.read())
header = pofile.parseheader()
pootle_path = header.get("X-Pootle-Path")
if not pootle_path:
raise ValueError(_("File %r missing X-Pootle-Path header\n") % (file.name))
rev = header.get("X-Pootle-Revision")
if not rev or not rev.isdigit():
raise ValueError(
_("File %r missing or invalid X-Pootle-Revision header\n") % (file.name)
)
rev = int(rev)
try:
store, created = Store.objects.get_or_create(pootle_path=pootle_path)
if rev < store.get_max_unit_revision():
# TODO we could potentially check at the unit level and only reject
# units older than most recent. But that's in store.update().
raise ValueError(
_("File %r was rejected because its X-Pootle-Revision is too old.")
% (file.name)
)
except Exception as e:
raise ValueError(
_("Could not create %r. Missing Project/Language? (%s)")
% (file.name, e)
)
store.update(overwrite=True, store=pofile)
开发者ID:dbbhattacharya,项目名称:pootle,代码行数:30,代码来源:utils.py
注:本文中的translate.storage.po.pofile函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论