本文整理汇总了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)
示例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)
示例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
示例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]
示例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()
示例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',
),
},
)
示例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)
示例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
示例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
示例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}
)
示例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)
示例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)
示例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())
示例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]
示例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)