本文整理汇总了Python中translate.lang.factory.getlanguage函数的典型用法代码示例。如果您正苦于以下问题:Python getlanguage函数的具体用法?Python getlanguage怎么用?Python getlanguage使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了getlanguage函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: posegment
def posegment(self, posource, sourcelanguage, targetlanguage, stripspaces=True, onlyaligned=True):
"""helper that convert po source without requiring files"""
inputfile = wStringIO.StringIO(posource)
inputpo = po.pofile(inputfile)
sourcelang = lang_factory.getlanguage(sourcelanguage)
targetlang = lang_factory.getlanguage(targetlanguage)
convertor = posegment.segment(sourcelang, targetlang, stripspaces=stripspaces, onlyaligned=onlyaligned)
outputpo = convertor.convertstore(inputpo)
return outputpo
示例2: segmentfile
def segmentfile(inputfile, outputfile, templatefile, sourcelanguage="en", targetlanguage=None, stripspaces=True, onlyaligned=False):
"""reads in inputfile, segments it then, writes to outputfile"""
# note that templatefile is not used, but it is required by the converter...
inputstore = factory.getobject(inputfile)
if inputstore.isempty():
return 0
sourcelang = lang_factory.getlanguage(sourcelanguage)
targetlang = lang_factory.getlanguage(targetlanguage)
convertor = segment(sourcelang, targetlang, stripspaces=stripspaces, onlyaligned=onlyaligned)
outputstore = convertor.convertstore(inputstore)
outputstore.serialize(outputfile)
return 1
示例3: test_punctranslate
def test_punctranslate():
"""Tests that we can translate punctuation."""
language = factory.getlanguage('ro')
assert language.punctranslate(u"") == u""
assert language.punctranslate(u"abc efg") == u"abc efg"
assert language.punctranslate(u"abc efg.") == u"abc efg."
assert language.punctranslate(u"abc efg!") == u"abc efg!"
assert language.punctranslate(u"abc efg? hij!") == u"abc efg? hij!"
assert language.punctranslate(u"Delete file: %s?") == u"Delete file: %s?"
assert language.punctranslate(u'"root" is powerful') == u"„root” is powerful"
assert language.punctranslate(u"'root' is powerful") == u"„root” is powerful"
assert language.punctranslate(u"`root' is powerful") == u"„root” is powerful"
assert language.punctranslate(u"‘root’ is powerful") == u"„root” is powerful"
assert language.punctranslate(u"“root” is powerful") == u"„root” is powerful"
assert language.punctranslate(u'The user "root"') == u"The user „root”"
assert language.punctranslate(u"The user 'root'") == u"The user „root”"
assert language.punctranslate(u"The user `root'") == u"The user „root”"
assert language.punctranslate(u'The user "root"?') == u"The user „root»?"
assert language.punctranslate(u"The user 'root'?") == u"The user „root”?"
assert language.punctranslate(u"The user `root'?") == u"The user „root”?"
assert language.punctranslate(u"The user ‘root’?") == u"The user „root”?"
assert language.punctranslate(u"The user “root”?") == u"The user „root”?"
assert language.punctranslate(u'Watch the " mark') == u'Watch the " mark'
assert language.punctranslate(u"Watch the ' mark") == u"Watch the ' mark"
assert language.punctranslate(u"Watch the ` mark") == u"Watch the ` mark"
assert language.punctranslate(u'Watch the “mark”') == u"Watch the „mark”"
assert language.punctranslate(u'The <a href="info">user</a> "root"?') == u'The <a href="info">user</a> „root”?'
assert language.punctranslate(u"The <a href='info'>user</a> 'root'?") == u"The <a href='info'>user</a> „root”?"
assert language.punctranslate(u"The <a href='info'>user</a> ‘root’?") == u"The <a href='info'>user</a> „root”?"
assert language.punctranslate(u"The <a href='info'>user</a> “root”?") == u"The <a href='info'>user</a> „root”?"
assert language.punctranslate(u"The <a href='http://koeie'>user</a>") == u"The <a href='http://koeie'>user</a>"
assert language.punctranslate(u"Copying `%s' to `%s'") == u"Copying „%s” to „%s”"
示例4: test_punctranslate
def test_punctranslate():
"""Tests that we can translate punctuation."""
language = factory.getlanguage('th')
assert language.punctranslate(u"") == u""
assert language.punctranslate(u"abc efg") == u"abc efg"
assert language.punctranslate(u"abc efg.") == u"abc efg"
assert language.punctranslate(u"abc efg. hij") == u"abc efg hij"
示例5: test_sentences
def test_sentences():
"""Tests basic functionality of sentence segmentation."""
language = factory.getlanguage('tr')
sentences = language.sentences(u"Normal case. Nothing interesting.")
assert sentences == [u"Normal case.", u"Nothing interesting."]
sentences = language.sentences(u"1. sayı, 2. sayı.")
assert sentences == [u"1. sayı, 2. sayı."]
示例6: create_default_languages
def create_default_languages():
"""Create the default languages.
We afford this privilege to languages with reasonably complete interface
translations for Pootle.
"""
from translate.lang import data, factory
from pootle_language.models import Language
default_languages = ("af", "ak", "ht", "nso", "ve", "wo", "zh_cn", "zh_hk",
"zh_tw", "ca_valencia", "son", "lg", "gd")
# import languages from toolkit
for code in data.languages.keys():
try:
tk_lang = factory.getlanguage(code)
criteria = {
'code': code,
'fullname': tk_lang.fullname,
'nplurals': tk_lang.nplurals,
'pluralequation': tk_lang.pluralequation,
'specialchars': tk_lang.specialchars,
}
lang, created = Language.objects.get_or_create(**criteria)
if code in default_languages:
lang.save()
except:
pass
示例7: test_punctranslate
def test_punctranslate():
"""Tests that we can translate punctuation."""
language = factory.getlanguage('fr')
assert language.punctranslate("") == ""
assert language.punctranslate("abc efg") == "abc efg"
assert language.punctranslate("abc efg.") == "abc efg."
assert language.punctranslate("abc efg!") == "abc efg\u00a0!"
assert language.punctranslate("abc efg? hij!") == "abc efg\u00a0? hij\u00a0!"
assert language.punctranslate("Delete file: %s?") == "Delete file\u00a0: %s\u00a0?"
assert language.punctranslate('"root" is powerful') == "«\u00a0root\u00a0» is powerful"
assert language.punctranslate("'root' is powerful") == "«\u00a0root\u00a0» is powerful"
assert language.punctranslate("`root' is powerful") == "«\u00a0root\u00a0» is powerful"
assert language.punctranslate('The user "root"') == "The user «\u00a0root\u00a0»"
assert language.punctranslate("The user 'root'") == "The user «\u00a0root\u00a0»"
assert language.punctranslate("The user `root'") == "The user «\u00a0root\u00a0»"
assert language.punctranslate('The user "root"?') == "The user «\u00a0root\u00a0»\u00a0?"
assert language.punctranslate("The user 'root'?") == "The user «\u00a0root\u00a0»\u00a0?"
assert language.punctranslate("The user `root'?") == "The user «\u00a0root\u00a0»\u00a0?"
assert language.punctranslate('Watch the " mark') == 'Watch the " mark'
assert language.punctranslate("Watch the ' mark") == "Watch the ' mark"
assert language.punctranslate("Watch the ` mark") == "Watch the ` mark"
assert language.punctranslate('Watch the “mark”') == "Watch the «\u00a0mark\u00a0»"
assert language.punctranslate('The <a href="info">user</a> "root"?') == 'The <a href="info">user</a> «\u00a0root\u00a0»\u00a0?'
assert language.punctranslate("The <a href='info'>user</a> 'root'?") == "The <a href='info'>user</a> «\u00a0root\u00a0»\u00a0?"
#Broken because we test for equal number of ` and ' in the string
#assert language.punctranslate(u"The <a href='info'>user</a> `root'?") == u"The <a href='info'>user</a> «\u00a0root\u00a0»\u00a0?"
assert language.punctranslate("The <a href='http://koeie'>user</a>") == "The <a href='http://koeie'>user</a>"
assert language.punctranslate("Copying `%s' to `%s'") == "Copying «\u00a0%s\u00a0» to «\u00a0%s\u00a0»"
示例8: _on_entry_changed
def _on_entry_changed(self, entry):
self.btn_add_term.props.sensitive = True
self.eb_add_term_errors.hide()
src_text = self.ent_source.get_text()
tgt_text = self.ent_target.get_text()
dup = self.term_model.get_duplicates(src_text, tgt_text)
if dup:
self.lbl_add_term_errors.set_text(_('Identical entry already exists.'))
self.eb_add_term_errors.modify_bg(gtk.STATE_NORMAL, gdk.color_parse(current_theme['warning_bg']))
self.eb_add_term_errors.show_all()
self.btn_add_term.props.sensitive = False
return
same_src_units = self.term_model.get_units_with_source(src_text)
if src_text and same_src_units:
# We want to separate multiple terms with the correct list
# separator for the UI language:
from translate.lang import factory as lang_factory
from virtaal.common.pan_app import ui_language
separator = lang_factory.getlanguage(ui_language).listseperator
#l10n: The variable is an existing term formatted for emphasis. The default is bold formatting, but you can remove/change the markup if needed. Leave it unchanged if you are unsure.
translations = separator.join([_('<b>%s</b>') % (u.target) for u in same_src_units])
errormsg = _('Existing translations: %(translations)s') % {
'translations': translations
}
self.lbl_add_term_errors.set_markup(errormsg)
self.eb_add_term_errors.modify_bg(gtk.STATE_NORMAL, gdk.color_parse(current_theme['warning_bg']))
self.eb_add_term_errors.show_all()
return
示例9: gtk_textview_compute_optimal_height
def gtk_textview_compute_optimal_height(widget, width):
if not widget.props.visible:
return
buf = widget.get_buffer()
# For border calculations, see gtktextview.c:gtk_text_view_size_request in the GTK source
border = 2 * widget.border_width - 2 * widget.parent.border_width
if widget.style_get_property("interior-focus"):
border += 2 * widget.style_get_property("focus-line-width")
buftext = buf.get_text(buf.get_start_iter(), buf.get_end_iter())
# A good way to test height estimation is to use it for all units and
# compare the reserved space to the actual space needed to display a unit.
# To use height estimation for all units (not just empty units), use:
# if True:
if not buftext:
text = getattr(widget, "_source_text", u"")
if text:
lang = factory.getlanguage(pan_app.settings.language["targetlang"])
buftext = lang.alter_length(text)
buftext = markup.escape(buftext)
_w, h = rendering.make_pango_layout(widget, buftext, width - border).get_pixel_size()
if h == 0:
# No idea why this bug happens, but it often happens for the first unit
# directly after the file is opened. For now we try to guess a more
# useful default than 0. This should look much better than 0, at least.
h = 28
parent = widget.parent
if isinstance(parent, gtk.ScrolledWindow) and parent.get_shadow_type() != gtk.SHADOW_NONE:
border += 2 * parent.rc_get_style().ythickness
widget.parent.set_size_request(-1, h + border)
示例10: test_punctranslate
def test_punctranslate():
"""Tests that we can translate punctuation."""
language = factory.getlanguage('fa')
assert language.punctranslate("") == ""
assert language.punctranslate("abc efg") == "abc efg"
assert language.punctranslate("abc efg.") == "abc efg."
assert language.punctranslate("Delete file: %s?") == "Delete file: %s؟"
assert language.punctranslate('"root" is powerful') == "«root» is powerful"
assert language.punctranslate("'root' is powerful") == "«root» is powerful"
assert language.punctranslate("`root' is powerful") == "«root» is powerful"
assert language.punctranslate('The user "root"') == "The user «root»"
assert language.punctranslate("The user 'root'") == "The user «root»"
assert language.punctranslate("The user `root'") == "The user «root»"
assert language.punctranslate('The user "root"?') == "The user «root»؟"
assert language.punctranslate("The user 'root'?") == "The user «root»؟"
assert language.punctranslate("The user `root'?") == "The user «root»؟"
assert language.punctranslate('Watch the " mark') == 'Watch the " mark'
assert language.punctranslate("Watch the ' mark") == "Watch the ' mark"
assert language.punctranslate("Watch the ` mark") == "Watch the ` mark"
assert language.punctranslate('Watch the “mark”') == "Watch the «mark»"
assert language.punctranslate('The <a href="info">user</a> "root"?') == 'The <a href="info">user</a> «root»؟'
assert language.punctranslate("The <a href='info'>user</a> 'root'?") == "The <a href='info'>user</a> «root»؟"
#Broken because we test for equal number of ` and ' in the string
#assert language.punctranslate(u"The <a href='info'>user</a> `root'?") == u"The <a href='info'>user</a> «root»؟"
assert language.punctranslate("The <a href='http://koeie'>user</a>") == "The <a href='http://koeie'>user</a>"
assert language.punctranslate("Copying `%s' to `%s'") == "Copying «%s» to «%s»"
示例11: test_sentences
def test_sentences():
"""Tests basic functionality of sentence segmentation."""
language = factory.getlanguage('uk')
sentences = language.sentences(u"")
assert sentences == []
sentences = language.sentences(u"Ел. пошта")
assert sentences == [u"Ел. пошта"]
示例12: __init__
def __init__(self, sourcelanguage='en', targetlanguage='en', checkerstyle=None):
self.sourcelanguage = sourcelanguage
self.targetlanguage = targetlanguage
self.language = factory.getlanguage(self.sourcelanguage)
# self.init_checker(checkerstyle)
self.classification = {}
示例13: test_sentences
def test_sentences():
"""Tests basic functionality of sentence segmentation."""
language = factory.getlanguage('zh')
sentences = language.sentences(u"")
assert sentences == []
sentences = language.sentences(u"這個用戶名稱已經存在。現在會寄一封信給已登記的電郵地址。\n")
assert sentences == [u"這個用戶名稱已經存在。", u"現在會寄一封信給已登記的電郵地址。"]
示例14: test_punctranslate
def test_punctranslate():
"""Tests that we can translate punctuation."""
language = factory.getlanguage('or')
assert language.punctranslate(u"") == u""
assert language.punctranslate(u"Document loaded") == u"Document loaded"
assert language.punctranslate(u"Document loaded.") == u"Document loaded।"
assert language.punctranslate(u"Document loaded.\n") == u"Document loaded।\n"
assert language.punctranslate(u"Document loaded...") == u"Document loaded..."
示例15: test_punctranslate
def test_punctranslate():
"""Tests that we can translate punctuation."""
language = factory.getlanguage('el')
assert language.punctranslate("") == ""
assert language.punctranslate("abc efg") == "abc efg"
assert language.punctranslate("abc efg. hij.") == "abc efg. hij."
assert language.punctranslate("abc efg;") == "abc efg·"
assert language.punctranslate("abc efg? hij!") == "abc efg; hij!"