From 9c78c8f744eaedf3af1dddc396f193365505c53a Mon Sep 17 00:00:00 2001 From: Oire Date: Mon, 24 Jun 2013 00:09:43 +0300 Subject: [PATCH] Fixed fromNow without suffix in German, should fix #842 --- lang/de.js | 31 +++++++++++++++++++++++-------- test/lang/de.js | 48 ++++++++++++++++++++++++------------------------ 2 files changed, 47 insertions(+), 32 deletions(-) diff --git a/lang/de.js b/lang/de.js index 404dd9875..e809ba28d 100644 --- a/lang/de.js +++ b/lang/de.js @@ -1,6 +1,21 @@ // moment.js language configuration // language : german (de) // author : lluchs : https://github.com/lluchs +// author: Menelion Elensúle: https://github.com/Oire + +function processRelativeTime(number, withoutSuffix, key, isFuture) { + var format = { + 'm': ['eine Minute', 'einer Minute'], + 'h': ['eine Stunde', 'einer Stunde'], + 'd': ['ein Tag', 'einem Tag'], + 'dd': [number + ' Tage', number + ' Tagen'], + 'M': ['ein Monat', 'einem Monat'], + 'MM': [number + ' Monate', number + ' Monaten'], + 'y': ['ein Jahr', 'einem Jahr'], + 'yy': [number + ' Jahre', number + ' Jahren'] + }; + return withoutSuffix ? format[key][0] : format[key][1]; +} require('../moment').lang('de', { months : "Januar_Februar_März_April_Mai_Juni_Juli_August_September_Oktober_November_Dezember".split("_"), @@ -27,16 +42,16 @@ require('../moment').lang('de', { future : "in %s", past : "vor %s", s : "ein paar Sekunden", - m : "einer Minute", + m : processRelativeTime, mm : "%d Minuten", - h : "einer Stunde", + h : processRelativeTime, hh : "%d Stunden", - d : "einem Tag", - dd : "%d Tagen", - M : "einem Monat", - MM : "%d Monaten", - y : "einem Jahr", - yy : "%d Jahren" + d : processRelativeTime, + dd : processRelativeTime, + M : processRelativeTime, + MM : processRelativeTime, + y : processRelativeTime, + yy : processRelativeTime }, ordinal : '%d.', week : { diff --git a/test/lang/de.js b/test/lang/de.js index 35ac1a9b2..25e60a425 100644 --- a/test/lang/de.js +++ b/test/lang/de.js @@ -139,35 +139,35 @@ exports["lang:de"] = { test.expect(30); var start = moment([2007, 1, 28]); test.equal(start.from(moment([2007, 1, 28]).add({s:44}), true), "ein paar Sekunden", "44 seconds = a few seconds"); - test.equal(start.from(moment([2007, 1, 28]).add({s:45}), true), "einer Minute", "45 seconds = a minute"); - test.equal(start.from(moment([2007, 1, 28]).add({s:89}), true), "einer Minute", "89 seconds = a minute"); + test.equal(start.from(moment([2007, 1, 28]).add({s:45}), true), "eine Minute", "45 seconds = a minute"); + test.equal(start.from(moment([2007, 1, 28]).add({s:89}), true), "eine Minute", "89 seconds = a minute"); test.equal(start.from(moment([2007, 1, 28]).add({s:90}), true), "2 Minuten", "90 seconds = 2 minutes"); test.equal(start.from(moment([2007, 1, 28]).add({m:44}), true), "44 Minuten", "44 minutes = 44 minutes"); - test.equal(start.from(moment([2007, 1, 28]).add({m:45}), true), "einer Stunde", "45 minutes = an hour"); - test.equal(start.from(moment([2007, 1, 28]).add({m:89}), true), "einer Stunde", "89 minutes = an hour"); + test.equal(start.from(moment([2007, 1, 28]).add({m:45}), true), "eine Stunde", "45 minutes = an hour"); + test.equal(start.from(moment([2007, 1, 28]).add({m:89}), true), "eine Stunde", "89 minutes = an hour"); test.equal(start.from(moment([2007, 1, 28]).add({m:90}), true), "2 Stunden", "90 minutes = 2 hours"); test.equal(start.from(moment([2007, 1, 28]).add({h:5}), true), "5 Stunden", "5 hours = 5 hours"); test.equal(start.from(moment([2007, 1, 28]).add({h:21}), true), "21 Stunden", "21 hours = 21 hours"); - test.equal(start.from(moment([2007, 1, 28]).add({h:22}), true), "einem Tag", "22 hours = a day"); - test.equal(start.from(moment([2007, 1, 28]).add({h:35}), true), "einem Tag", "35 hours = a day"); - test.equal(start.from(moment([2007, 1, 28]).add({h:36}), true), "2 Tagen", "36 hours = 2 days"); - test.equal(start.from(moment([2007, 1, 28]).add({d:1}), true), "einem Tag", "1 day = a day"); - test.equal(start.from(moment([2007, 1, 28]).add({d:5}), true), "5 Tagen", "5 days = 5 days"); - test.equal(start.from(moment([2007, 1, 28]).add({d:25}), true), "25 Tagen", "25 days = 25 days"); - test.equal(start.from(moment([2007, 1, 28]).add({d:26}), true), "einem Monat", "26 days = a month"); - test.equal(start.from(moment([2007, 1, 28]).add({d:30}), true), "einem Monat", "30 days = a month"); - test.equal(start.from(moment([2007, 1, 28]).add({d:45}), true), "einem Monat", "45 days = a month"); - test.equal(start.from(moment([2007, 1, 28]).add({d:46}), true), "2 Monaten", "46 days = 2 months"); - test.equal(start.from(moment([2007, 1, 28]).add({d:74}), true), "2 Monaten", "75 days = 2 months"); - test.equal(start.from(moment([2007, 1, 28]).add({d:76}), true), "3 Monaten", "76 days = 3 months"); - test.equal(start.from(moment([2007, 1, 28]).add({M:1}), true), "einem Monat", "1 month = a month"); - test.equal(start.from(moment([2007, 1, 28]).add({M:5}), true), "5 Monaten", "5 months = 5 months"); - test.equal(start.from(moment([2007, 1, 28]).add({d:344}), true), "11 Monaten", "344 days = 11 months"); - test.equal(start.from(moment([2007, 1, 28]).add({d:345}), true), "einem Jahr", "345 days = a year"); - test.equal(start.from(moment([2007, 1, 28]).add({d:547}), true), "einem Jahr", "547 days = a year"); - test.equal(start.from(moment([2007, 1, 28]).add({d:548}), true), "2 Jahren", "548 days = 2 years"); - test.equal(start.from(moment([2007, 1, 28]).add({y:1}), true), "einem Jahr", "1 year = a year"); - test.equal(start.from(moment([2007, 1, 28]).add({y:5}), true), "5 Jahren", "5 years = 5 years"); + test.equal(start.from(moment([2007, 1, 28]).add({h:22}), true), "ein Tag", "22 hours = a day"); + test.equal(start.from(moment([2007, 1, 28]).add({h:35}), true), "ein Tag", "35 hours = a day"); + test.equal(start.from(moment([2007, 1, 28]).add({h:36}), true), "2 Tage", "36 hours = 2 days"); + test.equal(start.from(moment([2007, 1, 28]).add({d:1}), true), "ein Tag", "1 day = a day"); + test.equal(start.from(moment([2007, 1, 28]).add({d:5}), true), "5 Tage", "5 days = 5 days"); + test.equal(start.from(moment([2007, 1, 28]).add({d:25}), true), "25 Tage", "25 days = 25 days"); + test.equal(start.from(moment([2007, 1, 28]).add({d:26}), true), "ein Monat", "26 days = a month"); + test.equal(start.from(moment([2007, 1, 28]).add({d:30}), true), "ein Monat", "30 days = a month"); + test.equal(start.from(moment([2007, 1, 28]).add({d:45}), true), "ein Monat", "45 days = a month"); + test.equal(start.from(moment([2007, 1, 28]).add({d:46}), true), "2 Monate", "46 days = 2 months"); + test.equal(start.from(moment([2007, 1, 28]).add({d:74}), true), "2 Monate", "75 days = 2 months"); + test.equal(start.from(moment([2007, 1, 28]).add({d:76}), true), "3 Monate", "76 days = 3 months"); + test.equal(start.from(moment([2007, 1, 28]).add({M:1}), true), "ein Monat", "1 month = a month"); + test.equal(start.from(moment([2007, 1, 28]).add({M:5}), true), "5 Monate", "5 months = 5 months"); + test.equal(start.from(moment([2007, 1, 28]).add({d:344}), true), "11 Monate", "344 days = 11 months"); + test.equal(start.from(moment([2007, 1, 28]).add({d:345}), true), "ein Jahr", "345 days = a year"); + test.equal(start.from(moment([2007, 1, 28]).add({d:547}), true), "ein Jahr", "547 days = a year"); + test.equal(start.from(moment([2007, 1, 28]).add({d:548}), true), "2 Jahre", "548 days = 2 years"); + test.equal(start.from(moment([2007, 1, 28]).add({y:1}), true), "ein Jahr", "1 year = a year"); + test.equal(start.from(moment([2007, 1, 28]).add({y:5}), true), "5 Jahre", "5 years = 5 years"); test.done(); }, -- 2.47.2