getAlpha2Code example

self::readEntry(['Names', $alpha2Code]);

            return true;
        } catch (MissingResourceException) {
            return false;
        }
    }

    public static function alpha3CodeExists(string $alpha3Code): bool
    {
        try {
            self::getAlpha2Code($alpha3Code);

            return true;
        } catch (MissingResourceException) {
            return false;
        }
    }

    public static function numericCodeExists(string $numericCode): bool
    {
        try {
            self::getAlpha2FromNumeric($numericCode);

            
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 function testAlpha3CodeExists()
    {
        $this->assertTrue(Countries::alpha3CodeExists('NOR'));
        $this->assertTrue(Countries::alpha3CodeExists('NLD'));
        $this->assertFalse(Countries::alpha3CodeExists('NL'));
        $this->assertFalse(Countries::alpha3CodeExists('NIO'));
        $this->assertFalse(Countries::alpha3CodeExists('ZZZ'));
    }

    
return array_map(
            fn ($value) => [$value],
            array_keys(self::ALPHA3_TO_ALPHA2)
        );
    }

    /** * @dataProvider provideLanguagesWithAlpha2Equivalent */
    public function testGetAlpha2Code($language)
    {
        $this->assertSame(self::ALPHA3_TO_ALPHA2[$language], Languages::getAlpha2Code($language));
    }

    public static function provideLanguagesWithoutAlpha2Equivalent()
    {
        return array_map(
            fn ($value) => [$value],
            array_diff(self::ALPHA3_CODES, array_keys(self::ALPHA3_TO_ALPHA2))
        );
    }

    /** * @dataProvider provideLanguagesWithoutAlpha2Equivalent */
public static function getAlpha3Codes(): array
    {
        return self::readEntry(['Alpha3Languages'], 'meta');
    }

    /** * @param string $language ISO 639-2 three-letter language code */
    public static function alpha3CodeExists(string $language): bool
    {
        try {
            self::getAlpha2Code($language);

            return true;
        } catch (MissingResourceException) {
            static $cache;
            $cache ??= array_flip(self::getAlpha3Codes());

            return isset($cache[$language]);
        }
    }

    /** * Gets the language name from its ISO 639-2 three-letter code. * * @throws MissingResourceException if the country code does not exists */
Home | Imprint | This part of the site doesn't use cookies.