本文整理汇总了Python中django.conf.settings.LANGUAGE_CODE属性的典型用法代码示例。如果您正苦于以下问题:Python settings.LANGUAGE_CODE属性的具体用法?Python settings.LANGUAGE_CODE怎么用?Python settings.LANGUAGE_CODE使用的例子?那么恭喜您, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类django.conf.settings
的用法示例。
在下文中一共展示了settings.LANGUAGE_CODE属性的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: currency
# 需要导入模块: from django.conf import settings [as 别名]
# 或者: from django.conf.settings import LANGUAGE_CODE [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: gettext
# 需要导入模块: from django.conf import settings [as 别名]
# 或者: from django.conf.settings import LANGUAGE_CODE [as 别名]
def gettext(message):
"""
Translate the 'message' string. It uses the current thread to find the
translation object to use. If no current translation is activated, the
message will be run through the default translation object.
"""
global _default
eol_message = message.replace('\r\n', '\n').replace('\r', '\n')
if len(eol_message) == 0:
# Return an empty value of the corresponding type if an empty message
# is given, instead of metadata, which is the default gettext behavior.
result = type(message)("")
else:
_default = _default or translation(settings.LANGUAGE_CODE)
translation_object = getattr(_active, "value", _default)
result = translation_object.gettext(eol_message)
if isinstance(message, SafeData):
return mark_safe(result)
return result
示例3: geocode
# 需要导入模块: from django.conf import settings [as 别名]
# 或者: from django.conf.settings import LANGUAGE_CODE [as 别名]
def geocode(query, country='', private=False, annotations=False, multiple=False):
key = SiteConfiguration.get_solo().opencage_api_key
lang = settings.LANGUAGE_CODE
if not query:
return
params = {'language': lang}
if not annotations:
params.update({'no_annotations': int(not annotations)})
if private:
params.update({'no_record': int(private)})
if country:
params.update({'countrycode': country})
result = geocoder.opencage(query, key=key, params=params, maxRows=15 if multiple else 1)
logging.getLogger('PasportaServo.geo').debug(
"Query: %s\n\tResult: %s\n\tConfidence: %d", query, result, result.confidence)
result.point = Point(result.xy, srid=SRID) if result.xy else None
return result
示例4: get_contest_queryset
# 需要导入模块: from django.conf import settings [as 别名]
# 或者: from django.conf.settings import LANGUAGE_CODE [as 别名]
def get_contest_queryset(self):
queryset = self.profile.current_contest.contest.contest_problems.select_related('problem__group') \
.defer('problem__description').order_by('problem__code') \
.annotate(user_count=Count('submission__participation', distinct=True)) \
.order_by('order')
queryset = TranslatedProblemForeignKeyQuerySet.add_problem_i18n_name(queryset, 'i18n_name',
self.request.LANGUAGE_CODE,
'problem__name')
return [{
'id': p['problem_id'],
'code': p['problem__code'],
'name': p['problem__name'],
'i18n_name': p['i18n_name'],
'group': {'full_name': p['problem__group__full_name']},
'points': p['points'],
'partial': p['partial'],
'user_count': p['user_count'],
} for p in queryset.values('problem_id', 'problem__code', 'problem__name', 'i18n_name',
'problem__group__full_name', 'points', 'partial', 'user_count')]
示例5: handle
# 需要导入模块: from django.conf import settings [as 别名]
# 或者: from django.conf.settings import LANGUAGE_CODE [as 别名]
def handle(self, *args, **options):
"""Collects Crossref Events, parses them and stores new events locally.
:param args: None
:param options: None
:return: None
"""
translation.activate(settings.LANGUAGE_CODE)
file_name = '{date}.json'.format(date=timezone.localdate())
file_path = os.path.join(settings.BASE_DIR, 'files', 'temp', file_name)
if os.path.isfile(file_path):
# Process file
print('Existing file found.')
process_events()
else:
# Fetch data
print('Fetching data from crossref event tracking API.')
fetch_crossref_data()
process_events()
示例6: save_plugin_setting
# 需要导入模块: from django.conf import settings [as 别名]
# 或者: from django.conf.settings import LANGUAGE_CODE [as 别名]
def save_plugin_setting(plugin, setting_name, value, journal):
setting = models.PluginSetting.objects.get(name=setting_name)
lang = get_language() or settings.LANGUAGE_CODE
lang = lang if setting.is_translatable else settings.LANGUAGE_CODE
setting_value, created = models.PluginSettingValue.objects.language(lang).get_or_create(
setting__plugin=plugin,
setting=setting,
journal=journal
)
if setting.types == 'json':
value = json.dumps(value)
if setting.types == 'boolean':
value = 'on' if value else ''
setting_value.value = value
setting_value.save()
return setting_value
示例7: _get_plugin_setting
# 需要导入模块: from django.conf import settings [as 别名]
# 或者: from django.conf.settings import LANGUAGE_CODE [as 别名]
def _get_plugin_setting(plugin, setting, journal, lang, create, fallback):
try:
setting = models.PluginSettingValue.objects.language(lang).get(
setting__plugin=plugin,
setting=setting,
journal=journal
)
return setting
except models.PluginSettingValue.DoesNotExist:
if lang == settings.LANGUAGE_CODE:
if create:
return save_plugin_setting(plugin, setting.name, '', journal)
else:
raise IndexError('Plugin setting does not exist and will not be created.')
else:
# Switch get the setting and start a translation
setting = models.PluginSettingValue.objects.language(settings.LANGUAGE_CODE).get(
setting__plugin=plugin,
setting=setting,
journal=journal
)
if not fallback:
setting.translate(lang)
return setting
示例8: test_save_translated_setting_without_default_lang
# 需要导入模块: from django.conf import settings [as 别名]
# 或者: from django.conf.settings import LANGUAGE_CODE [as 别名]
def test_save_translated_setting_without_default_lang(self):
setting_name = "test_save_translated_setting_without_default_lang"
setting_value = "plátano"
expected_result = ""
setting = setting_handler.create_setting(
"test_group", setting_name,
type="text",
pretty_name="Pretty Name",
description=None,
is_translatable=True,
)
setting_handler.save_setting(
"test_group", setting_name,
journal=self.journal_one,
value=setting_value,
)
with helpers.activate_translation(settings.LANGUAGE_CODE):
result = setting_handler.get_setting(
"test_group", setting_name,
journal=self.journal_one,
)
self.assertEqual(result.value, expected_result)
示例9: get
# 需要导入模块: from django.conf import settings [as 别名]
# 或者: from django.conf.settings import LANGUAGE_CODE [as 别名]
def get(self, language: str = None, default: str = None) -> str:
"""Gets the underlying value in the specified or primary language.
Arguments:
language:
The language to get the value in.
Returns:
The value in the current language, or
the primary language in case no language
was specified.
"""
language = language or settings.LANGUAGE_CODE
value = super().get(language, default)
return value if value is not None else default
示例10: validate
# 需要导入模块: from django.conf import settings [as 别名]
# 或者: from django.conf.settings import LANGUAGE_CODE [as 别名]
def validate(self, value: LocalizedValue, *_):
"""Validates that the values has been filled in for all required
languages.
Exceptions are raises in order to notify the user
of invalid values.
Arguments:
value:
The value to validate.
"""
if self.null:
return
for lang in self.required:
lang_val = getattr(value, settings.LANGUAGE_CODE)
if lang_val is None:
raise IntegrityError(
'null value in column "%s.%s" violates '
"not-null constraint" % (self.name, lang)
)
示例11: test_primary_language_required
# 需要导入模块: from django.conf import settings [as 别名]
# 或者: from django.conf.settings import LANGUAGE_CODE [as 别名]
def test_primary_language_required(self):
"""Tests whether the primary language is required by default and all
other languages are optiona."""
# not filling in anything should raise IntegrityError,
# the primary language is required
with self.assertRaises(IntegrityError):
obj = self.TestModel()
obj.save()
# when filling all other languages besides the primary language
# should still raise an error because the primary is always required
with self.assertRaises(IntegrityError):
obj = self.TestModel()
for lang_code, _ in settings.LANGUAGES:
if lang_code == settings.LANGUAGE_CODE:
continue
obj.score.set(lang_code, 23.0)
obj.save()
示例12: test_default_value
# 需要导入模块: from django.conf import settings [as 别名]
# 或者: from django.conf.settings import LANGUAGE_CODE [as 别名]
def test_default_value(self):
"""Tests whether a default is properly set when specified."""
model = get_fake_model(
{
"score": LocalizedFloatField(
default={settings.LANGUAGE_CODE: 75.0}
)
}
)
obj = model.objects.create()
assert obj.score.get(settings.LANGUAGE_CODE) == 75.0
obj = model()
for lang_code, _ in settings.LANGUAGES:
obj.score.set(lang_code, None)
obj.save()
for lang_code, _ in settings.LANGUAGES:
if lang_code == settings.LANGUAGE_CODE:
assert obj.score.get(lang_code) == 75.0
else:
assert obj.score.get(lang_code) is None
示例13: test_default_value
# 需要导入模块: from django.conf import settings [as 别名]
# 或者: from django.conf.settings import LANGUAGE_CODE [as 别名]
def test_default_value(self):
"""Tests whether a default is properly set when specified."""
model = get_fake_model(
{
"score": LocalizedIntegerField(
default={settings.LANGUAGE_CODE: 75}
)
}
)
obj = model.objects.create()
assert obj.score.get(settings.LANGUAGE_CODE) == 75
obj = model()
for lang_code, _ in settings.LANGUAGES:
obj.score.set(lang_code, None)
obj.save()
for lang_code, _ in settings.LANGUAGES:
if lang_code == settings.LANGUAGE_CODE:
assert obj.score.get(lang_code) == 75
else:
assert obj.score.get(lang_code) is None
示例14: make_wsgi_application
# 需要导入模块: from django.conf import settings [as 别名]
# 或者: from django.conf.settings import LANGUAGE_CODE [as 别名]
def make_wsgi_application():
# validate models
s = StringIO()
if get_validation_errors(s):
s.seek(0)
error = s.read()
msg = "One or more models did not validate:\n%s" % error
print(msg, file=sys.stderr)
sys.stderr.flush()
sys.exit(1)
translation.activate(settings.LANGUAGE_CODE)
if django14:
return get_internal_wsgi_application()
return WSGIHandler()
示例15: _i18n_cache_key_suffix
# 需要导入模块: from django.conf import settings [as 别名]
# 或者: from django.conf.settings import LANGUAGE_CODE [as 别名]
def _i18n_cache_key_suffix(request, cache_key):
"""If necessary, adds the current locale or time zone to the cache key."""
if settings.USE_I18N or settings.USE_L10N:
# first check if LocaleMiddleware or another middleware added
# LANGUAGE_CODE to request, then fall back to the active language
# which in turn can also fall back to settings.LANGUAGE_CODE
cache_key += '.%s' % getattr(request, 'LANGUAGE_CODE', get_language())
if settings.USE_TZ:
# The datetime module doesn't restrict the output of tzname().
# Windows is known to use non-standard, locale-dependent names.
# User-defined tzinfo classes may return absolutely anything.
# Hence this paranoid conversion to create a valid cache key.
tz_name = force_text(get_current_timezone_name(), errors='ignore')
cache_key += '.%s' % tz_name.encode('ascii', 'ignore').decode('ascii').replace(' ', '_')
return cache_key