How to use the langcodes.get_all_langs_for_select 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 / users / views / __init__.py View on Github external
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 / apps / translations / forms.py View on Github external
elif form_action == 'update':
            return UpdateAppTranslationsForm
        elif form_action == 'push':
            return PushAppTranslationsForm
        elif form_action == 'pull':
            return PullAppTranslationsForm
        elif form_action == 'backup':
            return BackUpAppTranslationsForm
        elif form_action == 'delete':
            return DeleteAppTranslationsForm


class CreateAppTranslationsForm(AppTranslationsForm):
    form_action = 'create'
    source_lang = forms.ChoiceField(label=ugettext_lazy("Source Language on Transifex"),
                                    choices=langcodes.get_all_langs_for_select(),
                                    initial="en"
                                    )

    def form_fields(self):
        form_fields = super(CreateAppTranslationsForm, self).form_fields()
        form_fields.append(hqcrispy.Field('source_lang', css_class="hqwebapp-select2"))
        return form_fields


class UpdateAppTranslationsForm(CreateAppTranslationsForm):
    form_action = 'update'


class PushAppTranslationsForm(AppTranslationsForm):
    form_action = 'push'
github dimagi / commcare-hq / corehq / apps / reports / views.py View on Github external
'show': user_can_view_reports(self.request.project, self.request.couch_user),
                'slug': None,
                'default_url': reverse('reports_home', args=(self.domain,)),
                'is_async': False,
                'section_name': ProjectReport.section_name,
                'title': self.page_name,
            }
        }

        if not self.configs and not self.request.couch_user.is_domain_admin(self.domain):
            return context

        is_configurable_map = {c._id: c.is_configurable_report for c in self.configs}
        supports_translations = {c._id: c.supports_translations for c in self.configs}
        languages_map = {c._id: list(c.languages | set(['en'])) for c in self.configs}
        languages_for_select = {tup[0]: tup for tup in langcodes.get_all_langs_for_select()}

        context.update({
            'form': self.scheduled_report_form,
            'day_value': getattr(self.report_notification, "day", 1),
            'weekly_day_options': ReportNotification.day_choices(),
            'monthly_day_options': [(i, i) for i in range(1, 32)],
            'form_action': _("Create a new") if self.is_new else _("Edit"),
            'is_configurable_map': is_configurable_map,
            'supports_translations': supports_translations,
            'languages_map': languages_map,
            'languages_for_select': languages_for_select,
            'is_owner': self.is_new or self.request.couch_user._id == self.owner_id,
        })
        return context
github dimagi / commcare-hq / custom / icds_reports / forms.py View on Github external
widget=forms.CheckboxSelectMultiple(),
        required=False,
        initial='yes',
    )
    update_resource = forms.MultipleChoiceField(
        choices=[
            ('yes', 'Update the resource files'),
        ],
        widget=forms.CheckboxSelectMultiple(),
        required=False,
        initial='no',
    )
    transifex_project_slug = forms.ChoiceField(label=ugettext_lazy("Trasifex project"), choices=(),
                                               required=True)
    source_lang = forms.ChoiceField(label=ugettext_lazy("Source Language"),
                                    choices=langcodes.get_all_langs_for_select(),
                                    initial="en"
                                    )
    # Unfortunately transifex api does not provide a way to pull all possible target languages and
    # allow us to just add a checkbox instead of selecting a single/multiple target languages at once
    target_lang = forms.ChoiceField(label=ugettext_lazy("Target Language"),
                                    choices=([(None, ugettext_lazy('Select Target Language'))] +
                                             langcodes.get_all_langs_for_select()),
                                    help_text=ugettext_lazy("Leave blank to skip"),
                                    required=False,
                                    )
    action = forms.ChoiceField(label=ugettext_lazy("Action"),
                               choices=[('push', ugettext_lazy('Push to transifex')),
                                        ('pull', ugettext_lazy('Pull from transifex')),
                                        ('delete', ugettext_lazy('Delete resources on transifex'))]
                               )
    lock_translations = forms.BooleanField(label=ugettext_lazy("Lock resources"),
github dimagi / commcare-hq / corehq / apps / reports / forms.py View on Github external
send_to_owner = forms.BooleanField(
        label='Send to me',
        required=False)

    attach_excel = forms.BooleanField(
        label='Attach Excel Report',
        required=False)

    recipient_emails = MultiEmailField(
        label='Other recipients',
        required=False)

    language = forms.ChoiceField(
        label='Language',
        required=False,
        choices=[('', '')] + langcodes.get_all_langs_for_select(),
        widget=LanguageSelect()
    )

    def __init__(self, *args, **kwargs):
        self.helper = FormHelper()
        self.helper.form_class = 'form-horizontal'
        self.helper.form_id = 'id-scheduledReportForm'
        self.helper.add_layout(
            crispy.Layout(
                'config_ids',
                crispy.Field('interval', data_bind='value: interval'),
                crispy.Field('day', data_bind='value: day'),
                'hour',
                crispy.Div(
                    crispy.Field('n_weeks', data_bind='value: nWeeks'),
                    crispy.Field('offset_weeks', data_bind=(
github dimagi / commcare-hq / corehq / apps / settings / views.py View on Github external
def settings_form(self):
        language_choices = langcodes.get_all_langs_for_select()
        api_key = self.get_or_create_api_key()
        from corehq.apps.users.forms import UpdateMyAccountInfoForm
        try:
            domain = self.request.domain
        except AttributeError:
            domain = ''
        if self.request.method == 'POST':
            form = UpdateMyAccountInfoForm(
                self.request.POST,
                api_key=api_key,
                domain=domain,
                existing_user=self.request.couch_user,
            )
        else:
            form = UpdateMyAccountInfoForm(
                api_key=api_key,
github dimagi / commcare-hq / corehq / apps / users / views / __init__.py View on Github external
'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()