Skip to content

Commit

Permalink
Fix sr translation (#1120)
Browse files Browse the repository at this point in the history
* Fix sr translation
* Update tests method names and add covering test details
* Simplify the local formatting
  • Loading branch information
kylekatarnls authored Feb 26, 2018
1 parent b1ab4a1 commit 10c98d1
Show file tree
Hide file tree
Showing 13 changed files with 504 additions and 42 deletions.
5 changes: 3 additions & 2 deletions src/Carbon/Carbon.php
Original file line number Diff line number Diff line change
Expand Up @@ -1187,8 +1187,9 @@ public static function getLocale()
*/
public static function setLocale($locale)
{
$locale = preg_replace_callback('/\b([a-z]{2})[-_](?:([a-z]{4})[-_])?([a-z]{2})\b/', function ($matches) {
return $matches[1].'_'.(!empty($matches[2]) ? ucfirst($matches[2]).'_' : '').strtoupper($matches[3]);
$locale = preg_replace_callback('/[-_]([a-z]{2,})/', function ($matches) {
// _2-letters is a region, _3+-letters is a variant
return '_'.call_user_func(strlen($matches[1]) > 2 ? 'ucfirst' : 'strtoupper', $matches[1]);
}, strtolower($locale));

if (file_exists($filename = __DIR__.'/Lang/'.$locale.'.php')) {
Expand Down
File renamed without changes.
6 changes: 6 additions & 0 deletions src/Carbon/Lang/sr.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,10 @@
'from_now' => ':time od sada',
'after' => 'nakon :time',
'before' => 'pre :time',

'year_from_now' => '{1,21,31,41,51} :count godinu|{2,3,4,22,23,24,32,33,34,42,43,44,52,53,54} :count godine|[5,Inf[ :count godina',
'year_ago' => '{1,21,31,41,51} :count godinu|{2,3,4,22,23,24,32,33,34,42,43,44,52,53,54} :count godine|[5,Inf[ :count godina',

'week_from_now' => '{1} :count nedelju|{2,3,4} :count nedelje|[5,Inf[ :count nedelja',
'week_ago' => '{1} :count nedelju|{2,3,4} :count nedelje|[5,Inf[ :count nedelja',
);
2 changes: 1 addition & 1 deletion src/Carbon/Lang/sr_Cyrl.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
'year' => '{2,3,4,22,23,24,32,33,34,42,43,44,52,53,54}:count године|[0,Inf[ :count година',
'y' => ':count г.',
'month' => '{1} :count месец|{2,3,4}:count месеца|[5,Inf[ :count месеци',
'm' => ':count мј.',
'm' => ':count м.',
'week' => '{1} :count недеља|{2,3,4}:count недеље|[5,Inf[ :count недеља',
'w' => ':count нед.',
'day' => '{1,21,31} :count дан|[2,Inf[ :count дана',
Expand Down
28 changes: 1 addition & 27 deletions src/Carbon/Lang/sr_ME.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,30 +9,4 @@
* file that was distributed with this source code.
*/

return array(
'year' => '{2,3,4,22,23,24,32,33,34,42,43,44,52,53,54}:count godine|[0,Inf[ :count godina',
'y' => ':count g.',
'month' => '{1} :count mjesec|{2,3,4}:count mjeseca|[5,Inf[ :count mjeseci',
'm' => ':count mj.',
'week' => '{1} :count nedjelja|{2,3,4}:count nedjelje|[5,Inf[ :count nedjelja',
'w' => ':count ned.',
'day' => '{1,21,31} :count dan|[2,Inf[ :count dana',
'd' => ':count d.',
'hour' => '{1,21} :count sat|{2,3,4,22,23,24}:count sata|[5,Inf[ :count sati',
'h' => ':count č.',
'minute' => '{1,21,31,41,51} :count minut|[2,Inf[ :count minuta',
'min' => ':count min.',
'second' => '{1,21,31,41,51} :count sekund|{2,3,4,22,23,24,32,33,34,42,43,44,52,53,54}:count sekunde|[5,Inf[:count sekundi',
's' => ':count sek.',
'ago' => 'prije :time',
'from_now' => 'za :time',
'after' => ':time nakon',
'before' => ':time prije',

'year_from_now' => '{1,21,31,41,51} :count godinu|{2,3,4,22,23,24,32,33,34,42,43,44,52,53,54} :count godine|[5,Inf[ :count godina',
'year_ago' => '{1,21,31,41,51} :count godinu|{2,3,4,22,23,24,32,33,34,42,43,44,52,53,54} :count godine|[5,Inf[ :count godina',

'week_from_now' => '{1} :count nedjelju|{2,3,4} :count nedjelje|[5,Inf[ :count nedjelja',
'week_ago' => '{1} :count nedjelju|{2,3,4} :count nedjelje|[5,Inf[ :count nedjelja',

);
return require __DIR__.'/sr_Latn_ME.php';
3 changes: 2 additions & 1 deletion tests/Carbon/LocalizationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public function providerLocales()
return array(
array('af'),
array('ar'),
array('ar_shakl'),
array('ar_Shakl'),
array('az'),
array('bg'),
array('bn'),
Expand Down Expand Up @@ -84,6 +84,7 @@ public function providerLocales()
array('sl'),
array('sq'),
array('sr'),
array('sr_Cyrl'),
array('sr_Cyrl_ME'),
array('sr_Latn_ME'),
array('sr_ME'),
Expand Down
2 changes: 1 addition & 1 deletion tests/Localization/ArShaklTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class ArShaklTest extends AbstractTestCase
{
public function testDiffForHumansLocalizedInArb()
{
Carbon::setLocale('ar_shakl');
Carbon::setLocale('ar_Shakl');

$scope = $this;
$this->wrapWithNonDstDate(function () use ($scope) {
Expand Down
15 changes: 10 additions & 5 deletions tests/Localization/LanguagesCoverageTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,18 @@ public function testAllLanguagesAreTested()
$tests = array_map(function ($file) {
return strtolower(substr(basename($file), 0, -8));
}, glob(__DIR__.'/*Test.php'));
$missingLanguages = count(array_filter($languages, function ($language) use ($tests) {
return !in_array(
str_replace(array('_', '-'), '', strtolower(substr(basename($language), 0, -4))),
$tester = $this;
$missingLanguages = array_filter($languages, function ($language) use ($tester, $tests) {
$file = basename($language);
$covered = in_array(
str_replace(array('_', '-'), '', strtolower(substr($file, 0, -4))),
$tests
);
}));
$tester->assertTrue($covered, "Expect $file language file to be covered.");

$this->assertSame(0, $missingLanguages);
return !$covered;
});

$this->assertCount(0, $missingLanguages, 'Expect to have 0 languages uncovered.');
}
}
2 changes: 1 addition & 1 deletion tests/Localization/SrCyrlMeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

class SrCyrlMeTest extends AbstractTestCase
{
public function testDiffForHumansLocalizedInSrCyrlMe()
public function testDiffForHumansLocalizedInCyrillicSerbianMe()
{
Carbon::setLocale('sr_Cyrl_ME');

Expand Down
Loading

0 comments on commit 10c98d1

Please sign in to comment.