]> git.openstreetmap.org Git - rails.git/blobdiff - app/assets/javascripts/application.js
Load pluralizers
[rails.git] / app / assets / javascripts / application.js
index 99bfede7e0b88ed292a7c45e722debc8fa1f01fb..c8f188a2e40f4163df77cef7c379109077d8b1e7 100644 (file)
 //= require leaflet.zoom
 //= require leaflet.locationfilter
 //= require i18n
+//= 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;
 
@@ -84,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;