本文整理汇总了Python中zope.i18n.interfaces.IUserPreferredLanguages类的典型用法代码示例。如果您正苦于以下问题:Python IUserPreferredLanguages类的具体用法?Python IUserPreferredLanguages怎么用?Python IUserPreferredLanguages使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了IUserPreferredLanguages类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: getLanguage
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
示例2: get_homepage_html
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
示例3: __call__
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 ()
示例4: __init__
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'
示例5: today
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)
示例6: getLanguage
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]
示例7: hour_time_formatter
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)
示例8: negotiate
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
示例9: getLocale
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)
示例10: getLanguage
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
示例11: browser_language
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
示例12: setupLocale
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)
示例13: menu_items
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
示例14: getLanguage
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
示例15: setupLocale
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)