Skip to content

Commit

Permalink
personal settings: add language auto-detect
Browse files Browse the repository at this point in the history
also: remove duplicate "en" entry.
  • Loading branch information
ThomasWaldmann committed Apr 9, 2024
1 parent 735f051 commit a5359c7
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions src/moin/apps/frontend/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@
from markupsafe import Markup

import pytz
from babel import Locale

from whoosh import sorting
from whoosh.query import Term, Prefix, And, Or, Not, DateRange, Every
Expand Down Expand Up @@ -2363,10 +2362,10 @@ class UserSettingsPersonalForm(Form):
# _timezones_keys = sorted(Locale('en').time_zones.keys())
_timezones_keys = [str(tz) for tz in pytz.common_timezones]
timezone = Select.using(label=L_("Timezone")).out_of((e, e) for e in _timezones_keys)
_supported_locales = [Locale("en")] + app.extensions["babel"].instance.list_translations()
_supported_locales = app.extensions["babel"].instance.list_translations()
locale = Select.using(label=L_("Locale")).out_of(
((str(locale), locale.display_name) for locale in _supported_locales), sort_by=1
)
[("auto", "---"), ] +
[(str(locale), locale.display_name) for locale in _supported_locales], sort_by=1)
submit_label = L_("Save")

class UserSettingsUIForm(Form):
Expand Down Expand Up @@ -2447,6 +2446,8 @@ class UserSettingsUIForm(Form):
user_old_email = flaskg.user.email
d = dict(form.value)
for k, v in d.items():
if k == "locale" and v == "auto":
v = None # None means "auto-detect language from http headers"
flaskg.user.profile[k] = v
if (
part == "notification"
Expand Down

0 comments on commit a5359c7

Please sign in to comment.