当前位置: 首页>>代码示例>>Python>>正文


Python gettext.GNUTranslations方法代码示例

本文整理汇总了Python中gettext.GNUTranslations方法的典型用法代码示例。如果您正苦于以下问题:Python gettext.GNUTranslations方法的具体用法?Python gettext.GNUTranslations怎么用?Python gettext.GNUTranslations使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在gettext的用法示例。


在下文中一共展示了gettext.GNUTranslations方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: _new_gnu_trans

# 需要导入模块: import gettext [as 别名]
# 或者: from gettext import GNUTranslations [as 别名]
def _new_gnu_trans(self, localedir, use_null_fallback=True):
        """
        Returns a mergeable gettext.GNUTranslations instance.

        A convenience wrapper. By default gettext uses 'fallback=False'.
        Using param `use_null_fallback` to avoid confusion with any other
        references to 'fallback'.
        """
        translation = gettext_module.translation(
            domain='django',
            localedir=localedir,
            languages=[self.__locale],
            codeset='utf-8',
            fallback=use_null_fallback)
        if not hasattr(translation, '_catalog'):
            # provides merge support for NullTranslations()
            translation._catalog = {}
            translation._info = {}
            translation.plural = lambda n: int(n != 1)
        return translation 
开发者ID:lanbing510,项目名称:GTDWeb,代码行数:22,代码来源:trans_real.py

示例2: test_the_alternative_interface

# 需要导入模块: import gettext [as 别名]
# 或者: from gettext import GNUTranslations [as 别名]
def test_the_alternative_interface(self):
        eq = self.assertEqual
        # test the alternative interface
        with open(self.mofile, 'rb') as fp:
            t = gettext.GNUTranslations(fp)
        # Install the translation object
        t.install()
        eq(_('nudge nudge'), 'wink wink')
        # Try unicode return type
        t.install(unicode=True)
        eq(_('mullusk'), 'bacon')
        # Test installation of other methods
        import __builtin__
        t.install(unicode=True, names=["gettext", "lgettext"])
        eq(_, t.ugettext)
        eq(__builtin__.gettext, t.ugettext)
        eq(lgettext, t.lgettext)
        del __builtin__.gettext
        del __builtin__.lgettext 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:21,代码来源:test_gettext.py

示例3: ngettext

# 需要导入模块: import gettext [as 别名]
# 或者: from gettext import GNUTranslations [as 别名]
def ngettext(self, singular, plural, num):
        """
        The translation of singular/plural is returned unless the translation is
        not available and the singular contains the separator. In that case,
        the returned value is the singular.

        :param singular: The singular form of the string to be translated.
                         may contain a context seperator
        :type singular: unicode
        :param plural: The plural form of the string to be translated.
        :type plural: unicode
        :param num: the amount for which to decide the translation
        :type num: int
        :returns: Translation or the original.
        :rtype: unicode
        """
        return gettext.GNUTranslations.ngettext(self, singular, plural, num) 
开发者ID:GenealogyCollective,项目名称:gprime,代码行数:19,代码来源:locale.py

示例4: __init__

# 需要导入模块: import gettext [as 别名]
# 或者: from gettext import GNUTranslations [as 别名]
def __init__(self, courseid, content_description, course_fs, task_factory, hook_manager):
        """
        :param courseid: the course id
        :param content_description: a dict with all the infos of this course
        :param task_factory: a function with one argument, the task id, that returns a Task object
        """
        self._id = courseid
        self._content = content_description
        self._fs = course_fs
        self._task_factory = task_factory
        self._hook_manager = hook_manager

        self._translations = {}
        translations_fs = self._fs.from_subfolder("$i18n")
        if translations_fs.exists():
            for f in translations_fs.list(folders=False, files=True, recursive=False):
                lang = f[0:len(f) - 3]
                if translations_fs.exists(lang + ".mo"):
                    self._translations[lang] = gettext.GNUTranslations(translations_fs.get_fd(lang + ".mo"))
                else:
                    self._translations[lang] = gettext.NullTranslations() 
开发者ID:UCL-INGI,项目名称:INGInious,代码行数:23,代码来源:courses.py

示例5: test_the_alternative_interface

# 需要导入模块: import gettext [as 别名]
# 或者: from gettext import GNUTranslations [as 别名]
def test_the_alternative_interface(self):
        eq = self.assertEqual
        # test the alternative interface
        with open(self.mofile, 'rb') as fp:
            t = gettext.GNUTranslations(fp)
        # Install the translation object
        t.install()
        eq(_('nudge nudge'), 'wink wink')
        # Try unicode return type
        t.install()
        eq(_('mullusk'), 'bacon')
        # Test installation of other methods
        import builtins
        t.install(names=["gettext", "lgettext"])
        eq(_, t.gettext)
        eq(builtins.gettext, t.gettext)
        eq(lgettext, t.lgettext)
        del builtins.gettext
        del builtins.lgettext 
开发者ID:Microvellum,项目名称:Fluid-Designer,代码行数:21,代码来源:test_gettext.py

示例6: init_localization

# 需要导入模块: import gettext [as 别名]
# 或者: from gettext import GNUTranslations [as 别名]
def init_localization(script_directory, language):
    if not language:
        if sys.platform.lower().startswith("darwin") and os.system("defaults read -g AppleLanguages > /tmp/languages.txt") == 0:
            language = re.search("\W*(\w+)", read_contents("/tmp/languages.txt")).group(1)
        else:
            try:
                language = locale.getdefaultlocale()[0][:2]
            except:
                language = "en"
    try:
        with open("%s/res/messages_%s.mo" % (script_directory, language), "rb") as mo_contents:
            trans = gettext.GNUTranslations(mo_contents)
    except IOError:
        trans = gettext.NullTranslations()
    
    if sys.version_info.major == 2:
        trans.install(unicode=True)
    else:
        trans.install()
    return language 
开发者ID:laowantong,项目名称:mocodo,代码行数:22,代码来源:argument_parser.py

示例7: test_the_alternative_interface

# 需要导入模块: import gettext [as 别名]
# 或者: from gettext import GNUTranslations [as 别名]
def test_the_alternative_interface(self):
        eq = self.assertEqual
        # test the alternative interface
        fp = open(self.mofile, 'rb')
        t = gettext.GNUTranslations(fp)
        fp.close()
        # Install the translation object
        t.install()
        eq(_('nudge nudge'), 'wink wink')
        # Try unicode return type
        t.install(unicode=True)
        eq(_('mullusk'), 'bacon')
        # Test installation of other methods
        import __builtin__
        t.install(unicode=True, names=["gettext", "lgettext"])
        eq(_, t.ugettext)
        eq(__builtin__.gettext, t.ugettext)
        eq(lgettext, t.lgettext)
        del __builtin__.gettext
        del __builtin__.lgettext 
开发者ID:ofermend,项目名称:medicare-demo,代码行数:22,代码来源:test_gettext.py

示例8: get_builtin_gnu_translations

# 需要导入模块: import gettext [as 别名]
# 或者: from gettext import GNUTranslations [as 别名]
def get_builtin_gnu_translations(languages=None):
    """
    Get a gettext.GNUTranslations object pointing at the
    included translation files.

    :param languages:
        A list of languages to try, in order. If omitted or None, then
        gettext will try to use locale information from the environment.
    """
    import gettext
    return gettext.translation('wtforms', messages_path(), languages) 
开发者ID:jpush,项目名称:jbox,代码行数:13,代码来源:i18n.py

示例9: __init__

# 需要导入模块: import gettext [as 别名]
# 或者: from gettext import GNUTranslations [as 别名]
def __init__(self, language):
        """Create a GNUTranslations() using many locale directories"""
        gettext_module.GNUTranslations.__init__(self)

        self.__language = language
        self.__to_language = to_language(language)
        self.__locale = to_locale(language)

        self._init_translation_catalog()
        self._add_installed_apps_translations()
        self._add_local_translations()
        self._add_fallback() 
开发者ID:lanbing510,项目名称:GTDWeb,代码行数:14,代码来源:trans_real.py

示例10: _add_fallback

# 需要导入模块: import gettext [as 别名]
# 或者: from gettext import GNUTranslations [as 别名]
def _add_fallback(self):
        """Sets the GNUTranslations() fallback with the default language."""
        # Don't set a fallback for the default language or any English variant
        # (as it's empty, so it'll ALWAYS fall back to the default language)
        if self.__language == settings.LANGUAGE_CODE or self.__language.startswith('en'):
            return
        default_translation = translation(settings.LANGUAGE_CODE)
        self.add_fallback(default_translation) 
开发者ID:lanbing510,项目名称:GTDWeb,代码行数:10,代码来源:trans_real.py

示例11: test_usability

# 需要导入模块: import gettext [as 别名]
# 或者: from gettext import GNUTranslations [as 别名]
def test_usability(pofile):
    # Use polib to write a mofile
    with tempfile.NamedTemporaryFile(mode="w+b") as mofile:
        pofile = polib.pofile(pofile)
        pofile.save_as_mofile(mofile.name)

        # Try to open it
        _t = gettext.GNUTranslations(fp=mofile) 
开发者ID:storaged-project,项目名称:libbytesize,代码行数:10,代码来源:test_usability.py

示例12: test_plural_forms2

# 需要导入模块: import gettext [as 别名]
# 或者: from gettext import GNUTranslations [as 别名]
def test_plural_forms2(self):
        eq = self.assertEqual
        with open(self.mofile, 'rb') as fp:
            t = gettext.GNUTranslations(fp)
        x = t.ngettext('There is %s file', 'There are %s files', 1)
        eq(x, 'Hay %s fichero')
        x = t.ngettext('There is %s file', 'There are %s files', 2)
        eq(x, 'Hay %s ficheros')

    # Examples from http://www.gnu.org/software/gettext/manual/gettext.html 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:12,代码来源:test_gettext.py

示例13: test_plural_form_error_issue17898

# 需要导入模块: import gettext [as 别名]
# 或者: from gettext import GNUTranslations [as 别名]
def test_plural_form_error_issue17898(self):
        with open(MOFILE, 'wb') as fp:
            fp.write(base64.decodestring(GNU_MO_DATA_ISSUE_17898))
        with open(MOFILE, 'rb') as fp:
            # If this runs cleanly, the bug is fixed.
            t = gettext.GNUTranslations(fp) 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:8,代码来源:test_gettext.py

示例14: setUp

# 需要导入模块: import gettext [as 别名]
# 或者: from gettext import GNUTranslations [as 别名]
def setUp(self):
        GettextBaseTest.setUp(self)
        with open(UMOFILE, 'rb') as fp:
            self.t = gettext.GNUTranslations(fp)
        self._ = self.t.ugettext 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:7,代码来源:test_gettext.py

示例15: merge

# 需要导入模块: import gettext [as 别名]
# 或者: from gettext import GNUTranslations [as 别名]
def merge(self, translations):
        """Merge the given translations into the catalog.

        Message translations in the specified catalog override any messages
        with the same identifier in the existing catalog.

        :param translations: the `Translations` instance with the messages to
                             merge
        """
        if isinstance(translations, gettext.GNUTranslations):
            self._catalog.update(translations._catalog)
            if isinstance(translations, Translations):
                self.files.extend(translations.files)

        return self 
开发者ID:Schibum,项目名称:sndlatr,代码行数:17,代码来源:support.py


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