本文整理汇总了Python中pyramid.i18n.get_locale_name函数的典型用法代码示例。如果您正苦于以下问题:Python get_locale_name函数的具体用法?Python get_locale_name怎么用?Python get_locale_name使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了get_locale_name函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: get_users_dt_helper
def get_users_dt_helper(request=None):
""" Get authenticated users timezone, lang and return DateTimeHelper for it. """
if request is None:
request = get_current_request()
userid = authenticated_userid(request)
root = find_root(request.context)
if root is None:
tz = request.registry.getUtility(ISettings)['default_timezone']
locale = get_locale_name(request)
else:
user = root['users'][userid]
tz = user.get_time_zone()
datetime_localisation = user.get_field_value('datetime_localisation', None)
locale = datetime_localisation and datetime_localisation or get_locale_name(request)
return createObject('dt_helper', tz, locale)
开发者ID:GlobalActionPlan,项目名称:MadeToMeasure,代码行数:15,代码来源:app.py
示例2: root_view
def root_view(request):
request.locale_name = 'fr'
localizer = get_localizer(request)
return {
'pyramid_translated': localizer.translate(_('Hello World')),
'locale_name': get_locale_name(request)
}
开发者ID:0x1997,项目名称:pyramid_jinja2,代码行数:7,代码来源:__init__.py
示例3: create_user
def create_user(request):
localizer = get_localizer(request)
name = request.params['name']
email = request.params['email']
user = User().queryObject().filter(User.email == email).scalar()
if (user != None):
msg = _('email_already_use', domain='Ondestan')
return localizer.translate(msg)
user = User()
user.name = name
user.email = email
user.locale = get_locale_name(request)
user.phone = request.params['phone']
user.activated = False
user.password = sha512(request.params['password']).hexdigest()
user.role_id = 2
user.save()
url = request.route_url('activate_user',
loginhash=sha512(email).hexdigest())
parameters = {'name': name, 'url': url}
ondestan.services.notification_service.process_notification('signup',
user.email, False, 0, True, False, parameters)
return ''
开发者ID:onde-estan,项目名称:ondestan,代码行数:27,代码来源:user_service.py
示例4: test_i18n_view
def test_i18n_view(request):
locale_name = get_locale_name(request)
print "DEBUG: locale_name is " + str(locale_name)
locale = Locale(locale_name)
print "DEBUG: babel locale is " + str(locale)
locale_name = get_locale_name(request)
print "DEBUG: locale_name is " + str(locale_name)
locale = Locale(locale_name)
print "DEBUG: babel locale is " + str(locale)
return {'project':'myapp',
'name':'Foo Bar',
'country_of_birth':'Baz'}
开发者ID:AnneGilles,项目名称:PyramidChameleonI18n,代码行数:16,代码来源:views.py
示例5: i18n
def i18n(self):
minmax = {'min':1, 'max':10}
locale_name = get_locale_name(self.request)
class Schema(colander.Schema):
number = colander.SchemaNode(
colander.Integer(),
title=_('A number between ${min} and ${max}',
mapping=minmax),
description=_('A number between ${min} and ${max}',
mapping=minmax),
validator = colander.Range(1, 10),
)
_LOCALE_ = colander.SchemaNode(
colander.String(),
widget = deform.widget.HiddenWidget(),
default=locale_name)
schema = Schema()
form = deform.Form(
schema,
buttons=[deform.Button('submit', _('Submit'))],
)
return self.render_form(form)
开发者ID:benzheren,项目名称:deform,代码行数:25,代码来源:app.py
示例6: get_ixiacr_tests
def get_ixiacr_tests(request):
lang = get_locale_name(request)
# JSON feed that is responsible for the ixiacr_tests.
test_id = request.params.get('test_id', None)
tests = TestCases.query.filter(TestCases.active=='1').order_by(TestCases.id.desc()).all()
items = []
try:
for test in tests:
config = {
"id": test.id,
"name": test.name.get_translation(lang),
"bpt_name": test.bpt_name,
"type": test.type,
"description": test.description.get_translation(lang),
#"duration": test.duration,
"topology_image": test.topology_image,
"topology_description": test.topology_description.get_translation(lang),
"attack_task": test.attack_task.get_translation(lang),
"attack_steps": test.attack_steps.get_translation(lang),
"attack_criteria": test.attack_criteria.get_translation(lang),
"defense_task": test.defense_task.get_translation(lang),
"defense_steps": test.defense_steps.get_translation(lang),
"defense_criteria": test.defense_criteria.get_translation(lang),
"traffic_direction": test.traffic_direction.get_translation(lang)
}
items.append(config)
return items
except DBAPIError, e:
return Response("Error: DB Error: {0}".format(e),
content_type='text/plain',
status_int=500)
开发者ID:jundong,项目名称:CRManager,代码行数:34,代码来源:ixiacr_json.py
示例7: survey_dt
def survey_dt(self):
survey = find_interface(self.context, ISurvey)
if not survey:
return
tz = survey.get_time_zone()
loc = get_locale_name(self.request)
return createObject('dt_helper', tz, loc)
开发者ID:GlobalActionPlan,项目名称:MadeToMeasure,代码行数:7,代码来源:base.py
示例8: __init__
def __init__(self, request):
self.request = request
init_cache_control(request, "entry")
self.settings = request.registry.settings
self.mapserver_settings = self.settings.get("mapserverproxy", {})
self.debug = "debug" in request.params
self.lang = get_locale_name(request)
开发者ID:kailIII,项目名称:c2cgeoportal,代码行数:7,代码来源:entry.py
示例9: title_to_name
def title_to_name(title):
request = get_current_request()
if request is not None:
locale_name = get_locale_name(request)
else:
locale_name = "en"
return unicode(urlnormalizer.normalize(title, locale_name, max_length=40))
开发者ID:dnouri,项目名称:Kotti,代码行数:7,代码来源:util.py
示例10: view_home
def view_home(self):
request = self.request
my_bootstrap.need() # we need css
log.debug("Locale: " + get_locale_name(request))
if not request.POST and self.logged_in and self.user:
data = {'HomeForm--yourmail': self.user.email,
'HomeForm--yourname': self.user.username
}
else:
data = None
form = home_form(request, data=request.POST or data)
if request.POST and form.validate(): # if submitted and and valid, create Pot and participant, and then go to pot site
log.debug("gutes Formular!")
pot = Pot(form.potname.value)
DBSession.add(pot)
participant = Participant(name=form.yourname.value, email=form.yourmail.value)
pot.participants.append(participant)
if form .yourmail.value:
mails.new_pot_mail(request, pot, participant, request.route_url('pot', identifier=participant.identifier))
if self.logged_in:
self.user.participations.append(participant)
return HTTPFound(location=request.route_url('pot', identifier=participant.identifier))
log.debug("Form: %s with model %s", str(id(form)), str(form.model))
log.debug("Field: %s", str(id(form.potname)))
log.debug("Form has errors? %s", str(form.errors))
return {'form': form, 'logged_in': self.logged_in}
开发者ID:NemesisSOAD,项目名称:moneypot,代码行数:27,代码来源:views.py
示例11: get_localizer
def get_localizer(request):
""" Retrieve a :class:`pyramid.i18n.Localizer` object
corresponding to the current request's locale name. """
localizer = getattr(request, 'localizer', None)
if localizer is None:
# no locale object cached on request
try:
registry = request.registry
except AttributeError:
registry = get_current_registry()
current_locale_name = get_locale_name(request)
localizer = registry.queryUtility(ILocalizer, name=current_locale_name)
if localizer is None:
# no localizer utility registered yet
tdirs = registry.queryUtility(ITranslationDirectories, default=[])
localizer = make_localizer(current_locale_name, tdirs)
registry.registerUtility(localizer, ILocalizer,
name=current_locale_name)
request.localizer = localizer
return localizer
开发者ID:petrblahos,项目名称:faapp-sample,代码行数:25,代码来源:__init__.py
示例12: sponsor_view
def sponsor_view(request):
"""
show a page confirming the sponsors payment
"""
#print "this is sponsor view"
_code = request.matchdict['linkcode']
_abo = Abo.get_by_linkcode(_code)
if 'de' in get_locale_name(request):
financial_blog_url = request.registry.settings['financial_blog_url_de']
else:
financial_blog_url = request.registry.settings['financial_blog_url_en']
if isinstance(_abo, NoneType):
#print "=== not found in DB"
request.session.flash('this linkcode is invalid', 'messages')
return {
'financial_situation_blog': financial_blog_url,
'invalid': True,
'message': "this linkcode is invalid.",
'abo': None
}
return {
'financial_situation_blog': financial_blog_url,
'invalid': False,
'message': '',
'abo': _abo
}
开发者ID:AnneGilles,项目名称:zabo,代码行数:26,代码来源:sponsors_views.py
示例13: project
def project(request):
check_project_expiration()
id = request.matchdict['project']
project = DBSession.query(Project).get(id)
if project is None:
_ = request.translate
request.session.flash(_("Sorry, this project doesn't exist"))
return HTTPFound(location=route_path('home', request))
project.locale = get_locale_name(request)
filter = and_(TaskState.project_id == id,
TaskState.state != TaskState.state_removed,
TaskState.state != TaskState.state_ready)
history = DBSession.query(TaskState) \
.filter(filter) \
.order_by(TaskState.date.desc()) \
.limit(20).all()
user_id = authenticated_userid(request)
locked_task = None
user = None
if user_id:
user = DBSession.query(User).get(user_id)
locked_task = get_locked_task(project.id, user)
features = []
for area in project.priority_areas:
features.append(Feature(geometry=shape.to_shape(area.geometry)))
return dict(page_id='project', project=project,
locked_task=locked_task,
history=history,
priority_areas=FeatureCollection(features),)
开发者ID:KaiBot3000,项目名称:osm-tasking-manager2,代码行数:35,代码来源:project.py
示例14: __init__
def __init__(self, context, request):
self.context = context
self.request = request
# Logged User
self.logged_in = authenticated_userid(request)
# Main message for pages if needed
self.message = u''
from easyblog.utilities import Provider
from pyramid.renderers import get_renderer
base = get_renderer('templates/base.pt').implementation()
# This dict will be returned in every view
def is_active(interface):
if provides(self.context, interface):
return 'active'
return ''
try:
lang = self.request.cookies['lang'],
except KeyError:
from pyramid.i18n import get_locale_name
lang = get_locale_name(self.request)
self.base_dict = {
'logged_in': self.logged_in,
'message': self.message,
'resource_url': resource_url,
'provider': Provider(self.context, self.request),
'is_active': is_active,
'base': base,
'lang': lang
}
开发者ID:tojuhaka,项目名称:easyblog,代码行数:34,代码来源:views.py
示例15: add_localizer
def add_localizer(event):
""" Localization event subscriber.
Automaticaly translate strings in the templates.
:param event: a ``pyramid.event.NewRequest`` object
"""
def auto_translate(string):
""" Use the message factory to translate strings."""
return localizer.translate(MessageFactory(string))
def gettext_translate(string):
""" Translate untranslated strings with FormEncode."""
# Try default translation first
translation = localizer.old_translate(i18n.TranslationString(string))
if translation == string:
# translation failed then use FormEncode
translation = formencode_api._stdtrans(string)
return translation
request = event.request
localizer = i18n.get_localizer(request)
request.localizer = localizer
request.translate = auto_translate
if not hasattr(localizer, "old_translate"):
localizer.old_translate = localizer.translate
locale_name = i18n.get_locale_name(request)
formencode_api.set_stdtranslation(languages=[locale_name])
localizer.translate = gettext_translate
开发者ID:lazaret,项目名称:anuket,代码行数:30,代码来源:subscribers.py
示例16: view_page
def view_page(request):
page_name = request.matchdict['page_name']
page_locale = get_locale_name(request)
page = DBSession.query(Page).filter_by(translite_name=page_name).\
filter_by(visible=True).one()
# clause for choised locale
if not page.language == page_locale:
page_on_lang = False
if page.orign_page_id == 0:
page_id = page.id
else:
page_id = page.orign_page_id
page_on_lang = DBSession.query(Page).\
filter_by(orign_page_id=page_id).\
filter_by(language=page_locale).all()
if page_on_lang:
page = page_on_lang[0]
childs = DBSession.query(Page).filter_by(parent_id=page.id).\
filter_by(visible=True).all()
def get_breadcrumbs_chain(page):
chain = []
chain.append(page)
while page.parent_id:
page = DBSession.query(Page).filter_by(id=page.parent_id).one()
chain.append(page)
if len(chain) == 1:
chain = []
return reversed(chain)
breadcrumbs = get_breadcrumbs_chain(page)
return dict(page=page, childs=childs, breadcrumbs=breadcrumbs)
开发者ID:eugeneai,项目名称:pyramid_promosite,代码行数:34,代码来源:pages.py
示例17: add_custom_functions
def add_custom_functions(event):
locale_name = get_locale_name(event['request'])
event.update({
'dates_formatter': DatesFormatter(locale_name),
})
开发者ID:Yaco-Sistemas,项目名称:yith-library-server,代码行数:7,代码来源:subscribers.py
示例18: locale_negotiator
def locale_negotiator(request):
lang = request.params.get('lang')
settings = get_current_registry().settings
languages = settings['available_languages'].split()
if lang is None or lang not in languages:
# the default_locale_name configuration variable
return get_locale_name(request)
return lang
开发者ID:cclauss,项目名称:mf-next,代码行数:8,代码来源:helpers.py
示例19: view_contactform
def view_contactform(context, request):
locale_name = get_locale_name(request)
tmpstore = FileUploadTempStore(request)
def file_size_limit(node, value):
value['fp'].seek(0, 2)
size = value['fp'].tell()
value['fp'].seek(0)
max_size = 10
if size > max_size * 1024 * 1024:
msg = _('Maximum file size: ${size}MB', mapping={'size': max_size})
raise colander.Invalid(node, msg)
def maybe_show_attachment(node, kw):
if kw.get('maybe_show_attachment', True) is False:
del node['attachment']
class SubmissionSchema(colander.MappingSchema):
name = colander.SchemaNode(colander.String(),
title=_("Full Name"))
sender = colander.SchemaNode(colander.String(),
validator=colander.Email(),
title=_("E-Mail Address"))
subject = colander.SchemaNode(colander.String(), title=_("Subject"))
content = colander.SchemaNode(
colander.String(),
widget=TextAreaWidget(cols=40, rows=5),
title=_("Your message")
)
attachment = colander.SchemaNode(
FileData(),
title=_('Attachment'),
widget=FileUploadWidget(tmpstore),
validator=file_size_limit,
missing=None,
)
_LOCALE_ = colander.SchemaNode(
colander.String(),
widget=HiddenWidget(),
default=locale_name)
schema = SubmissionSchema(after_bind=maybe_show_attachment)
schema = schema.bind(maybe_show_attachment=context.show_attachment)
form = Form(schema, buttons=[Button('submit', _('Submit'))])
appstruct = None
rendered_form = None
if 'submit' in request.POST:
controls = request.POST.items()
try:
appstruct = form.validate(controls)
mail_submission(context, request, appstruct)
except ValidationFailure, e:
appstruct = None
rendered_form = e.render()
开发者ID:jon1012,项目名称:kotti_contactform,代码行数:57,代码来源:views.py
示例20: add_page
def add_page(request):
user = authenticated_userid(request)
if 'form.submitted' in request.params:
name = request.params['name']
content = request.params['content']
if 'visible' in request.params:
visible = True
else:
visible = False
max_id = DBSession.query(func.max(Page.id)).all()
if max_id[0][0]:
position = max_id[0][0] + 1
else:
position = 1
page = Page(user, name, content, position, visible)
if 'parent_id' in request.params:
page.parent_id = request.params['parent_id']
else:
page.parent_id = 0
if 'lang' in request.params:
page.language = request.params['lang']
if 'translated_page' in request.params:
page.orign_page_id = request.params['translated_page']
page.created_by = user
page.tags = []
tags = re.split(r'[,;]+', request.params['tags'])
tags = filter(lambda x: x not in (None, '', ' '), tags)
tags = map(lambda x: x.strip(), tags)
tags = list(set(tags))
for tag in tags:
exist_tag = DBSession.query(Tag).filter_by(name=tag).all()
if exist_tag:
tag = exist_tag[0]
else:
tag = Tag(tag)
page.tags.append(tag)
DBSession.add(page)
return HTTPFound(location=request.route_url('admin'))
# if it child page
if 'parent_id' in request.params:
parent_id = request.params['parent_id']
else:
parent_id = ''
LOCALE = get_locale_name(request)
# if it translated page
if 'add_translate' in request.params:
translated_page_id = request.params['translated_page']
translated_page = DBSession.query(Page).\
filter_by(id=translated_page_id).one()
lang_list = get_lang(translated_page)
else:
lang_list = translated_page = None
page = Page(user, '', '', '', '')
return dict(page=page, parent_id=parent_id, translate_lang=lang_list,
translated=translated_page, LOCALE=LOCALE)
开发者ID:eugeneai,项目名称:pyramid_promosite,代码行数:57,代码来源:pages.py
注:本文中的pyramid.i18n.get_locale_name函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论