Country codes and regional differences
Source: Dev.to
Supporting Kosovo with Symfony Intl
Symfony’s Intl component does not include Kosovo because its ISO 3166‑1 code XK is a user‑assigned code, not an official one. Consequently, calls such as Countries::getNames() will not list Kosovo.
use Symfony\Component\Intl\Countries;
$countries = Countries::getNames();
isset($countries['XK']); // false
Countries::getName('XK'); // Throws MissingResourceException
Fix: Enable user‑assigned codes
Add the following line to your .env file:
# .env
SYMFONY_INTL_WITH_USER_ASSIGNED=true
After enabling this flag, Symfony recognises Kosovo and its related codes:
use Symfony\Component\Intl\Countries;
Countries::getName('XK'); // 'Kosovo'
Countries::getAlpha2Code('XKK'); // 'XK'
Countries::getAlpha3Code('XK'); // 'XKK'
Countries::getNumericCode('XK'); // 983
This one‑liner removes the need for custom workarounds when your application must handle regions that rely on user‑assigned country codes.