]> git.openstreetmap.org Git - rails.git/blobdiff - app/assets/javascripts/application.js
Load pluralizers
[rails.git] / app / assets / javascripts / application.js
index 4c9aa8b91ad3950dc4bfac1f7ff252a1575b930e..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;
 
@@ -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,6 +103,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();