當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。