def __init__(self, *args, **kwargs):
super(UserSettingsForm, self).__init__(*args, **kwargs)
# Languages
def get_language_display_name(code, desc):
try:
desc = translation.get_language_info(code)['name_local']
desc = string.capwords(desc)
except KeyError:
# If a language is not defined in django.conf.locale.LANG_INFO
# get_language_info raises KeyError
pass
return "%s (%s)" % (desc, code)
languages = [(k, get_language_display_name(k, v))
for k, v in settings.LANGUAGES]
self.fields['language'].choices = languages
# Timezones
timezones = []
language = translation.get_language()
current_locale = translation.to_locale(language)
babel_locale = babel.Locale.parse(current_locale)
for tz, offset in self._sorted_zones():
try:
utc_offset = _("UTC %(hour)s:%(min)s") % {"hour": offset[:3],
"min": offset[3:]}
except Exception:
utc_offset = ""
if tz == "UTC":
tz_name = _("UTC")
elif tz == "GMT":
tz_name = _("GMT")
else:
tz_label = babel.dates.get_timezone_location(
tz, locale=babel_locale)
# Translators: UTC offset and timezone label
tz_name = _("%(offset)s: %(label)s") % {"offset": utc_offset,
"label": tz_label}
timezones.append((tz, tz_name))
self.fields['timezone'].choices = timezones
# When we define a help_text using any variable together with
# form field, traslation does not work well.
# To avoid this, we define here. (#1563021)
self.fields['pagesize'].help_text = (
_("Number of items to show per page (applies to the pages "
"that have API supported pagination, Max Value: %s)")
% self.max_value)
评论列表
文章目录