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 possibility to use translated short notations #229

Merged
merged 1 commit into from
Mar 12, 2017
Merged
Show file tree
Hide file tree
Changes from all 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
15 changes: 12 additions & 3 deletions src/Date.php
Original file line number Diff line number Diff line change
Expand Up @@ -236,14 +236,23 @@ public function format($format)
if (in_array($character, ['F', 'M'])) {
$choice = (($i - 2) >= 0 and in_array($format[$i - 2], ['d', 'j'])) ? 1 : 0;

$translated = $lang->transChoice(strtolower($key), $choice);
$translated = $lang->transChoice(mb_strtolower($key), $choice);
} else {
$translated = $lang->trans(strtolower($key));
$translated = $lang->trans(mb_strtolower($key));
}

// Short notations.
if (in_array($character, ['D', 'M'])) {
$translated = mb_substr($translated, 0, 3);
$toTranslate = mb_strtolower($original);
$shortTranslated = $lang->trans($toTranslate);

if ($shortTranslated === $toTranslate) {
// use the first 3 characters as short notation
$translated = mb_substr($translated, 0, 3);
} else {
// use translated version
$translated = $shortTranslated;
}
}

// Add to replace list.
Expand Down
21 changes: 21 additions & 0 deletions src/Lang/de.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,19 @@
'november' => 'November',
'december' => 'Dezember',

'jan' => 'Jan',
'feb' => 'Feb',
'mar' => 'Mär',
'apr' => 'Apr',
'may' => 'Mai',
'jun' => 'Jun',
'jul' => 'Jul',
'aug' => 'Aug',
'sep' => 'Sep',
'oct' => 'Okt',
'nov' => 'Nov',
'dec' => 'Dez',

'monday' => 'Montag',
'tuesday' => 'Dienstag',
'wednesday' => 'Mittwoch',
Expand All @@ -45,6 +58,14 @@
'saturday' => 'Samstag',
'sunday' => 'Sonntag',

'mon' => 'Mo',
'tue' => 'Di',
'wed' => 'Mi',
'thu' => 'Do',
'fri' => 'Fr',
'sat' => 'Sa',
'sun' => 'So',

'year_diff' => '1 Jahr|:count Jahren',
'month_diff' => '1 Monat|:count Monaten',
'week_diff' => '1 Woche|:count Wochen',
Expand Down
21 changes: 21 additions & 0 deletions src/Lang/nl.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,19 @@
'november' => 'november',
'december' => 'december',

'jan' => 'jan',
'feb' => 'feb',
'mar' => 'mrt',
'apr' => 'apr',
'may' => 'mei',
'jun' => 'jun',
'jul' => 'jul',
'aug' => 'aug',
'sep' => 'sep',
'oct' => 'okt',
'nov' => 'nov',
'dec' => 'dec',

'monday' => 'maandag',
'tuesday' => 'dinsdag',
'wednesday' => 'woensdag',
Expand All @@ -45,4 +58,12 @@
'saturday' => 'zaterdag',
'sunday' => 'zondag',

'mon' => 'ma',
'tue' => 'di',
'wed' => 'wo',
'thu' => 'do',
'fri' => 'vr',
'sat' => 'za',
'sun' => 'zo',

];
25 changes: 20 additions & 5 deletions tests/AutomaticTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,18 @@ public function testTranslatesMonths()
$date = new Date("1 $month");
$date->setLocale($language);

// Full
$translation = $selector->choose($translations[$month], 0, $language);

$this->assertTrue(isset($translation));
$this->assertEquals($translation, $date->format('F'), "Language: $language"); // Full
$this->assertEquals(mb_substr($translation, 0, 3), $date->format('M'), "Language: $language"); // Short
$this->assertEquals($translation, $date->format('F'), "Language: $language");

// Short
$monthShortEnglish = mb_substr($month, 0, 3);
if (isset($translations[$monthShortEnglish])) {
$this->assertEquals($translations[$monthShortEnglish], $date->format('M'), "Language: $language");
} else {
$this->assertEquals(mb_substr($translation, 0, 3), $date->format('M'), "Language: $language");
}
}
}
}
Expand All @@ -66,9 +73,17 @@ public function testTranslatesDays()
$date = new Date($day);
$date->setLocale($language);

// Full
$this->assertTrue(isset($translations[$day]));
$this->assertEquals($translations[$day], $date->format('l'), "Language: $language"); // Full
$this->assertEquals(mb_substr($translations[$day], 0, 3), $date->format('D'), "Language: $language"); // Short
$this->assertEquals($translations[$day], $date->format('l'), "Language: $language");

// Short
$dayShortEnglish = mb_substr($day, 0, 3);
if (isset($translations[$dayShortEnglish])) {
$this->assertEquals($translations[$dayShortEnglish], $date->format('D'), "Language: $language");
} else {
$this->assertEquals(mb_substr($translations[$day], 0, 3), $date->format('D'), "Language: $language");
}
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion tests/TranslationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ public function testFormatTranslated()
$this->assertSame('l 28 F 2013 21:58:16', $date->format('\l j \F Y H:i:s'));

$date = new Date(1367186296);
$this->assertSame('zon 28 apr 2013 21:58:16', $date->format('D j M Y H:i:s'));
$this->assertSame('zo 28 apr 2013 21:58:16', $date->format('D j M Y H:i:s'));
}

public function testFormatDeclensions()
Expand Down