Skip to content

Commit 6c18585

Browse files
authored
feat: Added Hebrew translations and RTL language support (#335)
1 parent a72c337 commit 6c18585

7 files changed

+25
-6
lines changed

src/card.php

+5-1
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,9 @@ function generateCard(array $stats, array $params = null): string
135135
// add missing translations from English
136136
$localeTranslations += $translations["en"];
137137

138+
// whether the locale is right-to-left
139+
$direction = $localeTranslations["rtl"] ?? false ? "rtl" : "ltr";
140+
138141
// get date format
139142
// locale date formatter (used only if date_format is not specified)
140143
$dateFormat = $params["date_format"] ?? ($localeTranslations["date_format"] ?? null);
@@ -168,7 +171,8 @@ function generateCard(array $stats, array $params = null): string
168171
$longestStreakRange .= " - " . $longestStreakEnd;
169172
}
170173

171-
return "<svg xmlns='http://www.w3.org/2000/svg' xmlns:xlink='http://www.w3.org/1999/xlink' style='isolation:isolate' viewBox='0 0 495 195' width='495px' height='195px'>
174+
return "<svg xmlns='http://www.w3.org/2000/svg' xmlns:xlink='http://www.w3.org/1999/xlink'
175+
style='isolation:isolate' viewBox='0 0 495 195' width='495px' height='195px' direction='{$direction}'>
172176
<style>
173177
@keyframes currstreak {
174178
0% { font-size: 3px; opacity: 0.2; }

src/translations.php

+11
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,10 @@
1717
* 2016.8.10 8.10 [Y.]n.j
1818
*
1919
* For info on valid date_format strings, see https://github.com/DenverCoder1/github-readme-streak-stats#date-formats
20+
*
21+
* Right-to-Left Language Support
22+
* ------------------------------
23+
* To enable right-to-left language support, add `"rtl" => true` to the locale array (see "he" for an example).
2024
*/
2125

2226
return [
@@ -52,6 +56,13 @@
5256
"Longest Streak" => "Plus longue séquence",
5357
"Present" => "Aujourd'hui",
5458
],
59+
"he" => [
60+
"rtl" => true,
61+
"Total Contributions" => "סכום התרומות",
62+
"Current Streak" => "רצף נוכחי",
63+
"Longest Streak" => "רצף הכי ארוך",
64+
"Present" => "היום",
65+
],
5566
"hi" => [
5667
"Total Contributions" => "कुल योगदान",
5768
"Current Streak" => "निरंतर दैनिक योगदान",

tests/TranslationsTest.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ public function testAllPhrasesValid(): void
1616
{
1717
$translations = include "src/translations.php";
1818
$locales = array_keys($translations);
19-
$valid_phrases = ["date_format", "Total Contributions", "Current Streak", "Longest Streak", "Present"];
19+
$valid_phrases = ["rtl", "date_format", "Total Contributions", "Current Streak", "Longest Streak", "Present"];
2020
foreach ($locales as $locale) {
2121
$phrases = array_keys($translations[$locale]);
2222
$this->assertEmpty(array_diff($phrases, $valid_phrases), "Locale $locale contains invalid phrases");

tests/expected/test_border_radius_card.svg

+2-1
Loading

tests/expected/test_card.svg

+2-1
Loading

tests/expected/test_date_card.svg

+2-1
Loading

tests/expected/test_locale_ja_card.svg

+2-1
Loading

0 commit comments

Comments
 (0)