X-Git-Url: https://git.openstreetmap.org./rails.git/blobdiff_plain/d095dfe3d4c1ec90cebdfb3307564022cbeaf878..84fc41716298c24e7ed2ce5d96d4abe9c75fe94b:/app/assets/javascripts/application.js?ds=inline diff --git a/app/assets/javascripts/application.js b/app/assets/javascripts/application.js index 4c9aa8b91..4991e82fb 100644 --- a/app/assets/javascripts/application.js +++ b/app/assets/javascripts/application.js @@ -11,16 +11,22 @@ //= require leaflet.zoom //= require leaflet.locationfilter //= require i18n -//= require oauth +//= require make-plural/cardinals //= require matomo //= require richtext { const application_data = $("head").data(); + const locale = application_data.locale; I18n.default_locale = OSM.DEFAULT_LOCALE; - I18n.locale = application_data.locale; - I18n.fallbacks = true; + I18n.locale = locale; + + // '-' are replaced with '_' in https://github.com/eemeli/make-plural/tree/main/packages/plurals + const pluralizer = plurals[locale.replace(/\W+/g, "_")] || plurals[locale.split("-")[0]]; + if (pluralizer) { + I18n.pluralization[locale] = (count) => [pluralizer(count), "other"]; + } OSM.preferred_editor = application_data.preferredEditor; OSM.preferred_languages = application_data.preferredLanguages; @@ -85,7 +91,7 @@ window.updateLinks = function (loc, zoom, layers, object) { .toggleClass("disabled", editDisabled); }; -$(document).ready(function () { +$(function () { // NB: Turns Turbo Drive off by default. Turbo Drive must be opt-in on a per-link and per-form basis // See https://turbo.hotwired.dev/reference/drive#turbo.session.drive Turbo.session.drive = false; @@ -96,6 +102,9 @@ $(document).ready(function () { breakpointWidth = 768; let moreItemWidth = 0; + OSM.csrf = {}; + OSM.csrf[($("meta[name=csrf-param]").attr("content"))] = $("meta[name=csrf-token]").attr("content"); + function updateHeader() { const windowWidth = $(window).width();