Requires:
- PHP
Intl
extension
The peace of code:
function getLanguage(string $country): string {
$subtags = \ResourceBundle::create('likelySubtags', 'ICUDATA', false);
$country = \Locale::canonicalize('und_'.$country);
$locale = $subtags->get($country) ?: $subtags->get('und');
return \Locale::getPrimaryLanguage($locale);
}
1
2
3
4
5
6
2
3
4
5
6
Refs:
- https://newbedev.com/is-there-a-simple-way-to-get-the-language-code-from-a-country-code-in-php
Comment