Skip to content

Commit beacebd

Browse files
Add locale_is_right_to_left polyfill
1 parent c4ee386 commit beacebd

File tree

3 files changed

+28
-0
lines changed

3 files changed

+28
-0
lines changed

src/Php85/Php85.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313

1414
/**
1515
* @author Pierre Ambroise <[email protected]>
16+
* @author Alexander Schranz <[email protected]>
1617
*
1718
* @internal
1819
*/
@@ -33,4 +34,8 @@ public static function get_exception_handler(): ?callable
3334

3435
return $handler;
3536
}
37+
38+
public static function locale_is_right_to_left(string $locale): bool {
39+
return (bool) preg_match('/^(?:ar|he|fa|ur|ps|sd|ug|ckb|yi|dv|ku_arab|ku-arab)(?:[_-].*)?$/i', $locale);
40+
}
3641
}

src/Php85/bootstrap.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,3 +22,7 @@ function get_error_handler(): ?callable { return p\Php85::get_error_handler(); }
2222
if (!function_exists('get_exception_handler')) {
2323
function get_exception_handler(): ?callable { return p\Php85::get_exception_handler(); }
2424
}
25+
26+
if (!function_exists('locale_is_right_to_left')) {
27+
function locale_is_right_to_left(string $locale): bool { return p\Php85::locale_is_right_to_left($locale); }
28+
}

tests/Php85/Php85Test.php

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,25 @@ public static function provideHandler()
7878
$handler = new TestHandlerInvokable();
7979
yield [$handler, $handler];
8080
}
81+
82+
public function testLocaleIsRightToLeft(): void
83+
{
84+
$this->assertTrue(locale_is_right_to_left('ar'));
85+
$this->assertTrue(locale_is_right_to_left('he'));
86+
$this->assertTrue(locale_is_right_to_left('fa'));
87+
$this->assertTrue(locale_is_right_to_left('ur'));
88+
$this->assertTrue(locale_is_right_to_left('ps'));
89+
$this->assertTrue(locale_is_right_to_left('sd'));
90+
$this->assertTrue(locale_is_right_to_left('ug'));
91+
$this->assertTrue(locale_is_right_to_left('ckb'));
92+
$this->assertTrue(locale_is_right_to_left('yi'));
93+
$this->assertTrue(locale_is_right_to_left('dv'));
94+
$this->assertTrue(locale_is_right_to_left('ku_arab'));
95+
$this->assertTrue(locale_is_right_to_left('ku-arab'));
96+
97+
$this->assertFalse(locale_is_right_to_left('en'));
98+
$this->assertFalse(locale_is_right_to_left('fr'));
99+
}
81100
}
82101

83102
class TestHandler

0 commit comments

Comments
 (0)