<?php /* * This file is part of the Symfony package. * * (c) Fabien Potencier <fabien@symfony.com> * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace Symfony\Component\Intl; /** * Provides access to locale-related data. * * @author Bernhard Schussek <bschussek@gmail.com> * * @internal */ final class Locale extends \Locale { /** * @var string */ private static $defaultFallback = 'en'; /** * Sets the default fallback locale. * * The default fallback locale is used as fallback for locales that have no * fallback otherwise. * * @param string|null $locale The default fallback locale * * @see getFallback() */ public static function setDefaultFallback($locale) { self::$defaultFallback = $locale; } /** * Returns the default fallback locale. * * @return string|null The default fallback locale * * @see setDefaultFallback() * @see getFallback() */ public static function getDefaultFallback() { return self::$defaultFallback; } /** * Returns the fallback locale for a given locale. * * For example, the fallback of "fr_FR" is "fr". The fallback of "fr" is * the default fallback locale configured with {@link setDefaultFallback()}. * The default fallback locale has no fallback. * * @param string $locale The ICU locale code to find the fallback for * * @return string|null The ICU locale code of the fallback locale, or null * if no fallback exists */ public static function getFallback($locale) { if (\function_exists('locale_parse')) { $localeSubTags = locale_parse($locale); if (1 === \count($localeSubTags)) { if ('root' !== self::$defaultFallback && self::$defaultFallback === $localeSubTags['language']) { return 'root'; } // Don't return default fallback for "root", "meta" or others // Normal locales have two or three letters if (\strlen($locale) < 4) { return self::$defaultFallback; } return null; } array_pop($localeSubTags); $fallback = locale_compose($localeSubTags); return false !== $fallback ? $fallback : null; } if (false !== $pos = strrpos($locale, '_')) { return substr($locale, 0, $pos); } if (false !== $pos = strrpos($locale, '-')) { return substr($locale, 0, $pos); } if ('root' !== self::$defaultFallback && self::$defaultFallback === $locale) { return 'root'; } // Don't return default fallback for "root", "meta" or others // Normal locales have two or three letters return \strlen($locale) < 4 ? self::$defaultFallback : null; } /** * This class must not be instantiated. */ private function __construct() { } }
Name | Type | Size | Permission | Actions |
---|---|---|---|---|
Collator | Folder | 0755 |
|
|
Data | Folder | 0755 |
|
|
DateFormatter | Folder | 0755 |
|
|
Exception | Folder | 0755 |
|
|
Globals | Folder | 0755 |
|
|
Locale | Folder | 0755 |
|
|
NumberFormatter | Folder | 0755 |
|
|
ResourceBundle | Folder | 0755 |
|
|
Resources | Folder | 0755 |
|
|
Tests | Folder | 0755 |
|
|
Util | Folder | 0755 |
|
|
.gitignore | File | 34 B | 0644 |
|
CONTRIBUTING.md | File | 3.2 KB | 0644 |
|
Intl.php | File | 7.61 KB | 0644 |
|
LICENSE | File | 1.04 KB | 0644 |
|
Locale.php | File | 3.1 KB | 0644 |
|
README.md | File | 827 B | 0644 |
|
composer.json | File | 1.25 KB | 0644 |
|
phpunit.xml.dist | File | 984 B | 0644 |
|