Skip to content

Commit a4d68a9

Browse files
author
Norbert Orzechowicz
committed
Merge pull request coduo#41 from sam002/master
Add russian. Add prefix at format difference.
2 parents 0465bd0 + 212711d commit a4d68a9

File tree

19 files changed

+196
-27
lines changed

19 files changed

+196
-27
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,7 @@ Currently we support following languages:
210210
* [Português - Brasil](src/Coduo/PHPHumanizer/Resources/translations/difference.pt_BR.yml)
211211
* [Italian](src/Coduo/PHPHumanizer/Resources/translations/difference.it.yml)
212212
* [Dutch](src/Coduo/PHPHumanizer/Resources/translations/difference.nl.yml)
213+
* [Русский](src/Coduo/PHPHumanizer/Resources/translations/difference.ru.yml)
213214
* [Norwegian](src/Coduo/PHPHumanizer/Resources/translations/difference.no.yml)
214215
* [Afrikaans] (src/Coduo/PHPHumanizer/Resources/translations/difference.af.yml)
215216
* [Bulgarian] (src/Coduo/PHPHumanizer/Resources/translations/difference.bg.yml)
Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
<?php
2+
3+
namespace spec\Coduo\PHPHumanizer\DateTime;
4+
5+
use Coduo\PHPHumanizer\DateTime\PreciseDifference;
6+
use Coduo\PHPHumanizer\DateTime\Difference\CompoundResult;
7+
use Coduo\PHPHumanizer\DateTime\Unit\Day;
8+
use Coduo\PHPHumanizer\DateTime\Unit\Hour;
9+
use PhpSpec\ObjectBehavior;
10+
use Prophecy\Argument;
11+
use Symfony\Component\Translation\Translator;
12+
13+
class PreciseFormatterSpec extends ObjectBehavior
14+
{
15+
function let(Translator $translator)
16+
{
17+
$this->beConstructedWith($translator);
18+
$translator->transChoice(
19+
'compound.day',
20+
10,
21+
array('%count%' => 10),
22+
'difference',
23+
'en'
24+
)->willReturn('10 days');
25+
26+
$translator->transChoice(
27+
'compound.hour',
28+
5,
29+
array('%count%' => 5),
30+
'difference',
31+
'en'
32+
)->willReturn('5 hours');
33+
34+
$translator->trans(
35+
'compound.future',
36+
array('%value%' => '10 days, 5 hours'),
37+
'difference',
38+
'en'
39+
)->willReturn('10 days, 5 hours from now');
40+
41+
$translator->transChoice(
42+
'compound.day',
43+
10,
44+
array('%count%' => 10),
45+
'difference',
46+
'ru'
47+
)->willReturn('10 дней');
48+
49+
$translator->transChoice(
50+
'compound.hour',
51+
5,
52+
array('%count%' => 5),
53+
'difference',
54+
'ru'
55+
)->willReturn('5 часов');
56+
57+
$translator->trans(
58+
'compound.future',
59+
array('%value%' => '10 дней, 5 часов'),
60+
'difference',
61+
'ru'
62+
)->willReturn('через 10 дней, 5 часов');
63+
}
64+
65+
function it_format_compound_datetime_diff(PreciseDifference $diff, CompoundResult $dayResult,
66+
CompoundResult $hourResult)
67+
{
68+
$dayResult->getUnit()->willReturn(new Day());
69+
$dayResult->getQuantity()->willReturn(10);
70+
$hourResult->getUnit()->willReturn(new Hour());
71+
$hourResult->getQuantity()->willReturn(5);
72+
73+
$diff->getCompoundResults()->willReturn(array($dayResult, $hourResult));
74+
$diff->isPast()->willReturn(false);
75+
$this->formatDifference($diff)->shouldReturn('10 days, 5 hours from now');
76+
}
77+
78+
function it_format_compound_datetime_diff_for_specific_locale(PreciseDifference $diff,
79+
CompoundResult $dayResult, CompoundResult $hourResult)
80+
{
81+
$dayResult->getUnit()->willReturn(new Day());
82+
$dayResult->getQuantity()->willReturn(10);
83+
$hourResult->getUnit()->willReturn(new Hour());
84+
$hourResult->getQuantity()->willReturn(5);
85+
86+
$diff->getCompoundResults()->willReturn(array($dayResult, $hourResult));
87+
$diff->isPast()->willReturn(false);
88+
$this->formatDifference($diff, 'ru')->shouldReturn('через 10 дней, 5 часов');
89+
}
90+
}

src/Coduo/PHPHumanizer/DateTime/PreciseFormatter.php

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,15 +31,19 @@ public function formatDifference(PreciseDifference $difference, $locale = 'en')
3131

3232
foreach ($difference->getCompoundResults() as $result) {
3333
$diff[] = $this->translator->transChoice(
34-
'compound.'.$result->getUnit()->getName(),
34+
'compound.' . $result->getUnit()->getName(),
3535
$result->getQuantity(),
3636
array('%count%' => $result->getQuantity()),
3737
'difference',
3838
$locale
3939
);
4040
}
41-
$suffix = $difference->isPast() ? 'compound.ago' : 'compound.from_now';
4241

43-
return implode(', ', $diff).' '.$this->translator->trans($suffix, array(), 'difference', $locale);
42+
return $this->translator->trans(
43+
'compound.' . ($difference->isPast() ? 'past' : 'future'),
44+
array('%value%' => implode(', ', $diff)),
45+
'difference',
46+
$locale
47+
);
4448
}
4549
}

src/Coduo/PHPHumanizer/Resources/translations/difference.af.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,5 +31,5 @@ compound:
3131
week: "{1} %count% week|[2,Inf] %count% weke"
3232
month: "{1} %count% maand|[2,Inf] %count% maande"
3333
year: "{1} %count% jaar|[2,Inf] %count% jaar"
34-
ago: "gelede"
35-
from_now: "van nou af"
34+
past: "%value% gelede"
35+
future: "%value% van nou af"

src/Coduo/PHPHumanizer/Resources/translations/difference.bg.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,5 +31,5 @@ compound:
3131
week: "{1} %count% седмица|[2,Inf] %count% седмица"
3232
month: "{1} %count% месец|[2,Inf] %count% месеца"
3333
year: "{1} %count% година|[2,Inf] %count% години"
34-
ago: "преди това"
35-
from_now: "след това"
34+
past: "%value% преди това"
35+
future: "%value% след това"

src/Coduo/PHPHumanizer/Resources/translations/difference.de.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,5 +31,5 @@ compound:
3131
week: "{1} %count% Woche|[2,Inf] %count% Wochen"
3232
month: "{1} %count% Monat|[2,Inf] %count% Monate"
3333
year: "{1} %count% Jahr|[2,Inf] %count% Jahre"
34-
ago: "vor"
35-
from_now: "ab jetzt"
34+
past: "%value% vor"
35+
future: "%value% ab jetzt"

src/Coduo/PHPHumanizer/Resources/translations/difference.en.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,5 +31,5 @@ compound:
3131
week: "{1} %count% week|[2,Inf] %count% weeks"
3232
month: "{1} %count% month|[2,Inf] %count% months"
3333
year: "{1} %count% year|[2,Inf] %count% years"
34-
ago: "ago"
35-
from_now: "from now"
34+
past: "%value% ago"
35+
future: "%value% from now"

src/Coduo/PHPHumanizer/Resources/translations/difference.fr.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,5 +31,5 @@ compound:
3131
week: "{1} %count% semaine|[2,Inf] %count% semaines"
3232
month: "{1} %count% mois|[2,Inf] %count% mois"
3333
year: "{1} %count% année|[2,Inf] %count% années"
34-
ago: "il y a"
35-
from_now: "maintenant"
34+
past: "%value% il y a"
35+
future: "%value% maintenant"

src/Coduo/PHPHumanizer/Resources/translations/difference.it.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,5 +31,5 @@ compound:
3131
week: "{1} %count% settimana|[2,Inf] %count% settimane"
3232
month: "{1} %count% mese|[2,Inf] %count% mesi"
3333
year: "{1} %count% anno|[2,Inf] %count% anni"
34-
ago: "fa"
35-
from_now: "da adesso"
34+
past: "%value% fa"
35+
future: "%value% da adesso"

src/Coduo/PHPHumanizer/Resources/translations/difference.nl.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,5 +31,5 @@ compound:
3131
week: "{1} %count% week|[2,Inf] %count% weken"
3232
month: "{1} %count% maand|[2,Inf] %count% maanden"
3333
year: "{1} %count% jaar|[2,Inf] %count% jaren"
34-
ago: "geleden"
35-
from_now: "vanaf nu"
34+
past: "%value% geleden"
35+
future: "%value% vanaf nu"

0 commit comments

Comments
 (0)