Skip to content

Commit

Permalink
Fixed Translator Builder regexp, added spec and updated readme for pt…
Browse files Browse the repository at this point in the history
…_BR translation
  • Loading branch information
norberttech committed Oct 26, 2015
2 parents c6a594a + 17818b2 commit 8754ad1
Show file tree
Hide file tree
Showing 5 changed files with 58 additions and 3 deletions.
3 changes: 1 addition & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
vendor/
bin/
composer.lock
.idea
composer.lock
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,9 @@ Currently we support following languages:
* [English](src/Coduo/PHPHumanizer/Resources/translations/difference.en.yml)
* [Polish](src/Coduo/PHPHumanizer/Resources/translations/difference.pl.yml)
* [German](src/Coduo/PHPHumanizer/Resources/translations/difference.de.yml)
* [Turkish](src/Coduo/PHPHumanizer/Resources/translations/difference.tr.yml)
* [French](src/Coduo/PHPHumanizer/Resources/translations/difference.fr.yml)
* [Português - Brasil](src/Coduo/PHPHumanizer/Resources/translations/difference.pt_BR.yml)

# Credits

Expand Down
18 changes: 18 additions & 0 deletions spec/Coduo/PHPHumanizer/DateTimeSpec.php
Original file line number Diff line number Diff line change
Expand Up @@ -153,4 +153,22 @@ function it_humanizes_precise_difference_between_dates_for_fr_locale()
$this->preciseDifference(new \DateTime($example[0]), new \DateTime($example[1]), 'fr')->shouldReturn($example[2]);
}
}

function it_humanizes_precise_difference_between_dates_for_pt_BR_locale()
{
$examples = array(
array("2014-04-26 13:00:00", "2014-04-26 12:58:15", '1 minuto, 45 segundos atrás'),
array("2014-04-26 13:00:00", "2014-04-26 11:20:00", '1 hora, 40 minutos atrás'),
array("2014-04-26 13:00:00", "2014-04-27 13:15:00", '1 dia, 15 minutos a partir de agora'),
array("2014-04-26 13:00:00", "2014-05-03 15:00:00", '7 dias, 2 horas a partir de agora'),
array("2014-04-26 13:00:00", "2015-04-28 17:00:00", '1 ano, 2 dias, 4 horas a partir de agora'),
array("2014-04-26 13:00:00", "2014-04-28 23:00:00", '2 dias, 10 horas a partir de agora'),
array("2014-04-26 13:00:00", "2014-04-25 11:20:00", '1 dia, 1 hora, 40 minutos atrás'),
array("2014-04-26 13:00:00", "2016-04-27 13:00:00", '2 anos, 1 dia a partir de agora'),
);

foreach ($examples as $example) {
$this->preciseDifference(new \DateTime($example[0]), new \DateTime($example[1]), 'pt_BR')->shouldReturn($example[2]);
}
}
}
35 changes: 35 additions & 0 deletions src/Coduo/PHPHumanizer/Resources/translations/difference.pt_br.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
just_now:
past: "[0,Inf] atrás"
future: "[0,Inf] a partir de agora"
second:
past: "{1} %count% segundo atrás|[2,Inf] %count% segundos atrás"
future: "{1} %count% segundo a partir de agora|[2,Inf] %count% segundos a partir de agora"
minute:
past: "{1} %count% minuto atrás|[2,Inf] %count% minutos atrás"
future: "{1} %count% minuto a partir de agora|[2,Inf] %count% minutos a partir de agora"
hour:
past: "{1} %count% hora atrás|[2,Inf] %count% horas atrás"
future: "{1} %count% hora a partir de agora|[2,Inf] %count% horas a partir de agora"
day:
past: "{1} %count% dia atrás|[2,Inf] %count% dias atrás"
future: "{1} %count% dia a partir de agora|[2,Inf] %count% dias a partir de agora"
week:
past: "{1} %count% semana atrás|[2,Inf] %count% semanas atrás"
future: "{1} %count% semana a partir de agora|[2,Inf] %count% semanas a partir de agora"
month:
past: "{1} %count% mês atrás|[2,Inf] %count% meses atrás"
future: "{1} %count% mês a partir de agora|[2,Inf] %count% meses a partir de agora"
year:
past: "{1} %count% ano atrás|[2,Inf] %count% anos atrás"
future: "{1} %count% ano a partir de agora|[2,Inf] %count% anos a partir de agora"

compound:
second: "{1} %count% segundo|[2,Inf] %count% segundos"
minute: "{1} %count% minuto|[2,Inf] %count% minutos"
hour: "{1} %count% hora|[2,Inf] %count% horas"
day: "{1} %count% dia|[2,Inf] %count% dias"
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"
2 changes: 1 addition & 1 deletion src/Coduo/PHPHumanizer/Translator/Builder.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public static function build($locale)
$translator->addLoader('yml', new YamlFileLoader());

$iterator = new \FilesystemIterator(__DIR__ . "/../Resources/translations");
$filter = new \RegexIterator($iterator, '/[aA-zZ]+\.[a-z]{2}\.yml$/');
$filter = new \RegexIterator($iterator, '/[aA-zZ]+\.([a-z]{2}|[a-z]{2}\_[A-Z]{2})\.yml$/');

foreach($filter as $file) {
/* @var $file \SplFileInfo */
Expand Down

0 comments on commit 8754ad1

Please sign in to comment.