]> git.openstreetmap.org Git - rails.git/blobdiff - app/assets/javascripts/application.js
Load pluralizers
[rails.git] / app / assets / javascripts / application.js
index 464bbecee17db7f7ded5ddcf115ff0dc2c13395b..c8f188a2e40f4163df77cef7c379109077d8b1e7 100644 (file)
 //= 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.locale = locale;
   I18n.fallbacks = true;
 
+  // '-' 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;
 
@@ -76,7 +83,7 @@ window.updateLinks = function (loc, zoom, layers, object) {
 
   // Disable the button group and also the buttons to avoid
   // inconsistent behaviour when zooming
-  var editDisabled = zoom < 13;
+  const editDisabled = zoom < 13;
   $("#edit_tab")
     .tooltip({ placement: "bottom" })
     .tooltip(editDisabled ? "enable" : "disable")
@@ -85,7 +92,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,8 +103,11 @@ $(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() {
-    var windowWidth = $(window).width();
+    const windowWidth = $(window).width();
 
     if (windowWidth < breakpointWidth) {
       $("body").addClass("small-nav");