diff --git a/mainsite/settings/__init__.py b/mainsite/settings/__init__.py index 5cc2f66f..60e8bfde 100644 --- a/mainsite/settings/__init__.py +++ b/mainsite/settings/__init__.py @@ -1111,6 +1111,7 @@ set_option("NON_ZIPCODE_COUNTRIES", non_zipcode_countries()) ## Locale LANGUAGE_CODE = "en-us" +LANGUAGE_COOKIE_AGE = 31557600 # one year USE_I18N = True USE_L10N = True diff --git a/peeringdb_server/static/site.css b/peeringdb_server/static/site.css index bf6b3224..ab07a124 100644 --- a/peeringdb_server/static/site.css +++ b/peeringdb_server/static/site.css @@ -384,6 +384,12 @@ div.landing_search div.searchbox { width:100%; } +#anon-language-preference { + height:auto; + width:auto; + margin-bottom:5px; +} + div.landing_search div.searchbox input[type=submit] { font-size: 18px; font-weight: bold; diff --git a/peeringdb_server/templates/site/header.html b/peeringdb_server/templates/site/header.html index fa41b678..a188c475 100644 --- a/peeringdb_server/templates/site/header.html +++ b/peeringdb_server/templates/site/header.html @@ -72,6 +72,15 @@ $(window).bind("load", function() { url_request_authentication: "{% url "security-keys-request-authentication" %}" }); + $('#anon-language-preference').each(function(idx) { + $(this).on("change", function() { + Cookies.set('django_language', this.value, { expires: 365 }); // matches dj_settings.LANGUAGE_COOKIE_AGE + window.location.href=window.location.href; + window.location.reload(); + // Reload the current page, without using the cache + document.location.reload(true); + }) + }); }); @@ -99,38 +108,54 @@ $(window).bind("load", function() {
- {% trans "Set language preference" %}
diff --git a/peeringdb_server/views.py b/peeringdb_server/views.py index 20e56f4c..f4f51298 100644 --- a/peeringdb_server/views.py +++ b/peeringdb_server/views.py @@ -592,7 +592,11 @@ def view_set_user_locale(request): translation.activate(loc) response = JsonResponse({"status": "ok"}) - response.set_cookie(dj_settings.LANGUAGE_COOKIE_NAME, loc) + response.set_cookie( + dj_settings.LANGUAGE_COOKIE_NAME, + loc, + max_age=dj_settings.LANGUAGE_COOKIE_AGE, + ) return response @@ -3134,7 +3138,11 @@ class LoginView(TwoFactorLoginView): self.request.user, max_age=dj_settings.OAUTH_COOKIE_MAX_AGE, ) - response.set_cookie(dj_settings.LANGUAGE_COOKIE_NAME, user_language) + response.set_cookie( + dj_settings.LANGUAGE_COOKIE_NAME, + user_language, + max_age=dj_settings.LANGUAGE_COOKIE_AGE, + ) return response