diff --git a/.gitignore b/.gitignore index 5b83f26..4cda1c1 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,3 @@ vendor/ bin/ -composer.lock -.idea \ No newline at end of file +composer.lock \ No newline at end of file diff --git a/README.md b/README.md index 13c53c0..672f5be 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/spec/Coduo/PHPHumanizer/DateTimeSpec.php b/spec/Coduo/PHPHumanizer/DateTimeSpec.php index c278b28..8177e21 100644 --- a/spec/Coduo/PHPHumanizer/DateTimeSpec.php +++ b/spec/Coduo/PHPHumanizer/DateTimeSpec.php @@ -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]); + } + } } diff --git a/src/Coduo/PHPHumanizer/Resources/translations/difference.pt_br.yml b/src/Coduo/PHPHumanizer/Resources/translations/difference.pt_br.yml new file mode 100644 index 0000000..1c9c039 --- /dev/null +++ b/src/Coduo/PHPHumanizer/Resources/translations/difference.pt_br.yml @@ -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" \ No newline at end of file diff --git a/src/Coduo/PHPHumanizer/Translator/Builder.php b/src/Coduo/PHPHumanizer/Translator/Builder.php index da44e79..79e4809 100644 --- a/src/Coduo/PHPHumanizer/Translator/Builder.php +++ b/src/Coduo/PHPHumanizer/Translator/Builder.php @@ -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 */