From 5d328c56d4f7ab77dc1233171a4cc208c53d28e7 Mon Sep 17 00:00:00 2001 From: Semen Dubina Date: Fri, 30 Oct 2015 04:51:40 +0300 Subject: [PATCH 1/5] Add russian. Add prefix at format difference. --- spec/Coduo/PHPHumanizer/CollectionSpec.php | 15 +++++++ spec/Coduo/PHPHumanizer/DateTimeSpec.php | 45 +++++++++++++++++++ .../DateTime/PreciseFormatter.php | 19 +++++++- .../Resources/translations/difference.ru.yml | 35 +++++++++++++++ .../Resources/translations/oxford.ru.yml | 3 ++ 5 files changed, 115 insertions(+), 2 deletions(-) create mode 100644 src/Coduo/PHPHumanizer/Resources/translations/difference.ru.yml create mode 100644 src/Coduo/PHPHumanizer/Resources/translations/oxford.ru.yml diff --git a/spec/Coduo/PHPHumanizer/CollectionSpec.php b/spec/Coduo/PHPHumanizer/CollectionSpec.php index 8e9a6fa..0bae7b0 100644 --- a/spec/Coduo/PHPHumanizer/CollectionSpec.php +++ b/spec/Coduo/PHPHumanizer/CollectionSpec.php @@ -50,4 +50,19 @@ function it_humanizes_collections_for_dutch_locale() $this->oxford($example[0], $example[1], 'nl')->shouldReturn($example[2]); } } + + function it_humanizes_collections_for_russian_locale() + { + $examples = array( + array(array("Michal"), null, 'Michal'), + array(array("Michal", "Norbert"), null, 'Michal и Norbert'), + array(array("Michal", "Norbert", "Lukasz"), 2, 'Michal, Norbert и ещё 1'), + array(array("Michal", "Norbert", "Lukasz", "Pawel"), 2, 'Michal, Norbert и ещё 2'), + array(array("Michal", "Norbert", "Lukasz", "Pawel"), null, 'Michal, Norbert, Lukasz и Pawel'), + ); + + foreach ($examples as $example) { + $this->oxford($example[0], $example[1], 'ru')->shouldReturn($example[2]); + } + } } diff --git a/spec/Coduo/PHPHumanizer/DateTimeSpec.php b/spec/Coduo/PHPHumanizer/DateTimeSpec.php index 009cd8b..8a96074 100644 --- a/spec/Coduo/PHPHumanizer/DateTimeSpec.php +++ b/spec/Coduo/PHPHumanizer/DateTimeSpec.php @@ -121,6 +121,33 @@ function it_humanize_difference_between_dates_for_pt_locale() } } + function it_humanize_difference_between_dates_for_ru_locale() + { + $examples = array( + array("2014-04-26 13:00:00", "2014-04-26 13:00:00", 'сейчас'), + array("2014-04-26 13:00:00", "2014-04-26 13:00:05", 'через 5 секунд'), + array("2014-04-26 13:00:00", "2014-04-26 12:59:00", '1 минуту назад'), + array("2014-04-26 13:00:00", "2014-04-26 12:45:00", '15 минут назад'), + array("2014-04-26 13:00:00", "2014-04-26 13:15:00", 'через 15 минут'), + array("2014-04-26 13:00:00", "2014-04-26 14:00:00", 'через 1 час'), + array("2014-04-26 13:00:00", "2014-04-26 15:00:00", 'через 2 часа'), + array("2014-04-26 13:00:00", "2014-04-26 12:00:00", '1 час назад'), + array("2014-04-26", "2014-04-25", '1 день назад'), + array("2014-04-26", "2014-04-24", '2 дня назад'), + array("2014-04-26", "2014-04-28", 'через 2 дня'), + array("2014-04-01", "2014-04-15", 'через 2 недели'), + array("2014-04-15", "2014-04-07", '1 неделю назад'), + array("2014-01-01", "2014-04-01", 'через 3 месяца'), + array("2014-05-01", "2014-04-01", '1 месяц назад'), + array("2015-05-01", "2014-04-01", '1 год назад'), + array("2014-05-01", "2016-04-01", 'через 2 года'), + ); + + foreach ($examples as $example) { + $this->difference(new \DateTime($example[0]), new \DateTime($example[1]), 'ru')->shouldReturn($example[2]); + } + } + function it_humanizes_precise_difference_between_dates() { $examples = array( @@ -299,4 +326,22 @@ function it_humanizes_precise_difference_between_dates_for_no_locale() $this->preciseDifference(new \DateTime($example[0]), new \DateTime($example[1]), 'no')->shouldReturn($example[2]); } } + + function it_humanizes_precise_difference_between_dates_for_ru_locale() + { + $examples = array( + array("2014-04-26 13:00:00", "2014-04-26 12:58:15", '1 минута, 45 секунд назад'), + array("2014-04-26 13:00:00", "2014-04-26 11:20:00", '1 час, 40 минут назад'), + array("2014-04-26 13:00:00", "2014-04-27 13:15:00", 'через 1 день, 15 минут'), + array("2014-04-26 13:00:00", "2014-05-03 15:00:00", 'через 7 дней, 2 часа'), + array("2014-04-26 13:00:00", "2015-04-28 17:00:00", 'через 1 год, 2 дня, 4 часа'), + array("2014-04-26 13:00:00", "2014-04-28 23:00:00", 'через 2 дня, 10 часов'), + array("2014-04-26 13:00:00", "2014-04-25 11:20:00", '1 день, 1 час, 40 минут назад'), + array("2014-04-26 13:00:00", "2016-04-27 13:00:00", 'через 2 года, 1 день'), + ); + + foreach ($examples as $example) { + $this->preciseDifference(new \DateTime($example[0]), new \DateTime($example[1]), 'ru')->shouldReturn($example[2]); + } + } } diff --git a/src/Coduo/PHPHumanizer/DateTime/PreciseFormatter.php b/src/Coduo/PHPHumanizer/DateTime/PreciseFormatter.php index 251a93c..e2f0b48 100644 --- a/src/Coduo/PHPHumanizer/DateTime/PreciseFormatter.php +++ b/src/Coduo/PHPHumanizer/DateTime/PreciseFormatter.php @@ -10,6 +10,7 @@ class PreciseFormatter * @var \Symfony\Component\Translation\TranslatorInterface */ private $translator; + private $locale = 'en'; /** * @param TranslatorInterface $translator @@ -29,6 +30,8 @@ public function formatDifference(PreciseDifference $difference, $locale = 'en') { $diff = array(); + $this->locale = $locale; + foreach ($difference->getCompoundResults() as $result) { $diff[] = $this->translator->transChoice( 'compound.'.$result->getUnit()->getName(), @@ -38,8 +41,20 @@ public function formatDifference(PreciseDifference $difference, $locale = 'en') $locale ); } - $suffix = $difference->isPast() ? 'compound.ago' : 'compound.from_now'; + $suffix = $this->calculateCompoud($difference); + $suffixString = empty($suffix) ? '':' '.$suffix; + + $prefix = $this->calculateCompoud($difference, '_prefix'); + $prefixString = empty($prefix) ? '':$prefix.' '; - return implode(', ', $diff).' '.$this->translator->trans($suffix, array(), 'difference', $locale); + return $prefixString . implode(', ', $diff) . $suffixString; + } + + private function calculateCompoud(PreciseDifference $difference, $suffixName = '') + { + $compound = $difference->isPast() ? 'compound.ago'.$suffixName : 'compound.from_now'.$suffixName; + $compoundString = $this->translator->trans($compound, array(), 'difference', $this->locale); + $compoundRes = substr_compare($compoundString, 'compound', 0, 8) ? $compoundString:''; + return $compoundRes; } } 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..1b30aa4 --- /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% лет" + ago: "назад" + from_now_prefix: "через" \ No newline at end of file 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 From 9c6bf240d98bf4ad60b7e7d0869f89ad3e472825 Mon Sep 17 00:00:00 2001 From: Semen Dubina Date: Fri, 30 Oct 2015 04:56:36 +0300 Subject: [PATCH 2/5] russian in readme --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index f7ba58a..ddd14ef 100644 --- a/README.md +++ b/README.md @@ -194,6 +194,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) # Credits From 06b0735959baa44ed99c1030716553de1210f5db Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juan=20Ram=C3=ADrez=20Ruiz?= Date: Sat, 31 Oct 2015 12:56:18 +0100 Subject: [PATCH 3/5] Added spec for PreciseFormatter. --- .../DateTime/PreciseFormatterSpec.php | 104 ++++++++++++++++++ .../DateTime/PreciseFormatter.php | 7 +- 2 files changed, 110 insertions(+), 1 deletion(-) create mode 100644 spec/Coduo/PHPHumanizer/DateTime/PreciseFormatterSpec.php diff --git a/spec/Coduo/PHPHumanizer/DateTime/PreciseFormatterSpec.php b/spec/Coduo/PHPHumanizer/DateTime/PreciseFormatterSpec.php new file mode 100644 index 0000000..cce0989 --- /dev/null +++ b/spec/Coduo/PHPHumanizer/DateTime/PreciseFormatterSpec.php @@ -0,0 +1,104 @@ +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.from_now', + array(), + 'difference', + 'en' + )->willReturn('from now'); + + $translator->trans( + 'compound.from_now_prefix', + array(), + 'difference', + 'en' + )->willReturn(''); + + $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.from_now', + array(), + 'difference', + 'ru' + )->willReturn(''); + + $translator->trans( + 'compound.from_now_prefix', + array(), + 'difference', + 'ru' + )->willReturn('через'); + } + + 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 e2f0b48..4230728 100644 --- a/src/Coduo/PHPHumanizer/DateTime/PreciseFormatter.php +++ b/src/Coduo/PHPHumanizer/DateTime/PreciseFormatter.php @@ -54,7 +54,12 @@ private function calculateCompoud(PreciseDifference $difference, $suffixName = ' { $compound = $difference->isPast() ? 'compound.ago'.$suffixName : 'compound.from_now'.$suffixName; $compoundString = $this->translator->trans($compound, array(), 'difference', $this->locale); - $compoundRes = substr_compare($compoundString, 'compound', 0, 8) ? $compoundString:''; + + if (strlen($compoundString) > 0) { + $compoundRes = substr_compare($compoundString, 'compound', 0, 8) ? $compoundString:''; + } else { + $compoundRes = ''; + } return $compoundRes; } } From 9104ef095693fc7b9c1f417b1ff205d7e02aa1fa Mon Sep 17 00:00:00 2001 From: Semen Dubina Date: Tue, 3 Nov 2015 02:33:09 +0300 Subject: [PATCH 4/5] Past/future compound formater for prefix precise. Rename: ago->past and from_now->future --- .../DateTime/PreciseFormatterSpec.php | 26 ++++------------- .../DateTime/PreciseFormatter.php | 28 +++++------------- .../Resources/translations/difference.af.yml | 4 +-- .../Resources/translations/difference.bg.yml | 4 +-- .../Resources/translations/difference.de.yml | 4 +-- .../Resources/translations/difference.en.yml | 4 +-- .../Resources/translations/difference.fr.yml | 4 +-- .../Resources/translations/difference.it.yml | 4 +-- .../Resources/translations/difference.nl.yml | 4 +-- .../Resources/translations/difference.no.yml | 4 +-- .../Resources/translations/difference.pl.yml | 4 +-- .../Resources/translations/difference.pt.yml | 4 +-- .../translations/difference.pt_BR.yml | 2 +- .../Resources/translations/difference.ru.yml | 4 +-- .../Resources/translations/difference.tr.yml | 4 +-- .../PHPHumanizer/Tests/CollectionTest.php | 7 +++++ .../Coduo/PHPHumanizer/Tests/DateTimeTest.php | 29 +++++++++++++++++++ 17 files changed, 74 insertions(+), 66 deletions(-) diff --git a/spec/Coduo/PHPHumanizer/DateTime/PreciseFormatterSpec.php b/spec/Coduo/PHPHumanizer/DateTime/PreciseFormatterSpec.php index cce0989..40ea0f3 100644 --- a/spec/Coduo/PHPHumanizer/DateTime/PreciseFormatterSpec.php +++ b/spec/Coduo/PHPHumanizer/DateTime/PreciseFormatterSpec.php @@ -32,18 +32,11 @@ function let(Translator $translator) )->willReturn('5 hours'); $translator->trans( - 'compound.from_now', - array(), + 'compound.future', + array('%value%' => '10 days, 5 hours'), 'difference', 'en' - )->willReturn('from now'); - - $translator->trans( - 'compound.from_now_prefix', - array(), - 'difference', - 'en' - )->willReturn(''); + )->willReturn('10 days, 5 hours from now'); $translator->transChoice( 'compound.day', @@ -62,18 +55,11 @@ function let(Translator $translator) )->willReturn('5 часов'); $translator->trans( - 'compound.from_now', - array(), - 'difference', - 'ru' - )->willReturn(''); - - $translator->trans( - 'compound.from_now_prefix', - array(), + 'compound.future', + array('%value%' => '10 дней, 5 часов'), 'difference', 'ru' - )->willReturn('через'); + )->willReturn('через 10 дней, 5 часов'); } function it_format_compound_datetime_diff(PreciseDifference $diff, CompoundResult $dayResult, diff --git a/src/Coduo/PHPHumanizer/DateTime/PreciseFormatter.php b/src/Coduo/PHPHumanizer/DateTime/PreciseFormatter.php index 4230728..fef065c 100644 --- a/src/Coduo/PHPHumanizer/DateTime/PreciseFormatter.php +++ b/src/Coduo/PHPHumanizer/DateTime/PreciseFormatter.php @@ -10,7 +10,6 @@ class PreciseFormatter * @var \Symfony\Component\Translation\TranslatorInterface */ private $translator; - private $locale = 'en'; /** * @param TranslatorInterface $translator @@ -30,8 +29,6 @@ public function formatDifference(PreciseDifference $difference, $locale = 'en') { $diff = array(); - $this->locale = $locale; - foreach ($difference->getCompoundResults() as $result) { $diff[] = $this->translator->transChoice( 'compound.'.$result->getUnit()->getName(), @@ -41,25 +38,14 @@ public function formatDifference(PreciseDifference $difference, $locale = 'en') $locale ); } - $suffix = $this->calculateCompoud($difference); - $suffixString = empty($suffix) ? '':' '.$suffix; - - $prefix = $this->calculateCompoud($difference, '_prefix'); - $prefixString = empty($prefix) ? '':$prefix.' '; - - return $prefixString . implode(', ', $diff) . $suffixString; - } - private function calculateCompoud(PreciseDifference $difference, $suffixName = '') - { - $compound = $difference->isPast() ? 'compound.ago'.$suffixName : 'compound.from_now'.$suffixName; - $compoundString = $this->translator->trans($compound, array(), 'difference', $this->locale); + $translationKey = $difference->isPast() ? 'past' : 'future'; - if (strlen($compoundString) > 0) { - $compoundRes = substr_compare($compoundString, 'compound', 0, 8) ? $compoundString:''; - } else { - $compoundRes = ''; - } - return $compoundRes; + return $this->translator->trans( + 'compound.' . $translationKey, + 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..d590ab4 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" + past: "%value% atrás" from_now: "a partir de agora" diff --git a/src/Coduo/PHPHumanizer/Resources/translations/difference.ru.yml b/src/Coduo/PHPHumanizer/Resources/translations/difference.ru.yml index 1b30aa4..ca33639 100644 --- a/src/Coduo/PHPHumanizer/Resources/translations/difference.ru.yml +++ b/src/Coduo/PHPHumanizer/Resources/translations/difference.ru.yml @@ -31,5 +31,5 @@ compound: week: "%count% неделя|%count% недели|%count% недель" month: "%count% месяц|%count% месяца|%count% месяцев" year: "%count% год|%count% года|%count% лет" - ago: "назад" - from_now_prefix: "через" \ 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.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/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 From 212711d7f8dd92a45721e50bea9cffa9dbbcc12b Mon Sep 17 00:00:00 2001 From: Semen Dubina Date: Tue, 3 Nov 2015 15:26:40 +0300 Subject: [PATCH 5/5] Fix compound.future for pt_BR. Inline key in PreciseFormatter. --- src/Coduo/PHPHumanizer/DateTime/PreciseFormatter.php | 6 ++---- .../Resources/translations/difference.pt_BR.yml | 2 +- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/src/Coduo/PHPHumanizer/DateTime/PreciseFormatter.php b/src/Coduo/PHPHumanizer/DateTime/PreciseFormatter.php index fef065c..7788683 100644 --- a/src/Coduo/PHPHumanizer/DateTime/PreciseFormatter.php +++ b/src/Coduo/PHPHumanizer/DateTime/PreciseFormatter.php @@ -31,7 +31,7 @@ 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', @@ -39,10 +39,8 @@ public function formatDifference(PreciseDifference $difference, $locale = 'en') ); } - $translationKey = $difference->isPast() ? 'past' : 'future'; - return $this->translator->trans( - 'compound.' . $translationKey, + 'compound.' . ($difference->isPast() ? 'past' : 'future'), array('%value%' => implode(', ', $diff)), 'difference', $locale diff --git a/src/Coduo/PHPHumanizer/Resources/translations/difference.pt_BR.yml b/src/Coduo/PHPHumanizer/Resources/translations/difference.pt_BR.yml index d590ab4..b771ff4 100644 --- a/src/Coduo/PHPHumanizer/Resources/translations/difference.pt_BR.yml +++ b/src/Coduo/PHPHumanizer/Resources/translations/difference.pt_BR.yml @@ -32,4 +32,4 @@ compound: month: "{1} %count% mês|[2,Inf] %count% meses" year: "{1} %count% ano|[2,Inf] %count% anos" past: "%value% atrás" - from_now: "a partir de agora" + future: "%value% a partir de agora"