• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Python factory.getlanguage函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中translate.lang.factory.getlanguage函数的典型用法代码示例。如果您正苦于以下问题:Python getlanguage函数的具体用法?Python getlanguage怎么用?Python getlanguage使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了getlanguage函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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
开发者ID:XLeonardo,项目名称:translate-1,代码行数:9,代码来源:test_posegment.py


示例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
开发者ID:XLeonardo,项目名称:translate-1,代码行数:12,代码来源:posegment.py


示例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”"
开发者ID:Jobava,项目名称:translate-toolkit,代码行数:32,代码来源:test_ro.py


示例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"
开发者ID:Veterini,项目名称:translate,代码行数:7,代码来源:test_th.py


示例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ı."]
开发者ID:Veterini,项目名称:translate,代码行数:7,代码来源:test_tr.py


示例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
开发者ID:niragInes,项目名称:pootle,代码行数:29,代码来源:initdb.py


示例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»"
开发者ID:onia,项目名称:translate,代码行数:29,代码来源:test_fr.py


示例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
开发者ID:adamchainz,项目名称:virtaal,代码行数:32,代码来源:localfileview.py


示例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)
开发者ID:GursharnjitSingh,项目名称:virtaal,代码行数:31,代码来源:storecellrenderer.py


示例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»"
开发者ID:onia,项目名称:translate,代码行数:27,代码来源:test_fa.py


示例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"Ел. пошта"]
开发者ID:Veterini,项目名称:translate,代码行数:7,代码来源:test_uk.py


示例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 = {}
开发者ID:XLeonardo,项目名称:translate-1,代码行数:7,代码来源:statistics.py


示例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"現在會寄一封信給已登記的電郵地址。"]
开发者ID:AlexArgus,项目名称:affiliates-lib,代码行数:8,代码来源:test_zh.py


示例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..."
开发者ID:ANKIT-KS,项目名称:fjord,代码行数:8,代码来源:test_or.py


示例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!"
开发者ID:onia,项目名称:translate,代码行数:8,代码来源:test_el.py


示例16: test_getlanguage

def test_getlanguage():
    """Tests that a basic call to getlanguage() works."""
    kmlanguage = factory.getlanguage('km')
    assert kmlanguage.code == 'km'
    assert kmlanguage.fullname == 'Central Khmer'
    
    # Test a non-exisint code
    language = factory.getlanguage('zz')
    assert language.nplurals == 0

    # Test a code without a module
    language = factory.getlanguage('fy')
    assert language.nplurals == 2
    assert language.fullname == "Frisian"
    assert "n != 1" in language.pluralequation 

    # Test a code without a module and with a country code
    language = factory.getlanguage('de_AT')
    assert language.nplurals == 2
    assert language.fullname == "German"

    # Test with None as language code
    language = factory.getlanguage(None)
    assert language.code == ''

    #Test with a language code that is a reserved word in Python
    language = factory.getlanguage('is')
    assert language.nplurals == 2

    #Test with a language code contains '@'
    language = factory.getlanguage('[email protected]')
    assert language.nplurals == 2
开发者ID:AlexArgus,项目名称:affiliates-lib,代码行数:32,代码来源:test_factory.py


示例17: test_sentences

def test_sentences():
    """Tests basic functionality of sentence segmentation."""
    language = factory.getlanguage('am')
    sentences = language.sentences(u"")
    assert sentences == []

    sentences = language.sentences(u"ለምልክቱ መግቢያ የተለየ መለያ። ይህ የሚጠቅመው የታሪኩን ዝርዝር ለማስቀመጥ ነው።")
    print sentences
    assert sentences == [u"ለምልክቱ መግቢያ የተለየ መለያ።", u"ይህ የሚጠቅመው የታሪኩን ዝርዝር ለማስቀመጥ ነው።"]
开发者ID:ANKIT-KS,项目名称:fjord,代码行数:9,代码来源:test_am.py


示例18: test_punctranslate

def test_punctranslate():
    """Tests that we can translate punctuation."""
    language = factory.getlanguage('ne')
    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...") == u"abc efg..."
    assert language.punctranslate(u"abc efg?") == u"abc efg ?"
开发者ID:Veterini,项目名称:translate,代码行数:9,代码来源:test_ne.py


示例19: project_checker

def project_checker(project_style, source_lang):
    if project_style:
        from translate.filters.checks import projectcheckers
        checker = projectcheckers.get(project_style, None)
        if checker:
            checker = checker()
            from translate.lang import factory
            checker.config.sourcelang = factory.getlanguage(source_lang)
            return checker
开发者ID:viperfx,项目名称:GSOC,代码行数:9,代码来源:tmdb.py


示例20: test_sentences

def test_sentences():
    """Tests basic functionality of sentence segmentation."""
    language = factory.getlanguage('af')
    sentences = language.sentences(u"Normal case. Nothing interesting.")
    assert sentences == [u"Normal case.", "Nothing interesting."]
    sentences = language.sentences(u"Wat? 'n Fout?")
    assert sentences == [u"Wat?", "'n Fout?"]
    sentences = language.sentences(u"Dit sal a.g.v. 'n fout gebeur.")
    assert sentences == [u"Dit sal a.g.v. 'n fout gebeur."]
开发者ID:AlexArgus,项目名称:affiliates-lib,代码行数:9,代码来源:test_af.py



注:本文中的translate.lang.factory.getlanguage函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python multistring.multistring函数代码示例发布时间:2022-05-27
下一篇:
Python data.simplify_to_common函数代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap