Skip to content

Commit fcd0f72

Browse files
committed
GH-18345: adding Locale::isRightToLeft.
Checks is the locale is written left to right. It makes sure all the needed likely subtags are included (maximization) then determines the direction by known matches. close GH-18351
1 parent ba83d5d commit fcd0f72

8 files changed

+59
-2
lines changed

NEWS

+2
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,8 @@ PHP NEWS
8585
with uninitialised classes or clone failure. (David Carlier)
8686
. Added DECIMAL_COMPACT_SHORT/DECIMAL_COMPACT_LONG for NumberFormatter class.
8787
(BogdanUngureanu)
88+
. Added Locale::isRightToLeft to check if a locale is written right to left.
89+
(David Carlier)
8890

8991
- MySQLi:
9092
. Fixed bugs GH-17900 and GH-8084 (calling mysqli::__construct twice).

UPGRADING

+4
Original file line numberDiff line numberDiff line change
@@ -309,6 +309,10 @@ PHP 8.5 UPGRADE NOTES
309309
. Added enchant_dict_remove() to put a word on the exclusion list and
310310
remove it from the session dictionary.
311311

312+
- Intl:
313+
. Added locale_is_right_to_left/Locale::isRightToLeft, returns true if
314+
the locale is written right to left (after its enrichment with likely subtags).
315+
312316
- Pdo\Sqlite:
313317
. Added support for Pdo\Sqlite::setAuthorizer(), which is the equivalent of
314318
SQLite3::setAuthorizer(). The only interface difference is that the

ext/intl/locale/locale.stub.php

+5
Original file line numberDiff line numberDiff line change
@@ -133,4 +133,9 @@ public static function canonicalize(string $locale): ?string {}
133133
* @alias locale_accept_from_http
134134
*/
135135
public static function acceptFromHttp(string $header): string|false {}
136+
137+
/**
138+
* @alias locale_is_right_to_left
139+
*/
140+
public static function isRightToLeft(string $locale): bool {}
136141
}

ext/intl/locale/locale_arginfo.h

+7-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

ext/intl/locale/locale_methods.c

+16
Original file line numberDiff line numberDiff line change
@@ -1619,3 +1619,19 @@ PHP_FUNCTION(locale_accept_from_http)
16191619
RETURN_STRINGL(resultLocale, len);
16201620
}
16211621
/* }}} */
1622+
1623+
PHP_FUNCTION(locale_is_right_to_left)
1624+
{
1625+
char *locale;
1626+
size_t locale_len;
1627+
1628+
ZEND_PARSE_PARAMETERS_START(1, 1)
1629+
Z_PARAM_STRING(locale, locale_len)
1630+
ZEND_PARSE_PARAMETERS_END();
1631+
1632+
if (!locale_len) {
1633+
locale = (char *)intl_locale_get_default();
1634+
}
1635+
1636+
RETURN_BOOL(uloc_isRightToLeft(locale));
1637+
}

ext/intl/php_intl.stub.php

+2
Original file line numberDiff line numberDiff line change
@@ -501,6 +501,8 @@ function locale_lookup(array $languageTag, string $locale, bool $canonicalize =
501501

502502
function locale_accept_from_http(string $header): string|false {}
503503

504+
function locale_is_right_to_left(string $locale): bool {}
505+
504506
/* msgformat */
505507

506508
function msgfmt_create(string $locale, string $pattern): ?MessageFormatter {}

ext/intl/php_intl_arginfo.h

+7-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
--TEST--
2+
locale_is_right_to_left
3+
--EXTENSIONS--
4+
intl
5+
--FILE--
6+
<?php
7+
var_dump(Locale::isRightToLeft("en-US"));
8+
var_dump(Locale::isRightToLeft("\INVALID\\"));
9+
var_dump(Locale::isRightToLeft(""));
10+
var_dump(Locale::isRightToLeft("ar"));
11+
?>
12+
--EXPECT--
13+
bool(false)
14+
bool(false)
15+
bool(false)
16+
bool(true)

0 commit comments

Comments
 (0)