Skip to content

Commit c6f417f

Browse files
ci: Test locales are sorted alphabetically (DenverCoder1#247)
Co-authored-by: Abraham Murciano <[email protected]>
1 parent e5444c2 commit c6f417f

File tree

2 files changed

+30
-13
lines changed

2 files changed

+30
-13
lines changed

src/translations.php

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,14 @@
2020
*/
2121

2222
return [
23+
// "en" is the default locale
2324
"en" => [
2425
"Total Contributions" => "Total Contributions",
2526
"Current Streak" => "Current Streak",
2627
"Longest Streak" => "Longest Streak",
2728
"Present" => "Present",
2829
],
30+
// Locales below are sorted alphabetically
2931
"de" => [
3032
"Total Contributions" => "Gesamte Beiträge",
3133
"Current Streak" => "Aktuelle Serie",
@@ -35,6 +37,7 @@
3537
"Total Contributions" => "Todas Contribuciones",
3638
"Current Streak" => "Racha Actual",
3739
"Longest Streak" => "Racha Más Larga",
40+
"Present" => "Presente",
3841
],
3942
"ja" => [
4043
"date_format" => "[Y.]n.j",
@@ -43,17 +46,17 @@
4346
"Longest Streak" => "最長のストリーク",
4447
"Present" => "",
4548
],
46-
"tr" => [
47-
"Total Contributions" => "Toplam Katkı",
48-
"Current Streak" => "Güncel Seri",
49-
"Longest Streak" => "En Uzun Seri",
50-
],
5149
"pt-br" => [
5250
"Total Contributions" => "Total de Contribuições",
5351
"Current Streak" => "Atual Sequência",
5452
"Longest Streak" => "Maior Sequência",
5553
"Present" => "Atualmente",
5654
],
55+
"tr" => [
56+
"Total Contributions" => "Toplam Katkı",
57+
"Current Streak" => "Güncel Seri",
58+
"Longest Streak" => "En Uzun Seri",
59+
],
5760
"zh" => [
5861
"Total Contributions" => "合计贡献",
5962
"Current Streak" => "最近连续贡献",

tests/TranslationsTest.php

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,21 +10,35 @@
1010
final class TranslationsTest extends TestCase
1111
{
1212
/**
13-
* Test that all locales only contain phrases appearing for the locale "en"
14-
* or "date_format"
13+
* Test that all locales only contain phrases appearing for the locale "en" or "date_format"
1514
*/
1615
public function testAllPhrasesValid(): void
1716
{
1817
$translations = include 'src/translations.php';
1918
$locales = array_keys($translations);
20-
$valid_phrases = array_merge(array_keys($translations['en']), ['date_format']);
19+
$valid_phrases = ["date_format", "Total Contributions", "Current Streak", "Longest Streak", "Present"];
2120
foreach ($locales as $locale) {
2221
$phrases = array_keys($translations[$locale]);
23-
$this->assertEquals(
24-
array_diff($phrases, $valid_phrases),
25-
[],
26-
"Locale $locale contains invalid phrases"
27-
);
22+
$this->assertEmpty(array_diff($phrases, $valid_phrases), "Locale $locale contains invalid phrases");
2823
}
2924
}
25+
26+
/**
27+
* Test that "en" is first and the remaining locales are sorted alphabetically
28+
*/
29+
public function testLocalesSortedAlphabetically(): void
30+
{
31+
$translations = include 'src/translations.php';
32+
$locales = array_keys($translations);
33+
// check that "en" is first
34+
$this->assertEquals("en", $locales[0]);
35+
// check that the remaining locales are sorted alphabetically
36+
$remaining_locales = array_slice($locales, 1);
37+
$sorted_locales = call_user_func(function (array $arr) {
38+
asort($arr);
39+
return $arr;
40+
}, $remaining_locales);
41+
// check that the remaining locales are sorted alphabetically
42+
$this->assertEquals(implode(', ', $sorted_locales), implode(', ', $remaining_locales));
43+
}
3044
}

0 commit comments

Comments
 (0)