本文整理汇总了Python中translate.lang.data.forceunicode函数的典型用法代码示例。如果您正苦于以下问题:Python forceunicode函数的具体用法?Python forceunicode怎么用?Python forceunicode使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了forceunicode函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: format_suggestions
def format_suggestions(self, id, response):
"""clean up open tran suggestion and use the same format as tmserver"""
suggestions = self._loads_safe(response)
if not suggestions:
return []
id = data.forceunicode(id)
self.last_suggestions = suggestions
results = []
for suggestion in suggestions:
#check for fuzzyness at the 'flag' member:
for project in suggestion['projects']:
if project['flags'] == 0:
break
else:
continue
result = {}
result['target'] = data.forceunicode(suggestion['text'])
result['tmsource'] = suggestion['projects'][0]['name']
result['source'] = data.forceunicode(suggestion['projects'][0]['orig_phrase'])
#open-tran often gives too many results with many which can't really be
#considered to be suitable for translation memory
result['quality'] = self.comparer.similarity(id, result['source'], self.min_similarity)
if result['quality'] >= self.min_similarity:
results.append(result)
results.sort(key=lambda match: match['quality'], reverse=True)
results = results[:self.max_candidates]
return results
开发者ID:AndreasEisele,项目名称:wikitrans-pootle,代码行数:27,代码来源:opentranclient.py
示例2: get_xml_text_value
def get_xml_text_value(self, xmltarget):
if (len(xmltarget) == 0):
# There are no html markups, so unescaping it as plain text.
return self.unescape(xmltarget.text)
else:
# There are html markups, so clone it to perform unescaping for all elements.
cloned_target = copy.deepcopy(xmltarget)
# Unescaping texts.
if (cloned_target.text is not None):
cloned_target.text = self.unescape(cloned_target.text)
for xmlelement in cloned_target.iterdescendants():
if (xmlelement.text is not None):
xmlelement.text = self.unescape(xmlelement.text)
if (xmlelement.tail is not None):
xmlelement.tail = self.unescape(xmlelement.tail)
# Grab root text (using a temporary xml element for text escaping)
if (cloned_target.text is not None):
tmp_element = etree.Element('t')
tmp_element.text = cloned_target.text
target = data.forceunicode(etree.tostring(tmp_element, encoding='utf-8')[3:-4])
else:
target = u''
# Include markup as well
target += u''.join([data.forceunicode(etree.tostring(child, encoding='utf-8'))
for child in cloned_target.iterchildren()])
return target
开发者ID:XLeonardo,项目名称:translate-1,代码行数:29,代码来源:aresource.py
示例3: settarget
def settarget(self, text):
# This is a fairly destructive implementation. Don't assume that this
# is necessarily correct in all regards, but it does deal with a lot of
# cases. It is hard to deal with plurals.
#
# Firstly deal with reinitialising to None or setting to identical
# string.
self._rich_target = None
if self.gettarget() == text:
return
strings = []
if isinstance(text, multistring):
strings = text.strings
elif isinstance(text, list):
strings = text
else:
strings = [text]
targetnode = self._gettargetnode()
type = targetnode.get("type")
targetnode.clear()
if type:
targetnode.set("type", type)
if self.hasplural() or len(strings) > 1:
self.xmlelement.set("numerus", "yes")
for string in strings:
numerus = etree.SubElement(targetnode, self.namespaced("numerusform"))
numerus.text = data.forceunicode(string) or ""
# manual, nasty pretty printing. See bug 1420.
numerus.tail = "\n "
else:
targetnode.text = data.forceunicode(text) or ""
targetnode.tail = "\n "
开发者ID:onia,项目名称:translate,代码行数:32,代码来源:ts2.py
示例4: target
def target(self):
targetnode = self._gettargetnode()
if targetnode is None:
etree.SubElement(self.xmlelement, self.namespaced("translation"))
return None
if self.hasplural():
numerus_nodes = targetnode.findall(self.namespaced("numerusform"))
return multistring([data.forceunicode(node.text) or u"" for node in numerus_nodes])
else:
return data.forceunicode(targetnode.text) or u""
开发者ID:diorcety,项目名称:translate,代码行数:10,代码来源:ts2.py
示例5: fixup
def fixup(source, response):
source = data.forceunicode(source)
response = data.forceunicode(response)
from translate.filters.autocorrect import correct
tmp = correct(source, response)
if tmp:
response = tmp
response = response.replace(u" __::__ ", "\n")
# and again for the sake of \n\n:
response = response.replace(u"__::__ ", "\n")
response = response.replace(u"( ", u"(")
for c, repl in punc_tuples:
response = response.replace(repl, c)
return response
开发者ID:Ailick,项目名称:virtaal,代码行数:14,代码来源:mosesclient.py
示例6: setsource
def setsource(self, source):
self._rich_source = None
source = data.forceunicode(source)
if self.personality == "mozilla" or self.personality == "skype":
self.value = quote.mozillapropertiesencode(source or u"")
else:
self.value = quote.javapropertiesencode(source or u"")
开发者ID:lehmannro,项目名称:translate,代码行数:7,代码来源:properties.py
示例7: settarget
def settarget(self, target):
self._rich_target = None
target = data.forceunicode(target)
if self.personality == "mozilla" or self.personality == "skype":
self.translation = quote.mozillapropertiesencode(target or u"")
else:
self.translation = quote.javapropertiesencode(target or u"")
开发者ID:lehmannro,项目名称:translate,代码行数:7,代码来源:properties.py
示例8: addnote
def addnote(self, text, origin=None, position="append"):
if origin in ['programmer', 'developer', 'source code', None]:
text = data.forceunicode(text)
self.comments.append(text)
else:
return super(propunit, self).addnote(text, origin=origin,
position=position)
开发者ID:andynicholson,项目名称:translate,代码行数:7,代码来源:properties.py
示例9: addnote
def addnote(self, text, origin=None, position="append"):
"""This is modeled on the XLIFF method.
See :meth:`translate.storage.xliff.xliffunit.addnote`
"""
# ignore empty strings and strings without non-space characters
if not (text and text.strip()):
return
text = data.forceunicode(text)
commentlist = self.othercomments
linestart = "# "
autocomments = False
if origin in ["programmer", "developer", "source code"]:
autocomments = True
commentlist = self.automaticcomments
linestart = "#. "
text = text.split("\n")
newcomments = [linestart + line + "\n" for line in text]
if position == "append":
newcomments = commentlist + newcomments
elif position == "prepend":
newcomments = newcomments + commentlist
if autocomments:
self.automaticcomments = newcomments
else:
self.othercomments = newcomments
开发者ID:hansvanvelzen,项目名称:translate,代码行数:27,代码来源:pypo.py
示例10: settarget
def settarget(self, text, lang='xx', append=False):
"""Sets the "target" string (second language), or alternatively
appends to the list"""
#XXX: we really need the language - can't really be optional, and we
# need to propagate it
if self._rich_target is not None:
self._rich_target = None
text = data.forceunicode(text)
# Firstly deal with reinitialising to None or setting to identical
# string
if self.gettarget() == text:
return
languageNode = self.get_target_dom(None)
if not text is None:
if languageNode is None:
languageNode = self.createlanguageNode(lang, text, "target")
self.set_target_dom(languageNode, append)
else:
'''
if self.textNode:
terms = languageNode.iter(self.namespaced(self.textNode))
try:
languageNode = next(terms)
except StopIteration as e:
pass
languageNode.text = text
'''
# try to update all content including tags in targt node,
# but here only suits/tested for iws files, so need more checks.
# later could need to use a more better method to update target node.
self.xmlelement.remove(languageNode)
languageNode = self.createlanguageNode(lang, text, "target")
self.set_target_dom(languageNode, append)
else:
self.set_target_dom(None, False)
开发者ID:onia,项目名称:translate,代码行数:35,代码来源:lisa.py
示例11: getsource
def getsource(self):
# TODO: support <byte>. See bug 528.
sourcenode = self._getsourcenode()
if self.hasplural():
return multistring([sourcenode.text])
else:
return data.forceunicode(sourcenode.text)
开发者ID:onia,项目名称:translate,代码行数:7,代码来源:ts2.py
示例12: settarget
def settarget(self, text, lang='xx', append=False):
"""Sets the "target" string (second language), or alternatively
appends to the list"""
#XXX: we really need the language - can't really be optional, and we
# need to propagate it
if self._rich_target is not None:
self._rich_target = None
text = data.forceunicode(text)
# Firstly deal with reinitialising to None or setting to identical
# string
if self.gettarget() == text:
return
languageNode = self.get_target_dom(None)
if not text is None:
if languageNode is None:
languageNode = self.createlanguageNode(lang, text, "target")
self.set_target_dom(languageNode, append)
else:
if self.textNode:
terms = languageNode.iter(self.namespaced(self.textNode))
try:
languageNode = terms.next()
except StopIteration, e:
pass
languageNode.text = text
开发者ID:cc-archive,项目名称:pootle,代码行数:25,代码来源:lisa.py
示例13: gettarget
def gettarget(self, lang=None):
# Grab inner text
target = self.unescape(self.xmlelement.text or u"")
# Include markup as well
target += u"".join(
[data.forceunicode(etree.tostring(child, encoding="utf-8")) for child in self.xmlelement.iterchildren()]
)
return target
开发者ID:spc-12,项目名称:weblate,代码行数:8,代码来源:aresource.py
示例14: target
def target(self, target):
# Firstly deal with reinitialising to None or setting to identical
# string.
self._rich_target = None
if self.target == target:
return
targetnode = self._gettargetnode()
targetnode.clear()
targetnode.text = data.forceunicode(target) or u""
开发者ID:diorcety,项目名称:translate,代码行数:9,代码来源:resx.py
示例15: select_match
def select_match(self, match_data):
"""Handle a match-selection event.
(This method is used as View-Controller communications)"""
unit_controller = self.main_controller.unit_controller
target_n = unit_controller.view.focused_target_n
old_text = unit_controller.view.get_target_n(target_n)
textbox = unit_controller.view.targets[target_n]
self.main_controller.undo_controller.push_current_text(textbox)
unit_controller.set_unit_target(target_n, forceunicode(match_data['target']))
开发者ID:AndreasEisele,项目名称:wikitrans-pootle,代码行数:9,代码来源:tmcontroller.py
示例16: source
def source(self, source):
self._rich_source = None
source = data.forceunicode(source or u"")
source = source or u""
if isinstance(source, multistring):
self._source = source
elif isinstance(source, six.text_type):
self._source = source
else: # If it is unicode, list or dict.
self._source = multistring(source)
开发者ID:diorcety,项目名称:translate,代码行数:10,代码来源:fpo.py
示例17: addlocation
def addlocation(self, location):
"""Add a location to sourcecomments in the PO unit
:param location: Text location e.g. 'file.c:23' does not include #:
:type location: String
"""
location = data.forceunicode(location)
location = pocommon.quote_plus(location)
self.sourcecomments.append("#: %s\n" % location)
开发者ID:diorcety,项目名称:translate,代码行数:10,代码来源:pypo.py
示例18: _on_insert_text
def _on_insert_text(self, buffer, iter, ins_text, length):
if self.elem is None:
return
ins_text = data.forceunicode(ins_text[:length])
buff_offset = iter.get_offset()
gui_info = self.elem.gui_info
left = gui_info.elem_at_offset(buff_offset-1)
right = gui_info.elem_at_offset(buff_offset)
#logging.debug('"%s[[%s]]%s" | elem=%s[%d] | left=%s right=%s' % (
# buffer.get_text(buffer.get_start_iter(), iter),
# ins_text,
# buffer.get_text(iter, buffer.get_end_iter()),
# repr(self.elem), buff_offset,
# repr(left), repr(right)
#))
succeeded = False
if not (left is None and right is None) and (left is not right or not unicode(left)):
succeeded = self.elem.insert_between(left, right, ins_text)
#logging.debug('self.elem.insert_between(%s, %s, "%s"): %s' % (repr(left), repr(right), ins_text, succeeded))
if not succeeded and left is not None and left is right and left.isleaf():
# This block handles the special case where a the cursor is just
# inside a leaf element with a closing widget. In this case both
# left and right will point to the element in question, but it
# need not be empty to be a leaf. Because the cursor is still
# "inside" the element, we want to append to this leaf in stead
# of after it, which is what StringElem.insert() will do, seeing
# as the position before and after the widget is the same to in
# the context of StringElem.
anchor = iter.get_child_anchor()
if anchor:
widgets = anchor.get_widgets()
left_widgets = left.gui_info.widgets
if len(widgets) > 0 and len(left_widgets) > 1 and \
widgets[0] is left_widgets[1] and \
iter.get_offset() == self.elem.gui_info.length() - 1:
succeeded = left.insert(len(left), ins_text)
#logging.debug('%s.insert(len(%s), "%s")' % (repr(left), repr(left), ins_text))
if not succeeded:
offset = gui_info.gui_to_tree_index(buff_offset)
succeeded = self.elem.insert(offset, ins_text)
#logging.debug('self.elem.insert(%d, "%s"): %s' % (offset, ins_text, succeeded))
if succeeded:
self.elem.prune()
cursor_pos = self.refresh_cursor_pos
if cursor_pos < 0:
cursor_pos = self.buffer.props.cursor_position
cursor_pos += len(ins_text)
self.refresh_cursor_pos = cursor_pos
#logging.debug('text-inserted: %[email protected]%d of %s' % (ins_text, iter.get_offset(), repr(self.elem)))
self.emit('text-inserted', ins_text, buff_offset, self.elem)
开发者ID:martinproject,项目名称:virtaal,代码行数:54,代码来源:textbox.py
示例19: get_text
def get_text(self, start_iter=None, end_iter=None):
"""Return the text rendered in this text box.
Uses C{gtk.TextBuffer.get_text()}."""
if isinstance(start_iter, int):
start_iter = self.buffer.get_iter_at_offset(start_iter)
if isinstance(end_iter, int):
end_iter = self.buffer.get_iter_at_offset(end_iter)
if start_iter is None:
start_iter = self.buffer.get_start_iter()
if end_iter is None:
end_iter = self.buffer.get_end_iter()
return data.forceunicode(self.buffer.get_text(start_iter, end_iter))
开发者ID:martinproject,项目名称:virtaal,代码行数:12,代码来源:textbox.py
示例20: setsource
def setsource(self, source):
self._rich_source = None
# assert isinstance(source, unicode)
source = data.forceunicode(source or u"")
source = source or u""
if isinstance(source, multistring):
self._source = source
elif isinstance(source, unicode):
self._source = source
else:
#unicode, list, dict
self._source = multistring(source)
开发者ID:cc-archive,项目名称:pootle,代码行数:12,代码来源:fpo.py
注:本文中的translate.lang.data.forceunicode函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论