Skip to content

feat: Added Hebrew translations and RTL language support #335

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

Merged
merged 3 commits into from
Oct 16, 2022
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
6 changes: 5 additions & 1 deletion src/card.php
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,9 @@ function generateCard(array $stats, array $params = null): string
// add missing translations from English
$localeTranslations += $translations["en"];

// whether the locale is right-to-left
$direction = $localeTranslations["rtl"] ?? false ? "rtl" : "ltr";

// get date format
// locale date formatter (used only if date_format is not specified)
$dateFormat = $params["date_format"] ?? ($localeTranslations["date_format"] ?? null);
Expand Down Expand Up @@ -168,7 +171,8 @@ function generateCard(array $stats, array $params = null): string
$longestStreakRange .= " - " . $longestStreakEnd;
}

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'>
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' direction='{$direction}'>
<style>
@keyframes currstreak {
0% { font-size: 3px; opacity: 0.2; }
Expand Down
11 changes: 11 additions & 0 deletions src/translations.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@
* 2016.8.10 8.10 [Y.]n.j
*
* For info on valid date_format strings, see https://github.com/DenverCoder1/github-readme-streak-stats#date-formats
*
* Right-to-Left Language Support
* ------------------------------
* To enable right-to-left language support, add `"rtl" => true` to the locale array (see "he" for an example).
*/

return [
Expand Down Expand Up @@ -52,6 +56,13 @@
"Longest Streak" => "Plus longue séquence",
"Present" => "Aujourd'hui",
],
"he" => [
"rtl" => true,
"Total Contributions" => "סכום התרומות",
"Current Streak" => "רצף נוכחי",
"Longest Streak" => "רצף הכי ארוך",
"Present" => "היום",
],
"hi" => [
"Total Contributions" => "कुल योगदान",
"Current Streak" => "निरंतर दैनिक योगदान",
Expand Down
2 changes: 1 addition & 1 deletion tests/TranslationsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public function testAllPhrasesValid(): void
{
$translations = include "src/translations.php";
$locales = array_keys($translations);
$valid_phrases = ["date_format", "Total Contributions", "Current Streak", "Longest Streak", "Present"];
$valid_phrases = ["rtl", "date_format", "Total Contributions", "Current Streak", "Longest Streak", "Present"];
foreach ($locales as $locale) {
$phrases = array_keys($translations[$locale]);
$this->assertEmpty(array_diff($phrases, $valid_phrases), "Locale $locale contains invalid phrases");
Expand Down
3 changes: 2 additions & 1 deletion tests/expected/test_border_radius_card.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 2 additions & 1 deletion tests/expected/test_card.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 2 additions & 1 deletion tests/expected/test_date_card.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 2 additions & 1 deletion tests/expected/test_locale_ja_card.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.