Skip to content

Commit 667130e

Browse files
Update Php85.php
1 parent beacebd commit 667130e

File tree

1 file changed

+47
-1
lines changed

1 file changed

+47
-1
lines changed

src/Php85/Php85.php

Lines changed: 47 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,52 @@ public static function get_exception_handler(): ?callable
3636
}
3737

3838
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);
39+
static $rtlScripts = [
40+
'Adlm', 'Arab', 'Armi', 'Hebr', 'Mani', 'Mend', 'Nkoo',
41+
'Phnx', 'Rohg', 'Samr', 'Syrc', 'Thaa',
42+
];
43+
44+
static $languageToLikelyRtlScript = [
45+
'ar' => 'Arab', // Arabic
46+
'fa' => 'Arab', // Persian (Farsi)
47+
'ur' => 'Arab', // Urdu
48+
'ps' => 'Arab', // Pashto
49+
'sd' => 'Arab', // Sindhi
50+
'ug' => 'Arab', // Uyghur
51+
'ckb' => 'Arab', // Sorani Kurdish
52+
'he' => 'Hebr', // Hebrew
53+
'yi' => 'Hebr', // Yiddish
54+
'dv' => 'Thaa', // Dhivehi
55+
'nqo' => 'Nkoo', // N'Ko
56+
];
57+
58+
if (empty($locale)) {
59+
return false;
60+
}
61+
62+
$localeParts = preg_split('/[_-]/', $locale);
63+
$language = strtolower($localeParts[0] ?? '');
64+
$script = null;
65+
66+
foreach ($localeParts as $part) {
67+
if (strlen($part) === 4 && ctype_alpha($part)) {
68+
$script = ucfirst(strtolower($part));
69+
break;
70+
}
71+
}
72+
73+
if ($script === null) {
74+
$script = $languageToLikelyScript[$language] ?? null;
75+
}
76+
77+
if ($script === null) {
78+
if (in_array($language, ['ar', 'he', 'fa', 'ur', 'ps', 'sd', 'ug', 'ckb', 'yi', 'dv'])) {
79+
return true;
80+
}
81+
82+
return false;
83+
}
84+
85+
return in_array($script, $rtlScripts, true);
4086
}
4187
}

0 commit comments

Comments
 (0)