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


Python i18n.get_locale_name函数代码示例

本文整理汇总了Python中pyramid.i18n.get_locale_name函数的典型用法代码示例。如果您正苦于以下问题:Python get_locale_name函数的具体用法?Python get_locale_name怎么用?Python get_locale_name使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了get_locale_name函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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


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