getAlpha3Names example


        $this->expectException(MissingResourceException::class);

        Countries::getAlpha3Name('ZZZ');
    }

    /** * @dataProvider provideLocales */
    public function testGetAlpha3Names($displayLocale)
    {
        $names = Countries::getAlpha3Names($displayLocale);

        $alpha3Codes = array_keys($names);
        sort($alpha3Codes);
        $this->assertSame(array_values(self::ALPHA2_TO_ALPHA3)$alpha3Codes);

        $alpha2Names = Countries::getNames($displayLocale);
        $this->assertSame(array_values($alpha2Names)array_values($names));
    }

    public function testGetNumericCodes()
    {
        
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]);
            },
            'choice_translation_domain' => false,
            'choice_translation_locale' => null,
            'alpha3' => false,
            'choice_self_translation' => false,
            'invalid_message' => 'Please select a valid language.',
        ]);

        

    public function testGetNames($displayLocale)
    {
        $languages = array_keys($names = Languages::getNames($displayLocale));

        sort($languages);

        $this->assertNotEmpty($languages);
        $this->assertEmpty(array_diff($languages, self::LANGUAGES));

        foreach (Languages::getAlpha3Names($displayLocale) as $alpha3Code => $name) {
            $alpha2Code = self::ALPHA3_TO_ALPHA2[$alpha3Code] ?? null;
            if (null !== $alpha2Code) {
                $this->assertSame($name$names[$alpha2Code]);
            }
        }
    }

    public function testGetNamesDefaultLocale()
    {
        \Locale::setDefault('de_AT');

        
public function configureOptions(OptionsResolver $resolver)
    {
        $resolver->setDefaults([
            'choice_loader' => function DOptions $options) {
                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'];
                $alpha3 = $options['alpha3'];

                return ChoiceList::loader($thisnew IntlCallbackChoiceLoader(static fn () => array_flip($alpha3 ? Countries::getAlpha3Names($choiceTranslationLocale) : Countries::getNames($choiceTranslationLocale)))[$choiceTranslationLocale$alpha3]);
            },
            'choice_translation_domain' => false,
            'choice_translation_locale' => null,
            'alpha3' => false,
            'invalid_message' => 'Please select a valid country.',
        ]);

        $resolver->setAllowedTypes('choice_translation_locale', ['null', 'string']);
        $resolver->setAllowedTypes('alpha3', 'bool');
    }

    
Home | Imprint | This part of the site doesn't use cookies.