Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add russian. Add prefix at format difference. #41

Merged
merged 7 commits into from
Nov 3, 2015
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
90 changes: 90 additions & 0 deletions spec/Coduo/PHPHumanizer/DateTime/PreciseFormatterSpec.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
<?php

namespace spec\Coduo\PHPHumanizer\DateTime;

use Coduo\PHPHumanizer\DateTime\PreciseDifference;
use Coduo\PHPHumanizer\DateTime\Difference\CompoundResult;
use Coduo\PHPHumanizer\DateTime\Unit\Day;
use Coduo\PHPHumanizer\DateTime\Unit\Hour;
use PhpSpec\ObjectBehavior;
use Prophecy\Argument;
use Symfony\Component\Translation\Translator;

class PreciseFormatterSpec extends ObjectBehavior
{
function let(Translator $translator)
{
$this->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 часов');
}
}
10 changes: 8 additions & 2 deletions src/Coduo/PHPHumanizer/DateTime/PreciseFormatter.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,14 @@ public function formatDifference(PreciseDifference $difference, $locale = 'en')
$locale
);
}
$suffix = $difference->isPast() ? 'compound.ago' : 'compound.from_now';

return implode(', ', $diff).' '.$this->translator->trans($suffix, array(), 'difference', $locale);
$translationKey = $difference->isPast() ? 'past' : 'future';

return $this->translator->trans(
'compound.' . $translationKey,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need for $translationKey, 'compound.' . $difference->isPast() ? 'past' : 'future' its enoguh

array('%value%' => implode(', ', $diff)),
'difference',
$locale
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Original file line number Diff line number Diff line change
Expand Up @@ -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: "след това"
past: "%value% преди това"
future: "%value% след това"
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Original file line number Diff line number Diff line change
Expand Up @@ -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"
past: "%value% ago"
future: "%value% from now"
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Original file line number Diff line number Diff line change
Expand Up @@ -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"
past: "%value% geleden"
future: "%value% vanaf nu"
Original file line number Diff line number Diff line change
Expand Up @@ -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å"
past: "%value% siden"
future: "%value% fra nå"
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

future is missing here.

35 changes: 35 additions & 0 deletions src/Coduo/PHPHumanizer/Resources/translations/difference.ru.yml
Original file line number Diff line number Diff line change
@@ -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%"
Original file line number Diff line number Diff line change
Expand Up @@ -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"
3 changes: 3 additions & 0 deletions src/Coduo/PHPHumanizer/Resources/translations/oxford.ru.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
only_two: "%first% и %second%"
comma_separated: "%list% и %last%"
comma_separated_with_limit: "{1} %list% и ещё 1|[2,Inf] %list% и ещё %count%"
7 changes: 7 additions & 0 deletions tests/Coduo/PHPHumanizer/Tests/CollectionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'),
);
}
}
29 changes: 29 additions & 0 deletions tests/Coduo/PHPHumanizer/Tests/DateTimeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'),
);
}

Expand Down Expand Up @@ -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'),
);
}
}