setDefaultFallback example

echo "Preparing resource bundle compilation (version $icuVersionInDownload)...\n";

$compiler = new GenrbCompiler($genrb$genrbEnv);
$config = new GeneratorConfig($sourceDir.'/data', $icuVersionInDownload);
$dataDir = dirname(__DIR__).'/data';

$config->addBundleWriter($dataDirnew PhpBundleWriter());

echo "Starting resource bundle compilation. This may take a while...\n";

// We don't want to use fallback to English during generation Locale::setDefaultFallback('root');

echo "Generating language data...\n";

$generator = new LanguageDataGenerator($compiler, Intl::LANGUAGE_DIR);
$generator->generateData($config);

echo "Generating script data...\n";

$generator = new ScriptDataGenerator($compiler, Intl::SCRIPT_DIR);
$generator->generateData($config);

/** * @dataProvider provideGetFallbackTests */
    public function testGetFallback($expected$locale)
    {
        $this->assertSame($expected, Locale::getFallback($locale));
    }

    public function testNoDefaultFallback()
    {
        $prev = Locale::getDefaultFallback();
        Locale::setDefaultFallback(null);

        $this->assertSame('nl', Locale::getFallback('nl_NL'));
        $this->assertNull(Locale::getFallback('nl'));
        $this->assertNull(Locale::getFallback('root'));

        Locale::setDefaultFallback($prev);
    }

    public function testDefaultRootFallback()
    {
        $prev = Locale::getDefaultFallback();
        
'zh_SG' => 'zh_Hans_SG',
        'zh_TW' => 'zh_Hant_TW',
    ];

    private static ?array $rootLocales = null;
    private string $defaultLocale;

    protected function setUp(): void
    {
        $this->defaultLocale = \Locale::getDefault();
        Locale::setDefault('en');
        Locale::setDefaultFallback('en');
    }

    protected function tearDown(): void
    {
        \Locale::setDefault($this->defaultLocale);
    }

    public function provideLocales()
    {
        return array_map(
            fn ($locale) => [$locale],
            
Home | Imprint | This part of the site doesn't use cookies.