How to use the langcodes.get_name function in langcodes

To help you get started, we’ve selected a few langcodes examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github dimagi / commcare-hq / corehq / apps / app_manager / app_strings.py View on Github external
numeric_nav_on = app.profile.get('properties', {}).get('cc-entry-mode') == 'cc-entry-review'
            if app.profile.get('features', {}).get('sense') == 'true' or numeric_nav_on:
                text = "${0} %s" % (text,) if not (text and text[0].isdigit()) else text
        return text

    langs = [lang] + app.langs
    yield id_strings.homescreen_title(), app.name
    yield id_strings.app_display_name(), app.name

    yield 'cchq.case', "Case"
    yield 'cchq.referral', "Referral"

    if for_default:
        # include language code names and current language
        for lc in app.langs:
            name = langcodes.get_name(lc) or lc
            if not name:
                continue
            with localize(convert_to_two_letter_code(lc)):
                name = ugettext(name)
            yield lc, name

    yield id_strings.current_language(), lang

    for module in app.get_modules():
        for detail_type, detail, _ in module.get_details():
            for column in detail.get_columns():
                yield id_strings.detail_column_header_locale(module, detail_type, column), trans(column.header)

                if column.format in ('enum', 'enum-image', 'conditional-enum'):
                    for item in column.enum:
                        yield id_strings.detail_column_enum_variable(
github dimagi / commcare-hq / corehq / apps / reminders / forms.py View on Github external
def clean_translated_field(self, translations, default_lang):
        for lang, msg in translations.items():
            if msg:
                msg = msg.strip()
            if not msg:
                del translations[lang]
            else:
                translations[lang] = msg
        if default_lang not in translations:
            default_lang_name = (get_language_name(default_lang) or
                default_lang)
            raise ValidationError(_("Please provide messages for the "
                "default language (%(language)s) or change the default "
                "language at the bottom of the page.") %
                {"language": default_lang_name})
        return translations
github dimagi / commcare-hq / corehq / apps / users / views / __init__.py View on Github external
def get_domain_languages(domain):
    app_languages = [res['key'][1] for res in Application.get_db().view(
        'languages/list',
        startkey=[domain],
        endkey=[domain, {}],
        group='true'
    ).all()]

    translation_doc = StandaloneTranslationDoc.get_obj(domain, 'sms')
    sms_languages = translation_doc.langs if translation_doc else []

    domain_languages = []
    for lang_code in set(app_languages + sms_languages):
        name = langcodes.get_name(lang_code)
        label = u"{} ({})".format(lang_code, name) if name else lang_code
        domain_languages.append((lang_code, label))

    return sorted(domain_languages) or langcodes.get_all_langs_for_select()
github dimagi / commcare-hq / corehq / apps / users / views / __init__.py View on Github external
def get_domain_languages(domain):
    query = (AppES()
             .domain(domain)
             .terms_aggregation('langs', 'languages')
             .size(0))
    app_languages = query.run().aggregations.languages.keys

    translation_doc = StandaloneTranslationDoc.get_obj(domain, 'sms')
    sms_languages = translation_doc.langs if translation_doc else []

    domain_languages = []
    for lang_code in set(app_languages + sms_languages):
        name = langcodes.get_name(lang_code)
        label = "{} ({})".format(lang_code, name) if name else lang_code
        domain_languages.append((lang_code, label))

    return sorted(domain_languages) or langcodes.get_all_langs_for_select()
github dimagi / commcare-hq / corehq / messaging / scheduling / forms.py View on Github external
def set_default_language_code_choices(self):
        choices = [
            (self.LANGUAGE_PROJECT_DEFAULT, _("Project Default")),
        ]

        choices.extend([
            (language_code, _(get_language_name(language_code)))
            for language_code in self.language_list
        ])

        self.fields['default_language_code'].choices = choices