def register_account_preferred_language_preferences(request): if len(get_available_admin_languages()) > 1: return { 'url': reverse('wagtailadmin_account_language_preferences'), 'label': _('Language preferences'), 'help_text': _('Choose the language you want to use here.'), }
def _get_language_choices(): language_choices = [ (lang_code, get_language_info(lang_code)["name_local"]) for lang_code, lang_name in get_available_admin_languages() ] return sorted(BLANK_CHOICE_DASH + language_choices, key=lambda l: l[1].lower())
def _add12hrFormats(): # Time12hrInput will not work unless django.forms.fields.TimeField # can process 12hr times, so sneak them into the default and all the # selectable locales that define TIME_INPUT_FORMATS. # strptime does not accept %P, %p is for both cases here. _12hrFormats = ['%I:%M%p', # 2:30pm '%I%p'] # 7am # TIME_INPUT_FORMATS is defined in django.conf.global_settings if not # by the user's local settings. if (_12hrFormats[0] not in settings.TIME_INPUT_FORMATS or _12hrFormats[1] not in settings.TIME_INPUT_FORMATS): settings.TIME_INPUT_FORMATS += _12hrFormats # Many of the built-in locales define TIME_INPUT_FORMATS langCodes = [language[0] for language in get_available_admin_languages()] langCodes.append(settings.LANGUAGE_CODE) for lang in langCodes: for module in get_format_modules(lang): inputFormats = getattr(module, 'TIME_INPUT_FORMATS', None) if (inputFormats is not None and (_12hrFormats[0] not in inputFormats or _12hrFormats[1] not in inputFormats)): inputFormats += _12hrFormats
def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) if len(get_available_admin_languages()) <= 1: del self.fields["preferred_language"] if len(get_available_admin_time_zones()) <= 1: del self.fields["current_time_zone"]
def test_available_admin_languages_by_default(self): self.assertListEqual(get_available_admin_languages(), WAGTAILADMIN_PROVIDED_LANGUAGES)
def test_available_admin_languages_with_permitted_languages(self): self.assertListEqual(get_available_admin_languages(), [('en', 'English'), ('es', 'Spanish')])
def _get_language_choices(): return sorted(BLANK_CHOICE_DASH + get_available_admin_languages(), key=lambda l: l[1].lower())
def test_available_admin_languages_with_permitted_languages(self): self.assertListEqual(get_available_admin_languages(), [("en", "English"), ("es", "Spanish")])
def is_active(self): return (len(get_available_admin_languages()) > 1 or len(get_available_admin_time_zones()) > 1)