• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Python i18n.gettext函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: search

    def search(self, ver=None, register=None):

        log.debug('search %s params: %r' % (register, request.params))
        if register == 'revision':
            since_time = None
            if 'since_id' in request.params:
                id = request.params['since_id']
                if not id:
                    return self._finish_bad_request(
                        gettext(u'No revision specified'))
                rev = model.Session.query(model.Revision).get(id)
                if rev is None:
                    return self._finish_not_found(
                        gettext(u'There is no revision with id: %s') % id)
                since_time = rev.timestamp
            elif 'since_time' in request.params:
                since_time_str = request.params['since_time']
                try:
                    since_time = h.date_str_to_datetime(since_time_str)
                except ValueError, inst:
                    return self._finish_bad_request('ValueError: %s' % inst)
            else:
                return self._finish_bad_request(
                    gettext("Missing search term ('since_id=UUID' or " +
                            " 'since_time=TIMESTAMP')"))
            revs = model.Session.query(model.Revision).\
                filter(model.Revision.timestamp > since_time)
            return self._finish_ok([rev.id for rev in revs])
开发者ID:harvestchoice,项目名称:ar-ckan,代码行数:28,代码来源:api.py


示例2: _wet_pager

def _wet_pager(self, *args, **kwargs):
    ## a custom pagination method, because CKAN doesn't expose the pagination to the templates,
    ## and instead hardcodes the pagination html in helpers.py

    kwargs.update(
        format=u"<ul class='pagination'>$link_previous ~2~ $link_next</ul>",
        symbol_previous=gettext('Previous').decode('utf-8'), symbol_next=gettext('Next').decode('utf-8'),
        curpage_attr={'class': 'active'}
    )

    return super(h.Page, self).pager(*args, **kwargs)
开发者ID:open-data,项目名称:ckanext-wet-boew,代码行数:11,代码来源:plugins.py


示例3: _wet_pager

def _wet_pager(self, *args, **kwargs):
    ## a custom pagination method, because CKAN doesn't expose the pagination to the templates,
    ## and instead hardcodes the pagination html in helpers.py
    
    kwargs.update(
        format=u"<div class='pagination pagination-centered'><ul class='menu-horizontal ckan-paginate'>$link_previous ~2~ $link_next</ul></div>",
        symbol_previous=gettext('Previous').decode('utf-8'), symbol_next=gettext('Next').decode('utf-8'),
        curpage_attr={'class': 'disabled_paginator'}, link_attr={'class': 'button button-small'}
    )
    
    return super(h.Page, self).pager(*args, **kwargs)
开发者ID:boxkite,项目名称:ckanext-wet-boew,代码行数:11,代码来源:plugins.py


示例4: delete

    def delete(self, ver=None, register=None, subregister=None,
               id=None, id2=None):
        action_map = {
            'group': 'group_delete',
            'dataset': 'package_delete',
            'related': 'related_delete',
            ('dataset', 'relationships'): 'package_relationship_delete_rest',
        }
        for type in model.PackageRelationship.get_all_types():
            action_map[('dataset', type)] = 'package_relationship_delete_rest'

        context = {'model': model, 'session': model.Session, 'user': c.user,
                   'api_version': ver}

        data_dict = {'id': id, 'id2': id2, 'rel': subregister}

        log.debug('delete %s/%s/%s/%s' % (register, id, subregister, id2))

        action = self._get_action_from_map(action_map, register, subregister)
        if not action:
            return self._finish_bad_request(
                gettext('Cannot delete entity of this type: %s %s') %
                (register, subregister or ''))
        try:
            response_data = action(context, data_dict)
            return self._finish_ok(response_data)
        except NotAuthorized:
            return self._finish_not_authz()
        except NotFound, e:
            extra_msg = e.extra_msg
            return self._finish_not_found(extra_msg)
开发者ID:harvestchoice,项目名称:ar-ckan,代码行数:31,代码来源:api.py


示例5: show

    def show(self, ver=None, register=None, subregister=None,
             id=None, id2=None):
        action_map = {
            'revision': 'revision_show',
            'group': 'group_show_rest',
            'tag': 'tag_show_rest',
            'related': 'related_show',
            'dataset': 'package_show_rest',
            ('dataset', 'relationships'): 'package_relationships_list',
        }
        for type in model.PackageRelationship.get_all_types():
            action_map[('dataset', type)] = 'package_relationships_list'

        context = {'model': model, 'session': model.Session, 'user': c.user,
                   'api_version': ver}
        data_dict = {'id': id, 'id2': id2, 'rel': subregister}

        log.debug('show: %s' % context)

        action = self._get_action_from_map(action_map, register, subregister)
        if not action:
            return self._finish_bad_request(
                gettext('Cannot read entity of this type: %s') % register)
        try:
            return self._finish_ok(action(context, data_dict))
        except NotFound, e:
            extra_msg = e.extra_msg
            return self._finish_not_found(extra_msg)
开发者ID:harvestchoice,项目名称:ar-ckan,代码行数:28,代码来源:api.py


示例6: list

    def list(self, ver=None, register=None, subregister=None, id=None):
        context = {'model': model, 'session': model.Session,
                   'user': c.user, 'api_version': ver}
        log.debug('listing: %s' % context)
        action_map = {
            'revision': 'revision_list',
            'group': 'group_list',
            'dataset': 'package_list',
            'tag': 'tag_list',
            'related': 'related_list',
            'licenses': 'licence_list',
            ('dataset', 'relationships'): 'package_relationships_list',
            ('dataset', 'revisions'): 'package_revision_list',
            ('dataset', 'activity'): 'package_activity_list',
            ('group', 'activity'): 'group_activity_list',
            ('user', 'activity'): 'user_activity_list',
            ('user', 'dashboard_activity'): 'dashboard_activity_list',
            ('activity', 'details'): 'activity_detail_list',
        }

        action = self._get_action_from_map(action_map, register, subregister)
        if not action:
            return self._finish_bad_request(
                gettext('Cannot list entity of this type: %s') % register)
        try:
            return self._finish_ok(action(context, {'id': id}))
        except NotFound, e:
            extra_msg = e.extra_msg
            return self._finish_not_found(extra_msg)
开发者ID:harvestchoice,项目名称:ar-ckan,代码行数:29,代码来源:api.py


示例7: _get_search_params

 def _get_search_params(cls, request_params):
     if 'qjson' in request_params:
         try:
             params = h.json.loads(request_params['qjson'], encoding='utf8')
         except ValueError, e:
             raise ValueError(gettext('Malformed qjson value') + ': %r'
                              % e)
开发者ID:abulte,项目名称:ckan,代码行数:7,代码来源:api.py


示例8: _get_search_params

 def _get_search_params(cls, request_params):
     if 'qjson' in request_params:
         try:
             qjson_param = request_params['qjson'].replace('\\\\u', '\\u')
             params = h.json.loads(qjson_param, encoding='utf8')
         except ValueError, e:
             raise ValueError(gettext('Malformed qjson value') + ': %r'
                              % e)
开发者ID:harvestchoice,项目名称:ar-ckan,代码行数:8,代码来源:api.py


示例9: action

    def action(self, logic_function, ver=None):
        function = get_action(logic_function)
        if not function:
            log.error('Can\'t find logic function: %s' % logic_function)
            return self._finish_bad_request(
                gettext('Action name not known: %s') % str(logic_function))

        context = {'model': model, 'session': model.Session, 'user': c.user,
                   'api_version':ver}
        model.Session()._context = context
        return_dict = {'help': function.__doc__}
        try:
            request_data = self._get_request_data()
        except ValueError, inst:
            log.error('Bad request data: %s' % str(inst))
            return self._finish_bad_request(
                gettext('JSON Error: %s') % str(inst))
开发者ID:emphanos,项目名称:ckan,代码行数:17,代码来源:api.py


示例10: choices

 def choices(f, choices):
     out.append({
         'datastore_id': f['datastore_id'],
         'label': gettext(f['label']).decode('utf-8'),
         'choices': [(v,
                 choices[v] if all_languages else
                 recombinant_language_text(choices[v], prefer_lang))
             for v in sorted(choices)],
         })
开发者ID:thriuin,项目名称:ckanext-recombinant,代码行数:9,代码来源:helpers.py


示例11: action

    def action(self, logic_function, ver=None):
        try:
            function = get_action(logic_function)
        except KeyError:
            log.error('Can\'t find logic function: %s' % logic_function)
            return self._finish_bad_request(
                gettext('Action name not known: %s') % str(logic_function))

        context = {'model': model, 'session': model.Session, 'user': c.user,
                   'api_version': ver}
        model.Session()._context = context
        return_dict = {'help': function.__doc__}
        try:
            side_effect_free = getattr(function, 'side_effect_free', False)
            request_data = self._get_request_data(try_url_params=
                                                  side_effect_free)
        except ValueError, inst:
            log.error('Bad request data: %s' % str(inst))
            return self._finish_bad_request(
                gettext('JSON Error: %s') % str(inst))
开发者ID:harvestchoice,项目名称:ar-ckan,代码行数:20,代码来源:api.py


示例12: update

    def update(self, ver=None, register=None, subregister=None, id=None, id2=None):
        action_map = {
             'dataset': 'package_update_rest',
             'group': 'group_update_rest',
            ('dataset', 'relationships'): 'package_relationship_update_rest',
        }
        for type in model.PackageRelationship.get_all_types():
            action_map[('dataset', type)] = 'package_relationship_update_rest'

        context = {'model': model, 'session': model.Session, 'user': c.user,
                   'api_version': ver, 'id': id}
        log.debug('update: %s' % (context))
        try:
            request_data = self._get_request_data()
            data_dict = {'id': id, 'id2': id2, 'rel': subregister}
            data_dict.update(request_data)
        except ValueError, inst:
            return self._finish_bad_request(
                gettext('JSON Error: %s') % str(inst))
开发者ID:emphanos,项目名称:ckan,代码行数:19,代码来源:api.py


示例13: scheming_language_text

def scheming_language_text(text, prefer_lang=None):
    """
    :param text: {lang: text} dict or text string
    :param prefer_lang: choose this language version if available

    Convert "language-text" to users' language by looking up
    languag in dict or using gettext if not a dict
    """
    if not text:
        return u''

    assert text != {}
    if hasattr(text, 'get'):
        try:
            if prefer_lang is None:
                prefer_lang = lang()
        except TypeError:
            pass  # lang() call will fail when no user language available
        else:
            try:
                return text[prefer_lang]
            except KeyError:
                pass

        default_locale = config.get('ckan.locale_default', 'en')
        try:
            return text[default_locale]
        except KeyError:
            pass

        l, v = sorted(text.items())[0]
        return v

    t = gettext(text)
    if isinstance(t, str):
        return t.decode('utf-8')
    return t
开发者ID:DataShades,项目名称:ckanext-scheming,代码行数:37,代码来源:helpers.py


示例14: getattr

            'api_version': ver}
 model.Session()._context = context
 return_dict = {'help': function.__doc__}
 try:
     side_effect_free = getattr(function, 'side_effect_free', False)
     request_data = self._get_request_data(try_url_params=
                                           side_effect_free)
 except ValueError, inst:
     log.error('Bad request data: %s' % str(inst))
     return self._finish_bad_request(
         gettext('JSON Error: %s') % str(inst))
 if not isinstance(request_data, dict):
     # this occurs if request_data is blank
     log.error('Bad request data - not dict: %r' % request_data)
     return self._finish_bad_request(
         gettext('Bad request data: %s') %
         'Request data JSON decoded to %r but '
         'it needs to be a dictionary.' % request_data)
 try:
     result = function(context, request_data)
     return_dict['success'] = True
     return_dict['result'] = result
 except DataError, e:
     log.error('Format incorrect: %s - %s' % (e.error, request_data))
     #TODO make better error message
     return self._finish(400, _(u'Integrity Error') +
                         ': %s - %s' % (e.error, request_data))
 except NotAuthorized:
     return_dict['error'] = {'__type': 'Authorization Error',
                             'message': _('Access denied')}
     return_dict['success'] = False
开发者ID:harvestchoice,项目名称:ar-ckan,代码行数:31,代码来源:api.py


示例15: build_package_no_form

def build_package_no_form(is_admin=False, user_editable_groups=None, **kwargs):
    # Restrict fields
    restrict = str(kwargs.get('restrict', False)).lower() not in \
               ('0', 'no', 'false', 0, False)

    builder = package.build_package_form(user_editable_groups=user_editable_groups)

    # Extra fields
    builder.add_field(common.TextExtraField('external_reference'))
    builder.add_field(common.DateExtraField('date_released'))
    builder.add_field(common.DateExtraField('date_updated'))
    builder.add_field(common.TextExtraField('update_frequency'))
    builder.add_field(common.SuggestedTextExtraField('geographic_granularity', options=schema_datano.geographic_granularity_options))
    builder.add_field(GeoCoverageExtraField('geographic_coverage'))
    builder.add_field(common.SuggestedTextExtraField('temporal_granularity', options=schema_datano.temporal_granularity_options))
    builder.add_field(common.DateRangeExtraField('temporal_coverage'))
    builder.add_field(common.SuggestedTextExtraField('categories', options=schema_datano.category_options))
    builder.add_field(common.CheckboxExtraField('national_statistic'))
    builder.add_field(common.TextExtraField('precision'))
    builder.add_field(common.SuggestedTextExtraField('department', options=schema_datano.government_depts))
    builder.add_field(common.TextExtraField('agency'))
    builder.add_field(common.TextExtraField('taxonomy_url'))
    builder.add_field(common.TextExtraField('title_en'))
    builder.add_field(common.TextExtraField('notes_en'))
    builder.add_field(common.TextExtraField('external_rss'))
    builder.add_field(common.TextExtraField('example_data'))


    # Labels and instructions
    builder.set_field_text('national_statistic', _('National Statistic'))
    builder.set_field_text('external_rss', _('External RSS'), instructions=_('Link to the data owner\'s external RSS feed.'))
    builder.set_field_text('title_en', _('Title EN'), instructions=_('Title in English. Translate what you wrote in the previous field to English.'))
    builder.set_field_text('notes_en', _('Notes EN'), instructions=_('Description in English. Translate what you wrote in the previous field to English.'))
    builder.set_field_text('date_released', _('Date released'), instructions=_('Date when data source was made available.'), hints=_('Format: DD/MM/YYYY'))
    builder.set_field_text('update_frequency', _('Update frequency'), instructions=_('How often will the data be updated.'), hints=_('e.g. annually, monthly'))
    builder.set_field_text('geographic_coverage', _('Geographic coverage'), instructions=_('Select geographic coverage for your data set.'))
    builder.set_field_text('temporal_coverage', _('Temporal coverage'), instructions=_('Temporal coverage for the data set.'), hints=_('Format: DD/MM/YYYY'))
    builder.set_field_text('author_email', _('Author email'), instructions=_('Email of the main contact for this data source.'))
    builder.set_field_text('maintainer_email', _('Maintainer email'), instructions=_('Email of a person that can be contacted for questions regarding this data source.'))
    builder.set_field_text('example_data', _('Data package example'), instructions=_('Example preview of the data available in this package.'))


    # Options/settings
    builder.set_field_option('tags', 'with_renderer', SuggestTagRenderer)
    builder.set_field_option('notes_en', 'textarea', {'size':'60x15'})
    builder.set_field_option('title', 'validate', required)
    builder.set_field_option('notes', 'validate', required)
    builder.set_field_option('example_data', 'textarea', {'size':'60x15'})

    
    if restrict:
        for field_name in ('name', 'department', 'national_statistic'):
            builder.set_field_option(field_name, 'readonly', True)

    # Layout
    field_groups = OrderedDict([
        (_('Basic information'), ['title', 'title_en', 'name', 'version',
                                  'notes', 'notes_en', 'tags']),
        (_('Details'), ['date_released', 'update_frequency',
                        'geographic_coverage',
                        'temporal_coverage',
                        'author', 'author_email',
                        'maintainer', 'maintainer_email',
                        'license_id',
                        'url', 'external_rss', 'example_data']),
        (_('Resources'), ['resources']),
        (_('More details'), []),
        ])
    if is_admin:
        field_groups[gettext('More details')].append('state')
    builder.set_displayed_fields(field_groups)
    return builder
    # Strings for i18n
    [_('External reference'),  _('Date released'), _('Date updated'),
     _('Update frequency'), _('Geographic granularity'),
     _('Geographic coverage'), _('Temporal granularity'),
     _('Temporal coverage'), _('Categories'), _('National Statistic'),
     _('Precision'), _('Taxonomy URL'), _('Department'), _('Agency'), 
     _('External RSS'), _('Data package example'),
     ]
开发者ID:okfn,项目名称:ckanext-datano,代码行数:80,代码来源:package_datano.py


示例16: str

        context = {'model': model, 'session': model.Session, 'user': c.user,
                   'api_version':ver}
        model.Session()._context = context
        return_dict = {'help': function.__doc__}
        try:
            request_data = self._get_request_data()
        except ValueError, inst:
            log.error('Bad request data: %s' % str(inst))
            return self._finish_bad_request(
                gettext('JSON Error: %s') % str(inst))
        if not isinstance(request_data, dict):
            # this occurs if request_data is blank
            log.error('Bad request data - not dict: %r' % request_data)
            return self._finish_bad_request(
                gettext('Bad request data: %s') % \
                'Request data JSON decoded to %r but ' \
                'it needs to be a dictionary.' % request_data)
        try:
            result = function(context, request_data)
            return_dict['success'] = True
            return_dict['result'] = result
        except DataError, e:
            log.error('Format incorrect: %s - %s' % (e.error, request_data))
            #TODO make better error message
            return self._finish(400, _(u'Integrity Error') + \
                                ': %s - %s' %  (e.error, request_data))
        except NotAuthorized:
            return_dict['error'] = {'__type': 'Authorization Error',
                                    'message': _('Access denied')}
            return_dict['success'] = False
开发者ID:datagvat,项目名称:ckanext-dgvat_por,代码行数:30,代码来源:dgvat_api.py



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python i18n.set_lang函数代码示例发布时间:2022-05-25
下一篇:
Python i18n.get_lang函数代码示例发布时间:2022-05-25
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap