Python django.utils.translation.get_language_info() Examples
The following are 30
code examples of django.utils.translation.get_language_info().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
django.utils.translation
, or try the search function
.
Example #1
Source File: i18n.py From bioforum with MIT License | 6 votes |
def do_get_language_info(parser, token): """ This will store the language information dictionary for the given language code in a context variable. Usage:: {% get_language_info for LANGUAGE_CODE as l %} {{ l.code }} {{ l.name }} {{ l.name_translated }} {{ l.name_local }} {{ l.bidi|yesno:"bi-directional,uni-directional" }} """ args = token.split_contents() if len(args) != 5 or args[1] != 'for' or args[3] != 'as': raise TemplateSyntaxError("'%s' requires 'for string as variable' (got %r)" % (args[0], args[1:])) return GetLanguageInfoNode(parser.compile_filter(args[2]), args[4])
Example #2
Source File: i18n.py From Hands-On-Application-Development-with-PyCharm with MIT License | 6 votes |
def do_get_language_info(parser, token): """ Store the language information dictionary for the given language code in a context variable. Usage:: {% get_language_info for LANGUAGE_CODE as l %} {{ l.code }} {{ l.name }} {{ l.name_translated }} {{ l.name_local }} {{ l.bidi|yesno:"bi-directional,uni-directional" }} """ args = token.split_contents() if len(args) != 5 or args[1] != 'for' or args[3] != 'as': raise TemplateSyntaxError("'%s' requires 'for string as variable' (got %r)" % (args[0], args[1:])) return GetLanguageInfoNode(parser.compile_filter(args[2]), args[4])
Example #3
Source File: i18n.py From openhgsenti with Apache License 2.0 | 6 votes |
def do_get_language_info(parser, token): """ This will store the language information dictionary for the given language code in a context variable. Usage:: {% get_language_info for LANGUAGE_CODE as l %} {{ l.code }} {{ l.name }} {{ l.name_translated }} {{ l.name_local }} {{ l.bidi|yesno:"bi-directional,uni-directional" }} """ args = token.split_contents() if len(args) != 5 or args[1] != 'for' or args[3] != 'as': raise TemplateSyntaxError("'%s' requires 'for string as variable' (got %r)" % (args[0], args[1:])) return GetLanguageInfoNode(parser.compile_filter(args[2]), args[4])
Example #4
Source File: i18n.py From python with Apache License 2.0 | 6 votes |
def do_get_language_info(parser, token): """ This will store the language information dictionary for the given language code in a context variable. Usage:: {% get_language_info for LANGUAGE_CODE as l %} {{ l.code }} {{ l.name }} {{ l.name_translated }} {{ l.name_local }} {{ l.bidi|yesno:"bi-directional,uni-directional" }} """ args = token.split_contents() if len(args) != 5 or args[1] != 'for' or args[3] != 'as': raise TemplateSyntaxError("'%s' requires 'for string as variable' (got %r)" % (args[0], args[1:])) return GetLanguageInfoNode(parser.compile_filter(args[2]), args[4])
Example #5
Source File: i18n.py From luscan-devel with GNU General Public License v2.0 | 6 votes |
def do_get_language_info(parser, token): """ This will store the language information dictionary for the given language code in a context variable. Usage:: {% get_language_info for LANGUAGE_CODE as l %} {{ l.code }} {{ l.name }} {{ l.name_local }} {{ l.bidi|yesno:"bi-directional,uni-directional" }} """ args = token.contents.split() if len(args) != 5 or args[1] != 'for' or args[3] != 'as': raise TemplateSyntaxError("'%s' requires 'for string as variable' (got %r)" % (args[0], args[1:])) return GetLanguageInfoNode(args[2], args[4])
Example #6
Source File: i18n.py From python2017 with MIT License | 6 votes |
def do_get_language_info(parser, token): """ This will store the language information dictionary for the given language code in a context variable. Usage:: {% get_language_info for LANGUAGE_CODE as l %} {{ l.code }} {{ l.name }} {{ l.name_translated }} {{ l.name_local }} {{ l.bidi|yesno:"bi-directional,uni-directional" }} """ args = token.split_contents() if len(args) != 5 or args[1] != 'for' or args[3] != 'as': raise TemplateSyntaxError("'%s' requires 'for string as variable' (got %r)" % (args[0], args[1:])) return GetLanguageInfoNode(parser.compile_filter(args[2]), args[4])
Example #7
Source File: i18n.py From GTDWeb with GNU General Public License v2.0 | 6 votes |
def do_get_language_info(parser, token): """ This will store the language information dictionary for the given language code in a context variable. Usage:: {% get_language_info for LANGUAGE_CODE as l %} {{ l.code }} {{ l.name }} {{ l.name_local }} {{ l.bidi|yesno:"bi-directional,uni-directional" }} """ args = token.split_contents() if len(args) != 5 or args[1] != 'for' or args[3] != 'as': raise TemplateSyntaxError("'%s' requires 'for string as variable' (got %r)" % (args[0], args[1:])) return GetLanguageInfoNode(parser.compile_filter(args[2]), args[4])
Example #8
Source File: i18n.py From python2017 with MIT License | 6 votes |
def language_bidi(lang_code): return translation.get_language_info(lang_code)['bidi']
Example #9
Source File: i18n.py From luscan-devel with GNU General Public License v2.0 | 5 votes |
def render(self, context): langs = self.languages.resolve(context) context[self.variable] = [self.get_language_info(lang) for lang in langs] return ''
Example #10
Source File: i18n.py From luscan-devel with GNU General Public License v2.0 | 5 votes |
def get_language_info(self, language): # ``language`` is either a language code string or a sequence # with the language code as its first item if len(language[0]) > 1: return translation.get_language_info(language[0]) else: return translation.get_language_info(str(language))
Example #11
Source File: i18n.py From openhgsenti with Apache License 2.0 | 5 votes |
def language_name(lang_code): return translation.get_language_info(lang_code)['name']
Example #12
Source File: i18n.py From luscan-devel with GNU General Public License v2.0 | 5 votes |
def language_name(lang_code): return translation.get_language_info(lang_code)['name']
Example #13
Source File: i18n.py From luscan-devel with GNU General Public License v2.0 | 5 votes |
def language_bidi(lang_code): return translation.get_language_info(lang_code)['bidi']
Example #14
Source File: transcript.py From xblock-ooyala with GNU Affero General Public License v3.0 | 5 votes |
def get_localized_name(self, lang_name, lang_code): try: lang_info = get_language_info(lang_code) localized_name = lang_info.get('name_local') except KeyError: localized_name = lang_name return localized_name
Example #15
Source File: transcript.py From xblock-ooyala with GNU Affero General Public License v3.0 | 5 votes |
def _get_imported_transcripts(self, selected_lang): """ Retrieve imported transcripts. *Imported transcripts are not listed in translation api. """ imports_list = self.get_imported_transcripts_list() lang_ids = self.get_language_details() for caption_import in imports_list: if caption_import['media_file_id'] == self.transcript_id: lang_id = caption_import.get('language_id', 0) language = lang_ids.get(lang_id).get('name') lang_code = lang_ids.get(lang_id).get('code') threeplay_id = caption_import.get('threeplay_transcript_id') try: lang_info = get_language_info(lang_code) localized_name = lang_info.get('name_local') except KeyError: localized_name = language if language and lang_code and threeplay_id and lang_id != self.language_id: self.imported_translations.append({ 'threeplay_id': threeplay_id, 'transcript_id': self.transcript_id, 'language': language, 'lang_code': lang_code, 'selected': True if selected_lang in [language, lang_code] else False, 'localized_name': localized_name, 'dir': 'rtl' if language in RTL_LANGUAGES else 'ltr' })
Example #16
Source File: i18n.py From openhgsenti with Apache License 2.0 | 5 votes |
def render(self, context): lang_code = self.lang_code.resolve(context) context[self.variable] = translation.get_language_info(lang_code) return ''
Example #17
Source File: i18n.py From openhgsenti with Apache License 2.0 | 5 votes |
def get_language_info(self, language): # ``language`` is either a language code string or a sequence # with the language code as its first item if len(language[0]) > 1: return translation.get_language_info(language[0]) else: return translation.get_language_info(str(language))
Example #18
Source File: i18n.py From luscan-devel with GNU General Public License v2.0 | 5 votes |
def render(self, context): lang_code = self.lang_code.resolve(context) context[self.variable] = translation.get_language_info(lang_code) return ''
Example #19
Source File: i18n.py From openhgsenti with Apache License 2.0 | 5 votes |
def render(self, context): langs = self.languages.resolve(context) context[self.variable] = [self.get_language_info(lang) for lang in langs] return ''
Example #20
Source File: i18n.py From python with Apache License 2.0 | 5 votes |
def language_bidi(lang_code): return translation.get_language_info(lang_code)['bidi']
Example #21
Source File: i18n.py From openhgsenti with Apache License 2.0 | 5 votes |
def language_name_local(lang_code): return translation.get_language_info(lang_code)['name_local']
Example #22
Source File: i18n.py From openhgsenti with Apache License 2.0 | 5 votes |
def language_bidi(lang_code): return translation.get_language_info(lang_code)['bidi']
Example #23
Source File: base.py From c3nav with Apache License 2.0 | 5 votes |
def details_display(self, **kwargs): result = super().details_display(**kwargs) for lang, title in sorted(self.titles.items(), key=lambda item: item[0] != get_language()): language = _('Title ({lang})').format(lang=get_language_info(lang)['name_translated']) result['display'].append((language, title)) return result
Example #24
Source File: forms.py From c3nav with Apache License 2.0 | 5 votes |
def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) new_fields = OrderedDict() self.i18n_fields = [] for name, form_field in self.fields.items(): model_field = self.instance._meta.get_field(name) if not isinstance(model_field, I18nField): new_fields[name] = form_field continue values = OrderedDict((lang_code, '') for lang_code, language in settings.LANGUAGES) if self.instance is not None and self.instance.pk: values.update(getattr(self.instance, model_field.attname)) has_values = False for language in values.keys(): sub_field_name = '%s__%s' % (name, language) new_value = self.data.get(sub_field_name) if new_value is not None: has_values = True values[language] = new_value language_info = get_language_info(language) field_title = format_lazy(_('{field_name} ({lang})'), field_name=capfirst(model_field.verbose_name), lang=language_info['name_translated']) new_fields[sub_field_name] = CharField(label=field_title, required=False, initial=values[language].strip(), max_length=model_field.i18n_max_length, help_text=form_field.help_text) if has_values: self.i18n_fields.append((model_field, values)) self.fields = new_fields
Example #25
Source File: i18n.py From python2017 with MIT License | 5 votes |
def render(self, context): lang_code = self.lang_code.resolve(context) context[self.variable] = translation.get_language_info(lang_code) return ''
Example #26
Source File: i18n.py From python2017 with MIT License | 5 votes |
def get_language_info(self, language): # ``language`` is either a language code string or a sequence # with the language code as its first item if len(language[0]) > 1: return translation.get_language_info(language[0]) else: return translation.get_language_info(str(language))
Example #27
Source File: i18n.py From python2017 with MIT License | 5 votes |
def render(self, context): langs = self.languages.resolve(context) context[self.variable] = [self.get_language_info(lang) for lang in langs] return ''
Example #28
Source File: i18n.py From python2017 with MIT License | 5 votes |
def language_name(lang_code): return translation.get_language_info(lang_code)['name']
Example #29
Source File: i18n.py From python2017 with MIT License | 5 votes |
def language_name_local(lang_code): return translation.get_language_info(lang_code)['name_local']
Example #30
Source File: util_tags.py From donate-wagtail with Mozilla Public License 2.0 | 5 votes |
def get_local_language_names(): locale.setlocale(locale.LC_ALL, "C.UTF-8") languages = [] for lang in settings.LANGUAGES: languages.append([lang[0], get_language_info(lang[0])['name_local']]) return sorted(languages, key=lambda x: locale.strxfrm(unicodedata.normalize('NFD', x[1])).casefold())