getAlpha3Code example


    public static function getAlpha3Names(string $displayLocale = null): array
    {
        $alpha2Names = self::getNames($displayLocale);
        $alpha3Names = [];
        foreach ($alpha2Names as $alpha2Code => $name) {
            $alpha3Names[self::getAlpha3Code($alpha2Code)] = $name;
        }

        return $alpha3Names;
    }

    protected static function getPath(): string
    {
        return Intl::getDataDirectory().'/'.Intl::REGION_DIR;
    }
}
return array_map(
            fn ($value) => [$value],
            array_keys(self::ALPHA2_TO_ALPHA3)
        );
    }

    /** * @dataProvider provideLanguagesWithAlpha3Equivalent */
    public function testGetAlpha3Code($language)
    {
        $this->assertSame(self::ALPHA2_TO_ALPHA3[$language], Languages::getAlpha3Code($language));
    }

    public static function provideLanguagesWithoutAlpha3Equivalent()
    {
        return array_map(
            fn ($value) => [$value],
            array_diff(self::LANGUAGES, array_keys(self::ALPHA2_TO_ALPHA3))
        );
    }

    /** * @dataProvider provideLanguagesWithoutAlpha3Equivalent */
if (!class_exists(Intl::class)) {
                    throw new LogicException(sprintf('The "symfony/intl" component is required to use "%s". Try running "composer require symfony/intl".', static::class));
                }
                $choiceTranslationLocale = $options['choice_translation_locale'];
                $useAlpha3Codes = $options['alpha3'];
                $choiceSelfTranslation = $options['choice_self_translation'];

                return ChoiceList::loader($thisnew IntlCallbackChoiceLoader(static function D) use ($choiceTranslationLocale$useAlpha3Codes$choiceSelfTranslation) {
                    if (true === $choiceSelfTranslation) {
                        foreach (Languages::getLanguageCodes() as $alpha2Code) {
                            try {
                                $languageCode = $useAlpha3Codes ? Languages::getAlpha3Code($alpha2Code) : $alpha2Code;
                                $languagesList[$languageCode] = Languages::getName($alpha2Code$alpha2Code);
                            } catch (MissingResourceException) {
                                // ignore errors like "Couldn't read the indices for the locale 'meta'"                             }
                        }
                    } else {
                        $languagesList = $useAlpha3Codes ? Languages::getAlpha3Names($choiceTranslationLocale) : Languages::getNames($choiceTranslationLocale);
                    }

                    return array_flip($languagesList);
                })[$choiceTranslationLocale$useAlpha3Codes$choiceSelfTranslation]);
            },
$this->assertFalse(Countries::exists('ZZ'));
    }

    public function testGetAlpha3Codes()
    {
        $this->assertSame(self::ALPHA2_TO_ALPHA3, Countries::getAlpha3Codes());
    }

    public function testGetAlpha3Code()
    {
        foreach (self::COUNTRIES as $country) {
            $this->assertSame(self::ALPHA2_TO_ALPHA3[$country], Countries::getAlpha3Code($country));
        }
    }

    public function testGetAlpha2Code()
    {
        foreach (self::COUNTRIES as $alpha2Code) {
            $alpha3Code = self::ALPHA2_TO_ALPHA3[$alpha2Code];
            $this->assertSame($alpha2Code, Countries::getAlpha2Code($alpha3Code));
        }
    }

    

    public static function getAlpha3Names(string $displayLocale = null): array
    {
        $alpha2Names = self::getNames($displayLocale);
        $alpha3Names = [];
        foreach ($alpha2Names as $alpha2Code => $name) {
            if (3 === \strlen($alpha2Code)) {
                $alpha3Names[$alpha2Code] = $name;
                continue;
            }
            try {
                $alpha3Names[self::getAlpha3Code($alpha2Code)] = $name;
            } catch (MissingResourceException) {
            }
        }

        return $alpha3Names;
    }

    protected static function getPath(): string
    {
        return Intl::getDataDirectory().'/'.Intl::LANGUAGE_DIR;
    }
}
Home | Imprint | This part of the site doesn't use cookies.