本文整理匯總了Python中django.conf.settings.LANGUAGES屬性的典型用法代碼示例。如果您正苦於以下問題:Python settings.LANGUAGES屬性的具體用法?Python settings.LANGUAGES怎麽用?Python settings.LANGUAGES使用的例子?那麽, 這裏精選的屬性代碼示例或許可以為您提供幫助。您也可以進一步了解該屬性所在類django.conf.settings
的用法示例。
在下文中一共展示了settings.LANGUAGES屬性的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: do_get_available_languages
# 需要導入模塊: from django.conf import settings [as 別名]
# 或者: from django.conf.settings import LANGUAGES [as 別名]
def do_get_available_languages(parser, token):
"""
This will store a list of available languages
in the context.
Usage::
{% get_available_languages as languages %}
{% for language in languages %}
...
{% endfor %}
This will just pull the LANGUAGES setting from
your setting file (or the default settings) and
put it into the named variable.
"""
# token.split_contents() isn't useful here because this tag doesn't accept variable as arguments
args = token.contents.split()
if len(args) != 3 or args[1] != 'as':
raise TemplateSyntaxError("'get_available_languages' requires 'as variable' (got %r)" % args)
return GetAvailableLanguagesNode(args[2])
示例2: do_get_language_info_list
# 需要導入模塊: from django.conf import settings [as 別名]
# 或者: from django.conf.settings import LANGUAGES [as 別名]
def do_get_language_info_list(parser, token):
"""
This will store a list of language information dictionaries for the given
language codes in a context variable. The language codes can be specified
either as a list of strings or a settings.LANGUAGES style tuple (or any
sequence of sequences whose first items are language codes).
Usage::
{% get_language_info_list for LANGUAGES as langs %}
{% for l in langs %}
{{ l.code }}
{{ l.name }}
{{ l.name_local }}
{{ l.bidi|yesno:"bi-directional,uni-directional" }}
{% endfor %}
"""
args = token.split_contents()
if len(args) != 5 or args[1] != 'for' or args[3] != 'as':
raise TemplateSyntaxError("'%s' requires 'for sequence as variable' (got %r)" % (args[0], args[1:]))
return GetLanguageInfoListNode(parser.compile_filter(args[2]), args[4])
示例3: forward_to_backends
# 需要導入模塊: from django.conf import settings [as 別名]
# 或者: from django.conf.settings import LANGUAGES [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()
示例4: _generate_exportable_category
# 需要導入模塊: from django.conf import settings [as 別名]
# 或者: from django.conf.settings import LANGUAGES [as 別名]
def _generate_exportable_category(event):
citysdk_category = dict()
citysdk_category['author'] = CITYSDK_DEFAULT_AUTHOR
citysdk_category['lang'] = bcp47_lang_map[settings.LANGUAGES[0][0]]
citysdk_category['term'] = 'category'
to_field_name = 'label'
citysdk_category[to_field_name] = []
for lang in [x[0] for x in settings.LANGUAGES]:
value = getattr(event, '%s_%s' % ("name", lang))
if value:
lang_dict = {
'term': 'primary',
'value': value,
'lang': bcp47_lang_map[lang]
}
citysdk_category[to_field_name].append(lang_dict)
return citysdk_category
示例5: __str__
# 需要導入模塊: from django.conf import settings [as 別名]
# 或者: from django.conf.settings import LANGUAGES [as 別名]
def __str__(self):
name = ''
languages = [lang[0] for lang in settings.LANGUAGES]
for lang in languages:
lang = lang.replace('-', '_') # to handle complex codes like e.g. zh-hans
s = getattr(self, 'name_%s' % lang, None)
if s:
name = s
break
val = [name, '(%s)' % self.id]
dcount = self.get_descendant_count()
if dcount > 0:
val.append(u" (%d children)" % dcount)
else:
val.append(str(self.start_time))
return u" ".join(val)
示例6: validate
# 需要導入模塊: from django.conf import settings [as 別名]
# 或者: from django.conf.settings import LANGUAGES [as 別名]
def validate(self, data):
if 'name' in self.translated_fields:
name_exists = False
languages = [x[0] for x in settings.LANGUAGES]
for language in languages:
# null or empty strings are not allowed, they are the same as missing name!
if 'name_%s' % language in data and data['name_%s' % language]:
name_exists = True
break
else:
# null or empty strings are not allowed, they are the same as missing name!
name_exists = 'name' in data and data['name']
if not name_exists:
raise serializers.ValidationError({'name': _('The name must be specified.')})
super().validate(data)
return data
示例7: setup
# 需要導入模塊: from django.conf import settings [as 別名]
# 或者: from django.conf.settings import LANGUAGES [as 別名]
def setup(self):
self.languages_to_detect = [lang[0].replace('-', '_') for lang in settings.LANGUAGES
if lang[0] not in self.supported_languages]
ytj_data_source, _ = DataSource.objects.get_or_create(defaults={'name': "YTJ"}, id='ytj')
parent_org_args = dict(origin_id='0586977-6', data_source=ytj_data_source)
parent_defaults = dict(name='Helsinki Marketing Oy')
self.parent_organization, _ = Organization.objects.get_or_create(
defaults=parent_defaults, **parent_org_args)
org_args = dict(origin_id='1789232-4', data_source=ytj_data_source, internal_type=Organization.AFFILIATED,
parent=self.parent_organization)
org_defaults = dict(name="Lippupiste Oy")
self.organization, _ = Organization.objects.get_or_create(defaults=org_defaults, **org_args)
data_source_args = dict(id=self.name)
data_source_defaults = dict(name="Lippupiste", owner=self.organization)
self.data_source, _ = DataSource.objects.get_or_create(defaults=data_source_defaults, **data_source_args)
self.tprek_data_source = DataSource.objects.get(id='tprek')
self._cache_yso_keyword_objects()
self._cache_place_data()
try:
self.event_only_license = License.objects.get(id='event_only')
except License.DoesNotExist:
self.event_only_license = None
self.sub_event_count_by_super_event_source_id = defaultdict(lambda: 0)
示例8: do_get_language_info_list
# 需要導入模塊: from django.conf import settings [as 別名]
# 或者: from django.conf.settings import LANGUAGES [as 別名]
def do_get_language_info_list(parser, token):
"""
This will store a list of language information dictionaries for the given
language codes in a context variable. The language codes can be specified
either as a list of strings or a settings.LANGUAGES style list (or any
sequence of sequences whose first items are language codes).
Usage::
{% get_language_info_list for LANGUAGES as langs %}
{% for l in langs %}
{{ l.code }}
{{ l.name }}
{{ l.name_translated }}
{{ l.name_local }}
{{ l.bidi|yesno:"bi-directional,uni-directional" }}
{% endfor %}
"""
args = token.split_contents()
if len(args) != 5 or args[1] != 'for' or args[3] != 'as':
raise TemplateSyntaxError("'%s' requires 'for sequence as variable' (got %r)" % (args[0], args[1:]))
return GetLanguageInfoListNode(parser.compile_filter(args[2]), args[4])
示例9: info_integration
# 需要導入模塊: from django.conf import settings [as 別名]
# 或者: from django.conf.settings import LANGUAGES [as 別名]
def info_integration(asset: Asset, lang: str):
# Not using `asset` since this reference server only supports SRT
languages = [l[0] for l in server_settings.LANGUAGES]
if lang and lang not in languages:
raise ValueError()
return {
"fields": {
"type": {
"description": _("'bank_account' is the only value supported'"),
"choices": ["bank_account"],
},
},
"types": {
"bank_account": {
"fields": {
"dest": {"description": _("bank account number")},
"dest_extra": {"description": _("bank routing number")},
}
}
},
}
示例10: languages
# 需要導入模塊: from django.conf import settings [as 別名]
# 或者: from django.conf.settings import LANGUAGES [as 別名]
def languages(self, create, extracted, **kwargs):
"""Accepts a list of language codes and adds each language to the
Conference allowed languages.
This fixture makes easier to add allowed languages to a Conference in the tests
"""
if not create:
return
if extracted:
for language_code in extracted:
self.languages.add(Language.objects.get(code=language_code))
else:
self.languages.add(
Language.objects.get(code=random.choice(settings.LANGUAGES)[0])
)
示例11: test_i18n_switcher
# 需要導入模塊: from django.conf import settings [as 別名]
# 或者: from django.conf.settings import LANGUAGES [as 別名]
def test_i18n_switcher(rf):
""" The language switcher is rendered correctly. """
# create a fake template with a name
template = "{% load core_tags %}{% i18n_switcher %}"
# set a language
translation.activate(settings.LANGUAGES[0][0])
# render the link
request = rf.get(reverse('home'))
context = RequestContext(request, {})
rendered_template = Template(template).render(context)
for language in settings.LANGUAGES:
if language == settings.LANGUAGES[0]:
assert '<a href="/i18n/%s/"><u>%s</u></a>' % language in rendered_template
else:
assert'<a href="/i18n/%s/">%s</a>' % language in rendered_template
示例12: problem_update
# 需要導入模塊: from django.conf import settings [as 別名]
# 或者: from django.conf.settings import LANGUAGES [as 別名]
def problem_update(sender, instance, **kwargs):
if hasattr(instance, '_updating_stats_only'):
return
cache.delete_many([
make_template_fragment_key('submission_problem', (instance.id,)),
make_template_fragment_key('problem_feed', (instance.id,)),
'problem_tls:%s' % instance.id, 'problem_mls:%s' % instance.id,
])
cache.delete_many([make_template_fragment_key('problem_html', (instance.id, engine, lang))
for lang, _ in settings.LANGUAGES for engine in EFFECTIVE_MATH_ENGINES])
cache.delete_many([make_template_fragment_key('problem_authors', (instance.id, lang))
for lang, _ in settings.LANGUAGES])
cache.delete_many(['generated-meta-problem:%s:%d' % (lang, instance.id) for lang, _ in settings.LANGUAGES])
for lang, _ in settings.LANGUAGES:
unlink_if_exists(get_pdf_path('%s.%s.pdf' % (instance.code, lang)))
示例13: decompress
# 需要導入模塊: from django.conf import settings [as 別名]
# 或者: from django.conf.settings import LANGUAGES [as 別名]
def decompress(self, value: LocalizedValue) -> List[str]:
"""Decompresses the specified value so it can be spread over the
internal widgets.
Arguments:
value:
The :see:LocalizedValue to display in this
widget.
Returns:
All values to display in the inner widgets.
"""
result = []
for lang_code, _ in settings.LANGUAGES:
if value:
result.append(value.get(lang_code))
else:
result.append(None)
return result
示例14: __eq__
# 需要導入模塊: from django.conf import settings [as 別名]
# 或者: from django.conf.settings import LANGUAGES [as 別名]
def __eq__(self, other):
"""Compares :paramref:self to :paramref:other for equality.
Returns:
True when :paramref:self is equal to :paramref:other.
And False when they are not.
"""
if not isinstance(other, type(self)):
if isinstance(other, str):
return self.__str__() == other
return False
for lang_code, _ in settings.LANGUAGES:
if self.get(lang_code) != other.get(lang_code):
return False
return True
示例15: compress
# 需要導入模塊: from django.conf import settings [as 別名]
# 或者: from django.conf.settings import LANGUAGES [as 別名]
def compress(self, value: List[str]) -> LocalizedValue:
"""Compresses the values from individual fields into a single
:see:LocalizedValue instance.
Arguments:
value:
The values from all the widgets.
Returns:
A :see:LocalizedValue containing all
the value in several languages.
"""
localized_value = self.value_class()
for (lang_code, _), value in zip(settings.LANGUAGES, value):
localized_value.set(lang_code, value)
return localized_value