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


Python translation.get_language方法代码示例

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


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

示例1: currency

# 需要导入模块: from django.utils import translation [as 别名]
# 或者: from django.utils.translation import get_language [as 别名]
def currency(value, currency=None):
    """
    Format decimal value as currency
    """
    try:
        value = D(value)
    except (TypeError, InvalidOperation):
        return ""

    # Using Babel's currency formatting
    # http://babel.pocoo.org/en/latest/api/numbers.html#babel.numbers.format_currency

    kwargs = {
        'currency': currency or CURRENCY,
        'locale': to_locale(get_language() or settings.LANGUAGE_CODE)
    }

    return format_currency(value, **kwargs) 
开发者ID:slyapustin,项目名称:django-classified,代码行数:20,代码来源:classified.py

示例2: currency_formatter

# 需要导入模块: from django.utils import translation [as 别名]
# 或者: from django.utils.translation import get_language [as 别名]
def currency_formatter(value, currency=None):
    """
    Format decimal value as currency
    """
    try:
        value = D(value)
    except (TypeError, InvalidOperation):
        return ""
    # Using Babel's currency formatting
    # http://babel.pocoo.org/docs/api/numbers/#babel.numbers.format_currency
    currency = currency or settings.ACCOUNTING_DEFAULT_CURRENCY
    kwargs = {
        'currency': currency,
        'format': getattr(settings, 'CURRENCY_FORMAT', None),
        'locale': to_locale(get_language()),
    }
    return format_currency(value, **kwargs) 
开发者ID:dulacp,项目名称:django-accounting,代码行数:19,代码来源:currency_filters.py

示例3: tracker_context

# 需要导入模块: from django.utils import translation [as 别名]
# 或者: from django.utils.translation import get_language [as 别名]
def tracker_context(request, qdict=None):
    starttime = datetime.datetime.now()
    language = translation.get_language_from_request(request)
    translation.activate(language)
    request.LANGUAGE_CODE = translation.get_language()
    profile = None
    qdict = qdict or {}
    qdict.update(
        {
            'djangoversion': dv(),
            'pythonversion': pv(),
            'user': request.user,
            'profile': profile,
            'next': request.POST.get('next', request.GET.get('next', request.path)),
            'starttime': starttime,
            'events': tracker.models.Event.objects.all(),
            'settings': settings,
        }
    )
    qdict.setdefault('event', viewutil.get_event(None))
    qdict.setdefault('user', request.user)
    return qdict 
开发者ID:GamesDoneQuick,项目名称:donation-tracker,代码行数:24,代码来源:common.py

示例4: regex

# 需要导入模块: from django.utils import translation [as 别名]
# 或者: from django.utils.translation import get_language [as 别名]
def regex(self):
        """
        Returns a compiled regular expression, depending upon the activated
        language-code.
        """
        language_code = get_language()
        if language_code not in self._regex_dict:
            if isinstance(self._regex, six.string_types):
                regex = self._regex
            else:
                regex = force_text(self._regex)
            try:
                compiled_regex = re.compile(regex, re.UNICODE)
            except re.error as e:
                raise ImproperlyConfigured(
                    '"%s" is not a valid regular expression: %s' %
                    (regex, six.text_type(e)))

            self._regex_dict[language_code] = compiled_regex
        return self._regex_dict[language_code] 
开发者ID:lanbing510,项目名称:GTDWeb,代码行数:22,代码来源:urlresolvers.py

示例5: forward_to_backends

# 需要导入模块: from django.utils import translation [as 别名]
# 或者: from django.utils.translation import get_language [as 别名]
def forward_to_backends(self, method, *args, **kwargs):
        # forwards the desired backend method to all the language backends
        initial_language = translation.get_language()
        # retrieve unique backend name
        backends = []
        for language, _ in settings.LANGUAGES:
            using = '%s-%s' % (self.connection_alias, language)
            # Ensure each backend is called only once
            if using in backends:
                continue
            else:
                backends.append(using)
            translation.activate(language)
            backend = connections[using].get_backend()
            getattr(backend.parent_class, method)(backend, *args, **kwargs)

        if initial_language is not None:
            translation.activate(initial_language)
        else:
            translation.deactivate() 
开发者ID:City-of-Helsinki,项目名称:linkedevents,代码行数:22,代码来源:backends.py

示例6: media

# 需要导入模块: from django.utils import translation [as 别名]
# 或者: from django.utils.translation import get_language [as 别名]
def media(self):
        extra = '' if settings.DEBUG else '.min'
        i18n_name = SELECT2_TRANSLATIONS.get(get_language())
        i18n_file = ('admin/js/vendor/select2/i18n/%s.js' % i18n_name,) if i18n_name else ()
        return forms.Media(
            js=(
                'admin/js/vendor/jquery/jquery%s.js' % extra,
                'admin/js/vendor/select2/select2.full%s.js' % extra,
            ) + i18n_file + (
                'admin/js/jquery.init.js',
                'admin/js/autocomplete.js',
            ),
            css={
                'screen': (
                    'admin/css/vendor/select2/select2%s.css' % extra,
                    'admin/css/autocomplete.css',
                ),
            },
        ) 
开发者ID:reBiocoder,项目名称:bioforum,代码行数:21,代码来源:widgets.py

示例7: get_public_newsfeed

# 需要导入模块: from django.utils import translation [as 别名]
# 或者: from django.utils.translation import get_language [as 别名]
def get_public_newsfeed(self, offset, limit):
        """
        Fetches news items from the newsfeed database
        """
        language = self.get_language()

        parameters = {
            "news_type": {
                "$in": [NEWS_TYPE_CONTENTION,
                        NEWS_TYPE_PREMISE,
                        NEWS_TYPE_FALLACY]
            },
            "related_object.language": language
        }

        newsfeed = (Entry
                    .objects
                    .collection
                    .find(parameters)
                    .sort([("date_created", -1)])
                    .skip(offset)
                    .limit(limit))
        return map(Entry, newsfeed) 
开发者ID:arguman,项目名称:arguman.org,代码行数:25,代码来源:models.py

示例8: get_target

# 需要导入模块: from django.utils import translation [as 别名]
# 或者: from django.utils.translation import get_language [as 别名]
def get_target(self):
        target_noun = self.cleaned_data['target_noun']

        try:
            noun = Noun.objects.get(
                text=target_noun,
                language=normalize_language_code(get_language())
            )
        except Noun.DoesNotExist:
            noun = Noun.objects.create(
                text=target_noun,
                is_active=False,
                language=normalize_language_code(get_language())
            )

        return noun 
开发者ID:arguman,项目名称:arguman.org,代码行数:18,代码来源:forms.py

示例9: channel

# 需要导入模块: from django.utils import translation [as 别名]
# 或者: from django.utils.translation import get_language [as 别名]
def channel(self):
        from nouns.models import Channel

        if self.related_nouns.exists():
            nouns = self.related_nouns.all()
        else:
            nouns = self.nouns.all()

        if not nouns:
            return

        channel = Channel.objects.filter(
            nouns__in=nouns,
            language=normalize_language_code(get_language())
        ).first()

        return channel 
开发者ID:arguman,项目名称:arguman.org,代码行数:19,代码来源:models.py

示例10: media

# 需要导入模块: from django.utils import translation [as 别名]
# 或者: from django.utils.translation import get_language [as 别名]
def media(self):
        """
        Construct Media as a dynamic property.
        .. Note:: For more information visit
            https://docs.djangoproject.com/en/stable/topics/forms/media/#media-as-a-dynamic-property
        """
        lang = get_language()
        select2_js = (settings.SELECT2_JS,) if settings.SELECT2_JS else ()
        select2_css = (settings.SELECT2_CSS,) if settings.SELECT2_CSS else ()

        i18n_name = SELECT2_TRANSLATIONS.get(lang)
        if i18n_name not in settings.SELECT2_I18N_AVAILABLE_LANGUAGES:
            i18n_name = None

        i18n_file = (
            ('%s/%s.js' % (settings.SELECT2_I18N_PATH, i18n_name),)
            if i18n_name
            else ()
        )

        return forms.Media(
            js=select2_js + i18n_file + (static("js/django_select2.js"), ),
            css={'screen': select2_css}
        ) 
开发者ID:dissemin,项目名称:dissemin,代码行数:26,代码来源:widgets.py

示例11: merge_translation

# 需要导入模块: from django.utils import translation [as 别名]
# 或者: from django.utils.translation import get_language [as 别名]
def merge_translation(self, context):
        """
        Context wrapper which modifies the given language's translation catalog using the i18n service, if found.
        """
        language = get_language()
        i18n_service = context.get('_i18n_service', None)
        if i18n_service:
            # Cache the original translation object to reduce overhead
            if language not in self._translations:
                self._translations[language] = trans_real.DjangoTranslation(language)

            translation = trans_real.translation(language)
            translation.merge(i18n_service)

        yield

        # Revert to original translation object
        if language in self._translations:
            trans_real._translations[language] = self._translations[language]  # pylint: disable=protected-access
            # Re-activate the current language to reset translation caches
            trans_real.activate(language) 
开发者ID:edx,项目名称:xblock-utils,代码行数:23,代码来源:i18n.py

示例12: percentage_formatter

# 需要导入模块: from django.utils import translation [as 别名]
# 或者: from django.utils.translation import get_language [as 别名]
def percentage_formatter(value):
    if value or value == 0:
        kwargs = {
            'locale': to_locale(get_language()),
            'format': "#,##0.00 %",
        }
        return format_percent(value, **kwargs) 
开发者ID:dulacp,项目名称:django-accounting,代码行数:9,代码来源:format_filters.py

示例13: get_current_locale

# 需要导入模块: from django.utils import translation [as 别名]
# 或者: from django.utils.translation import get_language [as 别名]
def get_current_locale():
    """Return the locale for the current language."""
    return to_locale(get_language()) 
开发者ID:twschiller,项目名称:open-synthesis,代码行数:5,代码来源:translation.py

示例14: xstatic

# 需要导入模块: from django.utils import translation [as 别名]
# 或者: from django.utils.translation import get_language [as 别名]
def xstatic(*tags):
    from .vendors import vendors
    node = vendors

    fs = []
    lang = get_language()

    cls_str = str if six.PY3 else basestring
    for tag in tags:
        try:
            for p in tag.split('.'):
                node = node[p]
        except Exception as e:
            if tag.startswith('xadmin'):
                file_type = tag.split('.')[-1]
                if file_type in ('css', 'js'):
                    node = "xadmin/%s/%s" % (file_type, tag)
                else:
                    raise e
            else:
                raise e

        if isinstance(node, cls_str):
            files = node
        else:
            mode = 'dev'
            if not settings.DEBUG:
                mode = getattr(settings, 'STATIC_USE_CDN',
                               False) and 'cdn' or 'production'

            if mode == 'cdn' and mode not in node:
                mode = 'production'
            if mode == 'production' and mode not in node:
                mode = 'dev'
            files = node[mode]

        files = type(files) in (list, tuple) and files or [files, ]
        fs.extend([f % {'lang': lang.replace('_', '-')} for f in files])

    return [f.startswith('http://') and f or static(f) for f in fs] 
开发者ID:stormsha,项目名称:StormOnline,代码行数:42,代码来源:util.py

示例15: get_language

# 需要导入模块: from django.utils import translation [as 别名]
# 或者: from django.utils.translation import get_language [as 别名]
def get_language(self):
        ideascube_language = get_language()
        return _ideascube_to_tinyMCE_language_map.get(
            ideascube_language, ideascube_language) 
开发者ID:ideascube,项目名称:ideascube,代码行数:6,代码来源:widgets.py


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