Upgrade to 3.8.0

This commit is contained in:
Bastian Allgeier
2022-10-06 10:11:54 +02:00
parent a9ed4e45ca
commit 7d168aae58
332 changed files with 26337 additions and 21977 deletions

View File

@@ -99,13 +99,9 @@ class I18n
*/
public static function formatNumber($number, string $locale = null): string
{
$locale ??= static::locale();
$formatter = static::decimalNumberFormatter($locale);
if ($formatter !== null) {
$number = $formatter->format($number);
}
$locale ??= static::locale();
$formatter = static::decimalNumberFormatter($locale);
$number = $formatter?->format($number) ?? $number;
return (string)$number;
}
@@ -142,18 +138,25 @@ class I18n
if (is_array($key) === true) {
// try to use actual locale
if (isset($key[$locale])) {
if (isset($key[$locale]) === true) {
return $key[$locale];
}
// try to use language code, e.g. `es` when locale is `es_ES`
$lang = Str::before($locale, '_');
if (isset($key[$lang])) {
if (isset($key[$lang]) === true) {
return $key[$lang];
}
// use fallback
if (is_array($fallback)) {
return $fallback[$locale] ?? $fallback['en'] ?? reset($fallback);
// use global wildcard as i18n key
if (isset($key['*']) === true) {
return static::translate($key['*'], $key['*']);
}
// use fallback
if (is_array($fallback) === true) {
return $fallback[$locale] ??
$fallback['en'] ??
reset($fallback);
}
return $fallback;
}
@@ -189,7 +192,7 @@ class I18n
* @param string|null $locale
* @return string
*/
public static function template(string $key, $fallback = null, ?array $replace = null, ?string $locale = null): string
public static function template(string $key, $fallback = null, array|null $replace = null, string|null $locale = null): string
{
if (is_array($fallback) === true) {
$replace = $fallback;
@@ -209,9 +212,6 @@ class I18n
* Returns the current or any other translation
* by locale. If the translation does not exist
* yet, the loader will try to load it, if defined.
*
* @param string|null $locale
* @return array
*/
public static function translation(string $locale = null): array
{
@@ -221,7 +221,7 @@ class I18n
return static::$translations[$locale];
}
if (is_a(static::$load, 'Closure') === true) {
if (static::$load instanceof Closure) {
return static::$translations[$locale] = (static::$load)($locale);
}
@@ -236,8 +236,6 @@ class I18n
/**
* Returns all loaded or defined translations
*
* @return array
*/
public static function translations(): array
{
@@ -246,16 +244,17 @@ class I18n
/**
* Returns (and creates) a decimal number formatter for a given locale
*
* @return \NumberFormatter|null
*/
protected static function decimalNumberFormatter(string $locale): ?NumberFormatter
protected static function decimalNumberFormatter(string $locale): NumberFormatter|null
{
if (isset(static::$decimalsFormatters[$locale])) {
if (isset(static::$decimalsFormatters[$locale]) === true) {
return static::$decimalsFormatters[$locale];
}
if (extension_loaded('intl') !== true || class_exists('NumberFormatter') !== true) {
if (
extension_loaded('intl') !== true ||
class_exists('NumberFormatter') !== true
) {
return null; // @codeCoverageIgnore
}
@@ -287,7 +286,7 @@ class I18n
return null;
}
if (is_a($translation, 'Closure') === true) {
if ($translation instanceof Closure) {
return $translation($count);
}