diff --git a/README.md b/README.md index be38c2e..ecd2515 100644 --- a/README.md +++ b/README.md @@ -210,6 +210,7 @@ Currently we support following languages: * [Português - Brasil](src/Coduo/PHPHumanizer/Resources/translations/difference.pt_BR.yml) * [Italian](src/Coduo/PHPHumanizer/Resources/translations/difference.it.yml) * [Dutch](src/Coduo/PHPHumanizer/Resources/translations/difference.nl.yml) +* [Русский](src/Coduo/PHPHumanizer/Resources/translations/difference.ru.yml) * [Norwegian](src/Coduo/PHPHumanizer/Resources/translations/difference.no.yml) * [Afrikaans] (src/Coduo/PHPHumanizer/Resources/translations/difference.af.yml) * [Bulgarian] (src/Coduo/PHPHumanizer/Resources/translations/difference.bg.yml) diff --git a/spec/Coduo/PHPHumanizer/DateTime/PreciseFormatterSpec.php b/spec/Coduo/PHPHumanizer/DateTime/PreciseFormatterSpec.php new file mode 100644 index 0000000..40ea0f3 --- /dev/null +++ b/spec/Coduo/PHPHumanizer/DateTime/PreciseFormatterSpec.php @@ -0,0 +1,90 @@ +beConstructedWith($translator); + $translator->transChoice( + 'compound.day', + 10, + array('%count%' => 10), + 'difference', + 'en' + )->willReturn('10 days'); + + $translator->transChoice( + 'compound.hour', + 5, + array('%count%' => 5), + 'difference', + 'en' + )->willReturn('5 hours'); + + $translator->trans( + 'compound.future', + array('%value%' => '10 days, 5 hours'), + 'difference', + 'en' + )->willReturn('10 days, 5 hours from now'); + + $translator->transChoice( + 'compound.day', + 10, + array('%count%' => 10), + 'difference', + 'ru' + )->willReturn('10 дней'); + + $translator->transChoice( + 'compound.hour', + 5, + array('%count%' => 5), + 'difference', + 'ru' + )->willReturn('5 часов'); + + $translator->trans( + 'compound.future', + array('%value%' => '10 дней, 5 часов'), + 'difference', + 'ru' + )->willReturn('через 10 дней, 5 часов'); + } + + function it_format_compound_datetime_diff(PreciseDifference $diff, CompoundResult $dayResult, + CompoundResult $hourResult) + { + $dayResult->getUnit()->willReturn(new Day()); + $dayResult->getQuantity()->willReturn(10); + $hourResult->getUnit()->willReturn(new Hour()); + $hourResult->getQuantity()->willReturn(5); + + $diff->getCompoundResults()->willReturn(array($dayResult, $hourResult)); + $diff->isPast()->willReturn(false); + $this->formatDifference($diff)->shouldReturn('10 days, 5 hours from now'); + } + + function it_format_compound_datetime_diff_for_specific_locale(PreciseDifference $diff, + CompoundResult $dayResult, CompoundResult $hourResult) + { + $dayResult->getUnit()->willReturn(new Day()); + $dayResult->getQuantity()->willReturn(10); + $hourResult->getUnit()->willReturn(new Hour()); + $hourResult->getQuantity()->willReturn(5); + + $diff->getCompoundResults()->willReturn(array($dayResult, $hourResult)); + $diff->isPast()->willReturn(false); + $this->formatDifference($diff, 'ru')->shouldReturn('через 10 дней, 5 часов'); + } +} diff --git a/src/Coduo/PHPHumanizer/DateTime/PreciseFormatter.php b/src/Coduo/PHPHumanizer/DateTime/PreciseFormatter.php index 251a93c..7788683 100644 --- a/src/Coduo/PHPHumanizer/DateTime/PreciseFormatter.php +++ b/src/Coduo/PHPHumanizer/DateTime/PreciseFormatter.php @@ -31,15 +31,19 @@ public function formatDifference(PreciseDifference $difference, $locale = 'en') foreach ($difference->getCompoundResults() as $result) { $diff[] = $this->translator->transChoice( - 'compound.'.$result->getUnit()->getName(), + 'compound.' . $result->getUnit()->getName(), $result->getQuantity(), array('%count%' => $result->getQuantity()), 'difference', $locale ); } - $suffix = $difference->isPast() ? 'compound.ago' : 'compound.from_now'; - return implode(', ', $diff).' '.$this->translator->trans($suffix, array(), 'difference', $locale); + return $this->translator->trans( + 'compound.' . ($difference->isPast() ? 'past' : 'future'), + array('%value%' => implode(', ', $diff)), + 'difference', + $locale + ); } } diff --git a/src/Coduo/PHPHumanizer/Resources/translations/difference.af.yml b/src/Coduo/PHPHumanizer/Resources/translations/difference.af.yml index 77c6ed7..788457a 100644 --- a/src/Coduo/PHPHumanizer/Resources/translations/difference.af.yml +++ b/src/Coduo/PHPHumanizer/Resources/translations/difference.af.yml @@ -31,5 +31,5 @@ compound: week: "{1} %count% week|[2,Inf] %count% weke" month: "{1} %count% maand|[2,Inf] %count% maande" year: "{1} %count% jaar|[2,Inf] %count% jaar" - ago: "gelede" - from_now: "van nou af" + past: "%value% gelede" + future: "%value% van nou af" diff --git a/src/Coduo/PHPHumanizer/Resources/translations/difference.bg.yml b/src/Coduo/PHPHumanizer/Resources/translations/difference.bg.yml index 9e7fe54..9e035b3 100644 --- a/src/Coduo/PHPHumanizer/Resources/translations/difference.bg.yml +++ b/src/Coduo/PHPHumanizer/Resources/translations/difference.bg.yml @@ -31,5 +31,5 @@ compound: week: "{1} %count% седмица|[2,Inf] %count% седмица" month: "{1} %count% месец|[2,Inf] %count% месеца" year: "{1} %count% година|[2,Inf] %count% години" - ago: "преди това" - from_now: "след това" \ No newline at end of file + past: "%value% преди това" + future: "%value% след това" \ No newline at end of file diff --git a/src/Coduo/PHPHumanizer/Resources/translations/difference.de.yml b/src/Coduo/PHPHumanizer/Resources/translations/difference.de.yml index 0dcc736..8585f99 100644 --- a/src/Coduo/PHPHumanizer/Resources/translations/difference.de.yml +++ b/src/Coduo/PHPHumanizer/Resources/translations/difference.de.yml @@ -31,5 +31,5 @@ compound: week: "{1} %count% Woche|[2,Inf] %count% Wochen" month: "{1} %count% Monat|[2,Inf] %count% Monate" year: "{1} %count% Jahr|[2,Inf] %count% Jahre" - ago: "vor" - from_now: "ab jetzt" + past: "%value% vor" + future: "%value% ab jetzt" diff --git a/src/Coduo/PHPHumanizer/Resources/translations/difference.en.yml b/src/Coduo/PHPHumanizer/Resources/translations/difference.en.yml index 6a7534a..df245c7 100644 --- a/src/Coduo/PHPHumanizer/Resources/translations/difference.en.yml +++ b/src/Coduo/PHPHumanizer/Resources/translations/difference.en.yml @@ -31,5 +31,5 @@ compound: week: "{1} %count% week|[2,Inf] %count% weeks" month: "{1} %count% month|[2,Inf] %count% months" year: "{1} %count% year|[2,Inf] %count% years" - ago: "ago" - from_now: "from now" \ No newline at end of file + past: "%value% ago" + future: "%value% from now" \ No newline at end of file diff --git a/src/Coduo/PHPHumanizer/Resources/translations/difference.fr.yml b/src/Coduo/PHPHumanizer/Resources/translations/difference.fr.yml index fa1ce1a..1869933 100644 --- a/src/Coduo/PHPHumanizer/Resources/translations/difference.fr.yml +++ b/src/Coduo/PHPHumanizer/Resources/translations/difference.fr.yml @@ -31,5 +31,5 @@ compound: week: "{1} %count% semaine|[2,Inf] %count% semaines" month: "{1} %count% mois|[2,Inf] %count% mois" year: "{1} %count% année|[2,Inf] %count% années" - ago: "il y a" - from_now: "maintenant" + past: "%value% il y a" + future: "%value% maintenant" diff --git a/src/Coduo/PHPHumanizer/Resources/translations/difference.it.yml b/src/Coduo/PHPHumanizer/Resources/translations/difference.it.yml index ac3e622..e0f5de5 100644 --- a/src/Coduo/PHPHumanizer/Resources/translations/difference.it.yml +++ b/src/Coduo/PHPHumanizer/Resources/translations/difference.it.yml @@ -31,5 +31,5 @@ compound: week: "{1} %count% settimana|[2,Inf] %count% settimane" month: "{1} %count% mese|[2,Inf] %count% mesi" year: "{1} %count% anno|[2,Inf] %count% anni" - ago: "fa" - from_now: "da adesso" + past: "%value% fa" + future: "%value% da adesso" diff --git a/src/Coduo/PHPHumanizer/Resources/translations/difference.nl.yml b/src/Coduo/PHPHumanizer/Resources/translations/difference.nl.yml index 86aced4..cbabddd 100644 --- a/src/Coduo/PHPHumanizer/Resources/translations/difference.nl.yml +++ b/src/Coduo/PHPHumanizer/Resources/translations/difference.nl.yml @@ -31,5 +31,5 @@ compound: week: "{1} %count% week|[2,Inf] %count% weken" month: "{1} %count% maand|[2,Inf] %count% maanden" year: "{1} %count% jaar|[2,Inf] %count% jaren" - ago: "geleden" - from_now: "vanaf nu" \ No newline at end of file + past: "%value% geleden" + future: "%value% vanaf nu" \ No newline at end of file diff --git a/src/Coduo/PHPHumanizer/Resources/translations/difference.no.yml b/src/Coduo/PHPHumanizer/Resources/translations/difference.no.yml index 183dfe4..a2f4ffe 100644 --- a/src/Coduo/PHPHumanizer/Resources/translations/difference.no.yml +++ b/src/Coduo/PHPHumanizer/Resources/translations/difference.no.yml @@ -31,5 +31,5 @@ compound: week: "{1} %count% uke|[2,Inf] %count% uker" month: "{1} %count% måned|[2,Inf] %count% måneder" year: "{1} %count% år|[2,Inf] %count% år" - ago: "siden" - from_now: "fra nå" \ No newline at end of file + past: "%value% siden" + future: "%value% fra nå" \ No newline at end of file diff --git a/src/Coduo/PHPHumanizer/Resources/translations/difference.pl.yml b/src/Coduo/PHPHumanizer/Resources/translations/difference.pl.yml index 47b48c6..23be15d 100644 --- a/src/Coduo/PHPHumanizer/Resources/translations/difference.pl.yml +++ b/src/Coduo/PHPHumanizer/Resources/translations/difference.pl.yml @@ -31,5 +31,5 @@ compound: week: "{1} %count% tydzień|[2,4] %count% tygodnie|[5,Inf] %count% tygodni" month: "{1} %count% miesiąc|[2,4] %count% miesiące|[5,Inf] %count% miesięcy" year: "{1} %count% rok|[2,4] %count% lata|[5,Inf] %count% lat" - ago: "temu" - from_now: "od teraz" + past: "%value% temu" + future: "%value% od teraz" diff --git a/src/Coduo/PHPHumanizer/Resources/translations/difference.pt.yml b/src/Coduo/PHPHumanizer/Resources/translations/difference.pt.yml index b542d13..7fe2901 100644 --- a/src/Coduo/PHPHumanizer/Resources/translations/difference.pt.yml +++ b/src/Coduo/PHPHumanizer/Resources/translations/difference.pt.yml @@ -31,5 +31,5 @@ compound: week: "{1} %count% semana|[2,Inf] %count% semana" month: "{1} %count% mês|[2,Inf] %count% meses" year: "{1} %count% ano|[2,Inf] %count% anos" - ago: "atrás" - from_now: "a partir de agora" + past: "%value% atrás" + future: "%value% a partir de agora" diff --git a/src/Coduo/PHPHumanizer/Resources/translations/difference.pt_BR.yml b/src/Coduo/PHPHumanizer/Resources/translations/difference.pt_BR.yml index 570e55d..b771ff4 100644 --- a/src/Coduo/PHPHumanizer/Resources/translations/difference.pt_BR.yml +++ b/src/Coduo/PHPHumanizer/Resources/translations/difference.pt_BR.yml @@ -31,5 +31,5 @@ compound: week: "{1} %count% semana|[2,Inf] %count% semana" month: "{1} %count% mês|[2,Inf] %count% meses" year: "{1} %count% ano|[2,Inf] %count% anos" - ago: "atrás" - from_now: "a partir de agora" + past: "%value% atrás" + future: "%value% a partir de agora" diff --git a/src/Coduo/PHPHumanizer/Resources/translations/difference.ru.yml b/src/Coduo/PHPHumanizer/Resources/translations/difference.ru.yml new file mode 100644 index 0000000..ca33639 --- /dev/null +++ b/src/Coduo/PHPHumanizer/Resources/translations/difference.ru.yml @@ -0,0 +1,35 @@ +just_now: + past: "[0,Inf] сейчас" + future: "[0,Inf] сейчас" +second: + past: "%count% секунду назад|%count% секунды назад|%count% секунд назад" + future: "через %count% секунду|через %count% секунды|через %count% секунд" +minute: + past: "%count% минуту назад|%count% минуты назад|%count% минут назад" + future: "через %count% минуту|через %count% минуты|через %count% минут" +hour: + past: "%count% час назад|через %count% часа|%count% часов назад" + future: "через %count% час|через %count% часа|через %count% часов" +day: + past: "%count% день назад|%count% дня назад|%count% дней назад" + future: "через %count% день|через %count% дня|через %count% дней" +week: + past: "%count% неделю назад|%count% недели назад|%count% недель назад" + future: "через %count% неделю|через %count% недели|через %count% недель" +month: + past: "%count% месяц назад|%count% месяца назад|%count% месяцев назад" + future: "через %count% месяц|через %count% месяца|через %count% месяцев" +year: + past: "%count% год назад|%count% года назад|%count% лет назад" + future: "через %count% год|через %count% года|через %count% лет" + +compound: + second: "%count% секунда|%count% секунды|%count% секунд" + minute: "%count% минута|%count% минуты|%count% минут" + hour: "%count% час|%count% часа|%count% часов" + day: "%count% день|%count% дня|%count% дней" + week: "%count% неделя|%count% недели|%count% недель" + month: "%count% месяц|%count% месяца|%count% месяцев" + year: "%count% год|%count% года|%count% лет" + past: "%value% назад" + future: "через %value%" \ No newline at end of file diff --git a/src/Coduo/PHPHumanizer/Resources/translations/difference.tr.yml b/src/Coduo/PHPHumanizer/Resources/translations/difference.tr.yml index a283f2d..8573ef9 100644 --- a/src/Coduo/PHPHumanizer/Resources/translations/difference.tr.yml +++ b/src/Coduo/PHPHumanizer/Resources/translations/difference.tr.yml @@ -31,5 +31,5 @@ compound: week: "{1} %count% hafta|[2,Inf] %count% hafta" month: "{1} %count% ay|[2,Inf] %count% ay" year: "{1} %count% yıl|[2,Inf] %count% yıl" - ago: "önce" - from_now: "sonra" + past: "%value% önce" + future: "%value% sonra" diff --git a/src/Coduo/PHPHumanizer/Resources/translations/oxford.ru.yml b/src/Coduo/PHPHumanizer/Resources/translations/oxford.ru.yml new file mode 100644 index 0000000..903c661 --- /dev/null +++ b/src/Coduo/PHPHumanizer/Resources/translations/oxford.ru.yml @@ -0,0 +1,3 @@ +only_two: "%first% и %second%" +comma_separated: "%list% и %last%" +comma_separated_with_limit: "{1} %list% и ещё 1|[2,Inf] %list% и ещё %count%" \ No newline at end of file diff --git a/tests/Coduo/PHPHumanizer/Tests/CollectionTest.php b/tests/Coduo/PHPHumanizer/Tests/CollectionTest.php index 2ced098..358b5d2 100644 --- a/tests/Coduo/PHPHumanizer/Tests/CollectionTest.php +++ b/tests/Coduo/PHPHumanizer/Tests/CollectionTest.php @@ -36,6 +36,13 @@ public function oxfordCollectionProvider() array(array("Michal", "Norbert", "Lukasz"), 2, 'nl', 'Michal, Norbert, en 1 andere'), array(array("Michal", "Norbert", "Lukasz", "Pawel"), 2, 'nl', 'Michal, Norbert, en 2 andere'), array(array("Michal", "Norbert", "Lukasz", "Pawel"), null, 'nl', 'Michal, Norbert, Lukasz, en Pawel'), + + // Russian + array(array("Michal"), null, 'ru', 'Michal'), + array(array("Michal", "Norbert"), null, 'ru', 'Michal и Norbert'), + array(array("Michal", "Norbert", "Lukasz"), 2, 'ru', 'Michal, Norbert и ещё 1'), + array(array("Michal", "Norbert", "Lukasz", "Pawel"), 2, 'ru', 'Michal, Norbert и ещё 2'), + array(array("Michal", "Norbert", "Lukasz", "Pawel"), null, 'ru', 'Michal, Norbert, Lukasz и Pawel'), ); } } \ No newline at end of file diff --git a/tests/Coduo/PHPHumanizer/Tests/DateTimeTest.php b/tests/Coduo/PHPHumanizer/Tests/DateTimeTest.php index a993005..6665ff3 100644 --- a/tests/Coduo/PHPHumanizer/Tests/DateTimeTest.php +++ b/tests/Coduo/PHPHumanizer/Tests/DateTimeTest.php @@ -98,6 +98,25 @@ public function humanizeDataProvider() array("2014-05-01", "2014-04-01", 'преди 1 месец', 'bg'), array("2015-05-01", "2014-04-01", 'преди 1 година', 'bg'), array("2014-05-01", "2016-04-01", 'след 2 години', 'bg'), + + // Russian + array("2014-04-26 13:00:00", "2014-04-26 13:00:00", 'сейчас', 'ru'), + array("2014-04-26 13:00:00", "2014-04-26 13:00:05", 'через 5 секунд', 'ru'), + array("2014-04-26 13:00:00", "2014-04-26 12:59:00", '1 минуту назад', 'ru'), + array("2014-04-26 13:00:00", "2014-04-26 12:45:00", '15 минут назад', 'ru'), + array("2014-04-26 13:00:00", "2014-04-26 13:15:00", 'через 15 минут', 'ru'), + array("2014-04-26 13:00:00", "2014-04-26 14:00:00", 'через 1 час', 'ru'), + array("2014-04-26 13:00:00", "2014-04-26 15:00:00", 'через 2 часа', 'ru'), + array("2014-04-26 13:00:00", "2014-04-26 12:00:00", '1 час назад', 'ru'), + array("2014-04-26", "2014-04-25", '1 день назад', 'ru'), + array("2014-04-26", "2014-04-24", '2 дня назад', 'ru'), + array("2014-04-26", "2014-04-28", 'через 2 дня', 'ru'), + array("2014-04-01", "2014-04-15", 'через 2 недели', 'ru'), + array("2014-04-15", "2014-04-07", '1 неделю назад', 'ru'), + array("2014-01-01", "2014-04-01", 'через 3 месяца', 'ru'), + array("2014-05-01", "2014-04-01", '1 месяц назад', 'ru'), + array("2015-05-01", "2014-04-01", '1 год назад', 'ru'), + array("2014-05-01", "2016-04-01", 'через 2 года', 'ru'), ); } @@ -206,6 +225,16 @@ public function preciseDifferenceDataProvider() array("2014-04-26 13:00:00", "2014-04-28 23:00:00", '2 dae, 10 ure van nou af', 'af'), array("2014-04-26 13:00:00", "2014-04-25 11:20:00", '1 dag, 1 uur, 40 minute gelede', 'af'), array("2014-04-26 13:00:00", "2016-04-27 13:00:00", '2 jaar, 1 dag van nou af', 'af'), + + // Russian + array("2014-04-26 13:00:00", "2014-04-26 12:58:15", '1 минута, 45 секунд назад', 'ru'), + array("2014-04-26 13:00:00", "2014-04-26 11:20:00", '1 час, 40 минут назад', 'ru'), + array("2014-04-26 13:00:00", "2014-04-27 13:15:00", 'через 1 день, 15 минут', 'ru'), + array("2014-04-26 13:00:00", "2014-05-03 15:00:00", 'через 7 дней, 2 часа', 'ru'), + array("2014-04-26 13:00:00", "2015-04-28 17:00:00", 'через 1 год, 2 дня, 4 часа', 'ru'), + array("2014-04-26 13:00:00", "2014-04-28 23:00:00", 'через 2 дня, 10 часов', 'ru'), + array("2014-04-26 13:00:00", "2014-04-25 11:20:00", '1 день, 1 час, 40 минут назад', 'ru'), + array("2014-04-26 13:00:00", "2016-04-27 13:00:00", 'через 2 года, 1 день', 'ru'), ); } } \ No newline at end of file