diff --git a/app/assets/javascripts/application.js b/app/assets/javascripts/application.js index 4991e82fb..3ae4c20ee 100644 --- a/app/assets/javascripts/application.js +++ b/app/assets/javascripts/application.js @@ -14,6 +14,7 @@ //= require make-plural/cardinals //= require matomo //= require richtext +//= require language_selector { const application_data = $("head").data(); @@ -100,7 +101,8 @@ $(function () { $collapsedSecondaryMenu = $("#compact-secondary-nav > ul"), secondaryMenuItems = [], breakpointWidth = 768; - let moreItemWidth = 0; + let moreItemWidth = 0, + notCollapsibleItemsWidth = 0; OSM.csrf = {}; OSM.csrf[($("meta[name=csrf-param]").attr("content"))] = $("meta[name=csrf-token]").attr("content"); @@ -117,7 +119,7 @@ $(function () { secondaryMenuItems.forEach(function (item) { $(item[0]).remove(); }); - let runningWidth = 0, + let runningWidth = notCollapsibleItemsWidth, i = 0, requiredWidth; for (; i < secondaryMenuItems.length; i++) { @@ -176,10 +178,14 @@ $(function () { * to defer the measurement slightly as a workaround. */ setTimeout(function () { - $expandedSecondaryMenu.find("li:not(#compact-secondary-nav)").each(function () { + $expandedSecondaryMenu.find("li:not(#compact-secondary-nav):not(.not-collapsible)").each(function () { secondaryMenuItems.push([this, $(this).width()]); }); moreItemWidth = $("#compact-secondary-nav").width(); + notCollapsibleItemsWidth = $expandedSecondaryMenu + .find("li.not-collapsible") + .toArray() + .reduce((accWidth, item) => accWidth + $(item).outerWidth(), 0); updateHeader(); diff --git a/app/assets/javascripts/language_selector.js b/app/assets/javascripts/language_selector.js new file mode 100644 index 000000000..eac58e403 --- /dev/null +++ b/app/assets/javascripts/language_selector.js @@ -0,0 +1,4 @@ +$(document).on("change", ".language-change-trigger", function () { + Cookies.set("_osm_locale", this.value, { secure: true, path: "/", samesite: "lax" }); + document.location.reload(); +}); diff --git a/app/assets/stylesheets/common.scss b/app/assets/stylesheets/common.scss index 3ba484cd5..adb08b47a 100644 --- a/app/assets/stylesheets/common.scss +++ b/app/assets/stylesheets/common.scss @@ -52,6 +52,13 @@ time[title] { color: $blue; } +/* Utility for transparent color */ + +.text-transparent { + color: transparent !important; + user-select: none; +} + /* Bootstrap contextual table classes overrides in dark mode */ @include color-mode(dark) { diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 25de71f20..b286cd444 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -194,6 +194,8 @@ class ApplicationController < ActionController::Base Locale.list(params[:locale]) elsif current_user current_user.preferred_languages + elsif request.cookies["_osm_locale"] + Locale.list(request.cookies["_osm_locale"]) else Locale.list(http_accept_language.user_preferred_languages) end diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index c6e2298ab..427147121 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -205,7 +205,11 @@ class UsersController < ApplicationController current_user.data_public = true current_user.description = "" if current_user.description.nil? current_user.creation_address = request.remote_ip - current_user.languages = http_accept_language.user_preferred_languages + current_user.languages = if request.cookies["_osm_locale"] + Locale.list(request.cookies["_osm_locale"]) + else + http_accept_language.user_preferred_languages + end current_user.terms_agreed = Time.now.utc current_user.tou_agreed = Time.now.utc current_user.terms_seen = true diff --git a/app/views/layouts/_header.html.erb b/app/views/layouts/_header.html.erb index 69e323a99..d82858997 100644 --- a/app/views/layouts/_header.html.erb +++ b/app/views/layouts/_header.html.erb @@ -66,6 +66,15 @@
+