]> git.ipfire.org Git - thirdparty/moment.git/commitdiff
Added correct plural forms for Russian language 169/head
authorAlexander Hramov <alexander.hramov@gmail.com>
Sat, 18 Feb 2012 19:38:23 +0000 (23:38 +0400)
committerAlexander Hramov <alexander.hramov@gmail.com>
Sat, 18 Feb 2012 19:38:23 +0000 (23:38 +0400)
lang/ru.js
test/lang/ru.js

index 412d07e4aa3aafaa209691c5044a72d67ca09a91..b76d5cd691da06ec58682a158fbdad1e51ebb598 100644 (file)
@@ -1,5 +1,42 @@
 (function () {
-    var lang = {
+
+    var pluralRules = [
+        function (n) { return ((n % 10 === 1) && (n % 100 !== 11)); },
+        function (n) { return ((n % 10) >= 2 && (n % 10) <= 4 && ((n % 10) % 1) === 0) && ((n % 100) < 12 || (n % 100) > 14); },
+        function (n) { return ((n % 10) === 0 || ((n % 10) >= 5 && (n % 10) <= 9 && ((n % 10) % 1) === 0) || ((n % 100) >= 11 && (n % 100) <= 14 && ((n % 100) % 1) === 0)); },
+        function (n) { return true; }
+    ],
+
+    plural = function (word, num) {
+        var forms = word.split('_'),
+        minCount = Math.min(pluralRules.length, forms.length),
+        i = -1;
+
+        while (++i < minCount) {
+            if (pluralRules[i](num)) {
+                return forms[i];
+            }
+        }
+        return forms[minCount - 1];
+    },
+
+    relativeTimeWithPlural = function (number, withoutSuffix, key) {
+        var format = {
+            'mm': 'минута_минуты_минут_минуты',
+            'hh': 'час_часа_часов_часа',
+            'dd': 'день_дня_дней_дня',
+            'MM': 'месяц_месяца_месяцев_месяца',
+            'yy': 'год_года_лет_года'
+        };
+        if (key === 'm') {
+            return withoutSuffix ? 'минута' : 'минуту';
+        }
+        else {
+            return number + ' ' + plural(format[key], +number);
+        }
+    },
+
+    lang = {
             months : "январь_февраль_март_апрель_май_июнь_июль_август_сентябрь_октябрь_ноябрь_декабрь".split("_"),
             monthsShort : "янв_фев_мар_апр_май_июн_июл_авг_сен_окт_ноя_дек".split("_"),
             weekdays : "воскресенье_понедельник_вторник_среда_четверг_пятница_суббота".split("_"),
                 future : "через %s",
                 past : "%s назад",
                 s : "несколько секунд",
-                m : "минут",
-                mm : "%d минут",
-                h : "часа",
-                hh : "%d часов",
-                d : "день",
-                dd : "%d дней",
+                m : relativeTimeWithPlural,
+                mm : relativeTimeWithPlural,
+                h : "час",
+                hh : relativeTimeWithPlural,
+                d : "день",
+                dd : relativeTimeWithPlural,
                 M : "месяц",
-                MM : "%d месяцев",
+                MM : relativeTimeWithPlural,
                 y : "год",
-                yy : "%d лет"
+                yy : relativeTimeWithPlural
             },
             ordinal : function (number) {
                 return '.';
index b7c44f89a7b591c734163bd2526aa3b4adb7ee08..b37ad6f51e4ec18ca4ae2e6a75bc07bf0471a482 100644 (file)
@@ -126,33 +126,35 @@ exports["lang:ru"] = {
         moment.lang('ru');
         var start = moment([2007, 1, 28]);
         test.equal(start.from(moment([2007, 1, 28]).add({s:44}), true),  "несколько секунд",    "44 seconds = seconds");
-        test.equal(start.from(moment([2007, 1, 28]).add({s:45}), true),  "минут",   "45 seconds = a minute");
-        test.equal(start.from(moment([2007, 1, 28]).add({s:89}), true),  "минут",   "89 seconds = a minute");
-        test.equal(start.from(moment([2007, 1, 28]).add({s:90}), true),  "2 минут",  "90 seconds = 2 minutes");
-        test.equal(start.from(moment([2007, 1, 28]).add({m:44}), true),  "44 минут", "44 minutes = 44 minutes");
-        test.equal(start.from(moment([2007, 1, 28]).add({m:45}), true),  "часа",    "45 minutes = an hour");
-        test.equal(start.from(moment([2007, 1, 28]).add({m:89}), true),  "часа",    "89 minutes = an hour");
-        test.equal(start.from(moment([2007, 1, 28]).add({m:90}), true),  "2 Ñ\87аÑ\81ов",    "90 minutes = 2 hours");
+        test.equal(start.from(moment([2007, 1, 28]).add({s:45}), true),  "минута",   "45 seconds = a minute");
+        test.equal(start.from(moment([2007, 1, 28]).add({s:89}), true),  "минута",   "89 seconds = a minute");
+        test.equal(start.from(moment([2007, 1, 28]).add({s:90}), true),  "2 минуты",  "90 seconds = 2 minutes");
+        test.equal(start.from(moment([2007, 1, 28]).add({m:44}), true),  "44 минуты", "44 minutes = 44 minutes");
+        test.equal(start.from(moment([2007, 1, 28]).add({m:45}), true),  "час",    "45 minutes = an hour");
+        test.equal(start.from(moment([2007, 1, 28]).add({m:89}), true),  "час",    "89 minutes = an hour");
+        test.equal(start.from(moment([2007, 1, 28]).add({m:90}), true),  "2 Ñ\87аÑ\81а",    "90 minutes = 2 hours");
         test.equal(start.from(moment([2007, 1, 28]).add({h:5}), true),   "5 часов",    "5 hours = 5 hours");
-        test.equal(start.from(moment([2007, 1, 28]).add({h:21}), true),  "21 часов",   "21 hours = 21 hours");
+        test.equal(start.from(moment([2007, 1, 28]).add({h:21}), true),  "21 час",   "21 hours = 21 hours");
         test.equal(start.from(moment([2007, 1, 28]).add({h:22}), true),  "1 день",      "22 hours = a day");
         test.equal(start.from(moment([2007, 1, 28]).add({h:35}), true),  "1 день",      "35 hours = a day");
-        test.equal(start.from(moment([2007, 1, 28]).add({h:36}), true),  "2 дней",     "36 hours = 2 days");
+        test.equal(start.from(moment([2007, 1, 28]).add({h:36}), true),  "2 дня",     "36 hours = 2 days");
         test.equal(start.from(moment([2007, 1, 28]).add({d:1}), true),   "1 день",      "1 day = a day");
         test.equal(start.from(moment([2007, 1, 28]).add({d:5}), true),   "5 дней",     "5 days = 5 days");
+        test.equal(start.from(moment([2007, 1, 28]).add({d:11}), true),  "11 дней",     "11 days = 11 days");
+        test.equal(start.from(moment([2007, 1, 28]).add({d:21}), true),  "21 день",     "21 days = 21 days");
         test.equal(start.from(moment([2007, 1, 28]).add({d:25}), true),  "25 дней",    "25 days = 25 days");
         test.equal(start.from(moment([2007, 1, 28]).add({d:26}), true),  "месяц",    "26 days = a month");
         test.equal(start.from(moment([2007, 1, 28]).add({d:30}), true),  "месяц",    "30 days = a month");
         test.equal(start.from(moment([2007, 1, 28]).add({d:45}), true),  "месяц",    "45 days = a month");
-        test.equal(start.from(moment([2007, 1, 28]).add({d:46}), true),  "2 Ð¼ÐµÑ\81Ñ\8fÑ\86ев",   "46 days = 2 months");
-        test.equal(start.from(moment([2007, 1, 28]).add({d:74}), true),  "2 Ð¼ÐµÑ\81Ñ\8fÑ\86ев",   "75 days = 2 months");
-        test.equal(start.from(moment([2007, 1, 28]).add({d:76}), true),  "3 Ð¼ÐµÑ\81Ñ\8fÑ\86ев",   "76 days = 3 months");
+        test.equal(start.from(moment([2007, 1, 28]).add({d:46}), true),  "2 Ð¼ÐµÑ\81Ñ\8fÑ\86а",   "46 days = 2 months");
+        test.equal(start.from(moment([2007, 1, 28]).add({d:74}), true),  "2 Ð¼ÐµÑ\81Ñ\8fÑ\86а",   "75 days = 2 months");
+        test.equal(start.from(moment([2007, 1, 28]).add({d:76}), true),  "3 Ð¼ÐµÑ\81Ñ\8fÑ\86а",   "76 days = 3 months");
         test.equal(start.from(moment([2007, 1, 28]).add({M:1}), true),   "месяц",    "1 month = a month");
         test.equal(start.from(moment([2007, 1, 28]).add({M:5}), true),   "5 месяцев",   "5 months = 5 months");
         test.equal(start.from(moment([2007, 1, 28]).add({d:344}), true), "11 месяцев",  "344 days = 11 months");
         test.equal(start.from(moment([2007, 1, 28]).add({d:345}), true), "год",     "345 days = a year");
         test.equal(start.from(moment([2007, 1, 28]).add({d:547}), true), "год",     "547 days = a year");
-        test.equal(start.from(moment([2007, 1, 28]).add({d:548}), true), "2 Ð»ÐµÑ\82",    "548 days = 2 years");
+        test.equal(start.from(moment([2007, 1, 28]).add({d:548}), true), "2 Ð³Ð¾Ð´Ð°",    "548 days = 2 years");
         test.equal(start.from(moment([2007, 1, 28]).add({y:1}), true),   "год",     "1 year = a year");
         test.equal(start.from(moment([2007, 1, 28]).add({y:5}), true),   "5 лет",    "5 years = 5 years");
         test.done();