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


Python IUserPreferredLanguages.getPreferredLanguages方法代码示例

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


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

示例1: getLanguage

# 需要导入模块: from zope.i18n.interfaces import IUserPreferredLanguages [as 别名]
# 或者: from zope.i18n.interfaces.IUserPreferredLanguages import getPreferredLanguages [as 别名]
def getLanguage(self, langs, env):
    envadapter = IUserPreferredLanguages(env)
    userlangs = envadapter.getPreferredLanguages()
    # Always add the template language to the available ones. This allows the
    # template language to be picked without the need for a message catalog
    # for every domain for it to be registered.
    langs = tuple(langs) + TEMPLATE_LANGUAGE
    
    global _cache, _bcache
    l_cache = _cache
    b_cache = _bcache

    notnormalized = [l for l in langs if l not in b_cache]
    if notnormalized:
        l_cache.update(normalize_langs(notnormalized))
        b_cache.update(dict((v, k) for k, v in l_cache.items()))
    
      
    # Prioritize on the user preferred languages.  Return the
    # first user preferred language that the object has available.
    #langs = normalize_langs(langs)
    for lang in userlangs:
        if lang in l_cache:
            return l_cache[lang]
        # If the user asked for a specific variation, but we don't
        # have it available we may serve the most generic one,
        # according to the spec (eg: user asks for ('en-us',
        # 'de'), but we don't have 'en-us', then 'en' is preferred
        # to 'de').
        parts = lang.split('-')
        if len(parts) > 1 and parts[0] in l_cache:
            return l_cache.get(parts[0])
    return None
开发者ID:enfold,项目名称:experimental.ploneperformance,代码行数:35,代码来源:pts.py

示例2: get_homepage_html

# 需要导入模块: from zope.i18n.interfaces import IUserPreferredLanguages [as 别名]
# 或者: from zope.i18n.interfaces.IUserPreferredLanguages import getPreferredLanguages [as 别名]
 def get_homepage_html(self):
     adapter = IUserPreferredLanguages(self.request)
     language = adapter.getPreferredLanguages()[0]
     if language == 'en':
         return self.context['admin'].english_home_html
     else:
         return self.context['admin'].dutch_home_html
开发者ID:brambgit,项目名称:bioport-site,代码行数:9,代码来源:app.py

示例3: __call__

# 需要导入模块: from zope.i18n.interfaces import IUserPreferredLanguages [as 别名]
# 或者: from zope.i18n.interfaces.IUserPreferredLanguages import getPreferredLanguages [as 别名]
    def __call__(self, objectId, instance, *args, **kw):
        lang = IUserPreferredLanguages(instance.request, None)
        if lang is not None:
            lang = lang.getPreferredLanguages()
            if lang:
                return {'request:%s'%self.name: lang[0]}

        return ()
开发者ID:Zojax,项目名称:zojax.cache,代码行数:10,代码来源:default.py

示例4: __init__

# 需要导入模块: from zope.i18n.interfaces import IUserPreferredLanguages [as 别名]
# 或者: from zope.i18n.interfaces.IUserPreferredLanguages import getPreferredLanguages [as 别名]
    def __init__(self, request):
        self._send = getUtility(IMessageService).send
        self.request = request

        adapter = IUserPreferredLanguages(self.request)
        languages = adapter.getPreferredLanguages()
        if languages:
            self._language = languages[0]
        else:
            self._language = 'en'
开发者ID:silvacms,项目名称:silva.ui,代码行数:12,代码来源:notifier.py

示例5: today

# 需要导入模块: from zope.i18n.interfaces import IUserPreferredLanguages [as 别名]
# 或者: from zope.i18n.interfaces.IUserPreferredLanguages import getPreferredLanguages [as 别名]
 def today(self):
     today = datetime.date.today()
     adapter = IUserPreferredLanguages(self.request)
     lang = adapter.getPreferredLanguages()[0]
     if lang == 'en':
         month = months[today.month - 1]
         return '%s %s' % (month, today.day)
     else:
         month = maanden[today.month - 1]
         return '%s %s' % (today.day, month)
开发者ID:brambgit,项目名称:bioport-site,代码行数:12,代码来源:app.py

示例6: getLanguage

# 需要导入模块: from zope.i18n.interfaces import IUserPreferredLanguages [as 别名]
# 或者: from zope.i18n.interfaces.IUserPreferredLanguages import getPreferredLanguages [as 别名]
 def getLanguage(self):
     """
     """
     languages = IUserPreferredLanguages(self.context.REQUEST)
     langs = languages.getPreferredLanguages()
     if langs:
         language = langs[0]
     else:
         plone_props = getToolByName(self.context, 'portal_properties')
         language = plone_props.site_properties.default_language
     language = language.split('-')
     return language[0]
开发者ID:huubbouma,项目名称:pcommerce.payment.docdata,代码行数:14,代码来源:plugin.py

示例7: hour_time_formatter

# 需要导入模块: from zope.i18n.interfaces import IUserPreferredLanguages [as 别名]
# 或者: from zope.i18n.interfaces.IUserPreferredLanguages import getPreferredLanguages [as 别名]
def hour_time_formatter(self, timeobj):
    """uses zope.i18n.locales to determine hour/min format
    """

    #grab locale from request
    languages = IUserPreferredLanguages(self.request)
    langs = languages.getPreferredLanguages()
    if langs:
        parts = (langs[0].split('-') + [None,None])[:3]
    else:
        parts = (None,None,None)
    locale = locales.getLocale(*parts)

    #create formatted hour minute string
    formatter = locale.dates.getFormatter('time', 'short')
    return formatter.format(timeobj)
开发者ID:Cenditel,项目名称:cenditel.comunidades.cynin,代码行数:18,代码来源:month.py

示例8: negotiate

# 需要导入模块: from zope.i18n.interfaces import IUserPreferredLanguages [as 别名]
# 或者: from zope.i18n.interfaces.IUserPreferredLanguages import getPreferredLanguages [as 别名]
def negotiate(request):
    """Monkey patch zope.i18n.negotiate not to rely on environment
    variable, and to cache its computation.
    """
    if IRequest.providedBy(request):
        if 'I18N_LANGUAGE' in request.other:
            return request.other['I18N_LANGUAGE']
        adapter = IUserPreferredLanguages(request)
        languages = adapter.getPreferredLanguages()
        if languages:
            language = languages[0]
        else:
            language = 'en'
        request.other['I18N_LANGUAGE'] = language
        return language
    return None
开发者ID:silvacms,项目名称:silva.translations,代码行数:18,代码来源:negotiate.py

示例9: getLocale

# 需要导入模块: from zope.i18n.interfaces import IUserPreferredLanguages [as 别名]
# 或者: from zope.i18n.interfaces.IUserPreferredLanguages import getPreferredLanguages [as 别名]
def getLocale(request):
    envadapter = IUserPreferredLanguages(request, None)
    if envadapter is None:
        return None

    langs = envadapter.getPreferredLanguages()
    for httplang in langs:
        parts = (httplang.split('-') + [None, None])[:3]
        try:
            return locales.getLocale(*parts)
        except LoadLocaleError:
            # Just try the next combination
            pass
    else:
        # No combination gave us an existing locale, so use the default,
        # which is guaranteed to exist
        return locales.getLocale(None, None, None)
开发者ID:goschtl,项目名称:zope,代码行数:19,代码来源:form.py

示例10: getLanguage

# 需要导入模块: from zope.i18n.interfaces import IUserPreferredLanguages [as 别名]
# 或者: from zope.i18n.interfaces.IUserPreferredLanguages import getPreferredLanguages [as 别名]
 def getLanguage(self, langs, env):
     envadapter = IUserPreferredLanguages(env)
     userlangs = envadapter.getPreferredLanguages()
     # Prioritize on the user preferred languages.  Return the
     # first user preferred language that the object has available.
     langs = normalize_langs(langs)
     for lang in userlangs:
         if lang in langs:
             return langs.get(lang)
         # If the user asked for a specific variation, but we don't
         # have it available we may serve the most generic one,
         # according to the spec (eg: user asks for ('en-us',
         # 'de'), but we don't have 'en-us', then 'en' is preferred
         # to 'de').
         parts = lang.split('-')
         if len(parts) > 1 and parts[0] in langs:
             return langs.get(parts[0])
     return None
开发者ID:Andyvs,项目名称:TrackMonthlyExpenses,代码行数:20,代码来源:negotiator.py

示例11: browser_language

# 需要导入模块: from zope.i18n.interfaces import IUserPreferredLanguages [as 别名]
# 或者: from zope.i18n.interfaces.IUserPreferredLanguages import getPreferredLanguages [as 别名]
 def browser_language(self):
     language = 'en'
     pl = IUserPreferredLanguages(self.request)
     if pl is not None:
         languages = pl.getPreferredLanguages()
         for httplang in languages:
             parts = (httplang.split('-') + [None, None])[:3]
             if parts[0] == parts[1]:
                 # Avoid creating a country code for simple languages codes
                 parts = [parts[0], None, None]
             try:
                 locale = locales.getLocale(*parts)
                 language = locale.getLocaleID().replace('_', '-').lower()
                 break
             except LoadLocaleError:
                 # Just try the next combination
                 pass
     return language
开发者ID:mingtak,项目名称:Products.CMFPlone_for_tpa,代码行数:20,代码来源:admin.py

示例12: menu_items

# 需要导入模块: from zope.i18n.interfaces import IUserPreferredLanguages [as 别名]
# 或者: from zope.i18n.interfaces.IUserPreferredLanguages import getPreferredLanguages [as 别名]
    def menu_items(self):
        items = [
            (self.application_url(), _('home')),
            (self.application_url('zoek'), _('zoeken')),
            (self.application_url('personen') + '?beginletter=a', _('bladeren')),
            (self.application_url('about'), _('project')),
        ]

        adapter = IUserPreferredLanguages(self.request)
        lang = adapter.getPreferredLanguages()[0]
        if lang != 'en':
            items += [(self.application_url('blog'), _('blog')),
                    (self.application_url('agenda'), _('agenda')), ]
        items += [
            (self.application_url('links'), _('links')),
            (self.application_url('faq'), _('vragen')),
            (self.application_url('contact'), _('contact')),
        ]
        return items
开发者ID:HuygensING,项目名称:bioport-site,代码行数:21,代码来源:app.py

示例13: setupLocale

# 需要导入模块: from zope.i18n.interfaces import IUserPreferredLanguages [as 别名]
# 或者: from zope.i18n.interfaces.IUserPreferredLanguages import getPreferredLanguages [as 别名]
    def setupLocale(self):
        envadapter = IUserPreferredLanguages(self, None)
        if envadapter is None:
            self._locale = None
            return

        langs = envadapter.getPreferredLanguages()
        for httplang in langs:
            parts = (httplang.split("-") + [None, None])[:3]
            try:
                self._locale = locales.getLocale(*parts)
                return
            except LoadLocaleError:
                # Just try the next combination
                pass
        else:
            # No combination gave us an existing locale, so use the default,
            # which is guaranteed to exist
            self._locale = locales.getLocale(None, None, None)
开发者ID:pigaov10,项目名称:plone4.3,代码行数:21,代码来源:http.py

示例14: getLanguage

# 需要导入模块: from zope.i18n.interfaces import IUserPreferredLanguages [as 别名]
# 或者: from zope.i18n.interfaces.IUserPreferredLanguages import getPreferredLanguages [as 别名]
def getLanguage(self, langs, env):
    envadapter = IUserPreferredLanguages(env)
    userlangs = envadapter.getPreferredLanguages()
    # Always add the template language to the available ones. This allows the
    # template language to be picked without the need for a message catalog
    # for every domain for it to be registered.
    langs = list(langs) + TEMPLATE_LANGUAGE
    # Prioritize on the user preferred languages.  Return the
    # first user preferred language that the object has available.
    langs = normalize_langs(langs)
    for lang in userlangs:
        if lang in langs:
            return langs.get(lang)
        # If the user asked for a specific variation, but we don't
        # have it available we may serve the most generic one,
        # according to the spec (eg: user asks for ('en-us',
        # 'de'), but we don't have 'en-us', then 'en' is preferred
        # to 'de').
        parts = lang.split('-')
        if len(parts) > 1 and parts[0] in langs:
            return langs.get(parts[0])
    return None
开发者ID:CGTIC,项目名称:Plone_SP,代码行数:24,代码来源:patches.py

示例15: setupLocale

# 需要导入模块: from zope.i18n.interfaces import IUserPreferredLanguages [as 别名]
# 或者: from zope.i18n.interfaces.IUserPreferredLanguages import getPreferredLanguages [as 别名]
    def setupLocale( self, request ):
        # slightly adapted from zope.publisher.http.HTTPRequest.setupLocale
        if getattr( request, 'locale', None) is not None:
            return
        
        envadapter = IUserPreferredLanguages(request, None)
        if envadapter is None:
            request.locale = locales.getLocale(None, None, None)            
            return

        langs = envadapter.getPreferredLanguages()
        for httplang in langs:
            parts = (httplang.split('-') + [None, None])[:3]
            try:
                request.locale = locales.getLocale(*parts)
                return
            except LoadLocaleError:
                # Just try the next combination
                pass
        else:
            # No combination gave us an existing locale, so use the default,
            # which is guaranteed to exist
            request.locale = locales.getLocale(None, None, None)
开发者ID:Martronic-SA,项目名称:Products.PloneGetPaid,代码行数:25,代码来源:base.py


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