Skip to content
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
13 changes: 8 additions & 5 deletions src/translations.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,14 @@
*/

return [
// "en" is the default locale
"en" => [
"Total Contributions" => "Total Contributions",
"Current Streak" => "Current Streak",
"Longest Streak" => "Longest Streak",
"Present" => "Present",
],
// Locales below are sorted alphabetically
"de" => [
"Total Contributions" => "Gesamte Beiträge",
"Current Streak" => "Aktuelle Serie",
Expand All @@ -35,6 +37,7 @@
"Total Contributions" => "Todas Contribuciones",
"Current Streak" => "Racha Actual",
"Longest Streak" => "Racha Más Larga",
"Present" => "Presente",
],
"ja" => [
"date_format" => "[Y.]n.j",
Expand All @@ -43,17 +46,17 @@
"Longest Streak" => "最長のストリーク",
"Present" => "今",
],
"tr" => [
"Total Contributions" => "Toplam Katkı",
"Current Streak" => "Güncel Seri",
"Longest Streak" => "En Uzun Seri",
],
"pt-br" => [
"Total Contributions" => "Total de Contribuições",
"Current Streak" => "Atual Sequência",
"Longest Streak" => "Maior Sequência",
"Present" => "Atualmente",
],
"tr" => [
"Total Contributions" => "Toplam Katkı",
"Current Streak" => "Güncel Seri",
"Longest Streak" => "En Uzun Seri",
],
"zh" => [
"Total Contributions" => "合计贡献",
"Current Streak" => "最近连续贡献",
Expand Down
30 changes: 22 additions & 8 deletions tests/TranslationsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,21 +10,35 @@
final class TranslationsTest extends TestCase
{
/**
* Test that all locales only contain phrases appearing for the locale "en"
* or "date_format"
* Test that all locales only contain phrases appearing for the locale "en" or "date_format"
*/
public function testAllPhrasesValid(): void
{
$translations = include 'src/translations.php';
$locales = array_keys($translations);
$valid_phrases = array_merge(array_keys($translations['en']), ['date_format']);
$valid_phrases = ["date_format", "Total Contributions", "Current Streak", "Longest Streak", "Present"];
foreach ($locales as $locale) {
$phrases = array_keys($translations[$locale]);
$this->assertEquals(
array_diff($phrases, $valid_phrases),
[],
"Locale $locale contains invalid phrases"
);
$this->assertEmpty(array_diff($phrases, $valid_phrases), "Locale $locale contains invalid phrases");
}
}

/**
* Test that "en" is first and the remaining locales are sorted alphabetically
*/
public function testLocalesSortedAlphabetically(): void
{
$translations = include 'src/translations.php';
$locales = array_keys($translations);
// check that "en" is first
$this->assertEquals("en", $locales[0]);
// check that the remaining locales are sorted alphabetically
$remaining_locales = array_slice($locales, 1);
$sorted_locales = call_user_func(function (array $arr) {
asort($arr);
return $arr;
}, $remaining_locales);
// check that the remaining locales are sorted alphabetically
$this->assertEquals(implode(', ', $sorted_locales), implode(', ', $remaining_locales));
}
}