]> git.openstreetmap.org Git - rails.git/commitdiff
Load pluralizers
authorAnton Khorev <tony29@yandex.ru>
Tue, 11 Feb 2025 15:25:16 +0000 (18:25 +0300)
committerAnton Khorev <tony29@yandex.ru>
Tue, 4 Mar 2025 15:36:53 +0000 (18:36 +0300)
app/assets/javascripts/application.js
config/eslint.config.mjs
package.json
yarn.lock

index e07830d4ea7c7a010ffe5426732298997c5249aa..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;
 
index d695f0131db7b1f916cf42c64514ce64806f1dbe..a24dc08f5e62ffb2727efcd3c05c07003a7ec82a 100644 (file)
@@ -30,6 +30,7 @@ export default [
         Matomo: "readonly",
         OSM: "writable",
         Turbo: "readonly",
+        plurals: "readonly",
         updateLinks: "readonly"
       }
     },
index f8eac3db914233eda8262f34e18f2a05cd80be97..2a7eddd2bf9fa2b3edb3f6bf5d5c96abc7c03a71 100644 (file)
@@ -6,6 +6,7 @@
     "js-cookie": "^3.0.0",
     "leaflet": "^1.8.0",
     "leaflet.locatecontrol": "^0.83.0",
+    "make-plural": "^7.4.0",
     "osm-community-index": "^5.2.0"
   },
   "devDependencies": {
index bc2be6e82c0072db70dbdbd3bdabbc30774a2450..5f42ea7f27abd0d44cf72d43b23549a8c2077e2d 100644 (file)
--- a/yarn.lock
+++ b/yarn.lock
@@ -509,6 +509,11 @@ lodash.merge@^4.6.2:
   resolved "https://registry.yarnpkg.com/lodash.merge/-/lodash.merge-4.6.2.tgz#558aa53b43b661e1925a0afdfa36a9a1085fe57a"
   integrity sha512-0KpjqXRVvrYyCsX1swR/XTK0va6VQkQM6MNo7PqW77ByjAhoARA8EfrP1N4+KlKj8YS0ZUCtRT/YUuhyYDujIQ==
 
+make-plural@^7.4.0:
+  version "7.4.0"
+  resolved "https://registry.yarnpkg.com/make-plural/-/make-plural-7.4.0.tgz#fa6990dd550dea4de6b20163f74e5ed83d8a8d6d"
+  integrity sha512-4/gC9KVNTV6pvYg2gFeQYTW3mWaoJt7WZE5vrp1KnQDgW92JtYZnzmZT81oj/dUTqAIu0ufI2x3dkgu3bB1tYg==
+
 minimatch@^3.1.2:
   version "3.1.2"
   resolved "https://registry.yarnpkg.com/minimatch/-/minimatch-3.1.2.tgz#19cd194bfd3e428f049a70817c038d89ab4be35b"