PHP Classes

PHP Get Locale from CountryCode: Determine locale language from country code

Recommend this page to a friend!
  Info   View files Documentation   View files View files (4)   DownloadInstall with Composer Download .zip   Reputation   Support forum   Blog    
Ratings Unique User Downloads Download Rankings
StarStarStar 58%Total: 331 All time: 7,138 This week: 560Up
Version License PHP version Categories
country-to-locale 1.0.7Custom (specified...5Localization, PHP 5, Geography


This class can determine locale language from country code.

It can take the code of a country and converts it to the locale name that identifies the country and language used in that country.

For countries that use different languages, it returns a string with all locale names separated by commas.

Innovation Award
PHP Programming Innovation award nominee
April 2017
Number 13
Locale is the definition of settings that change from country to country, like the language and the way to format values like time, dates and money amounts.

Each locale has a name string formed by the country and the language or languages associated with that country.

This class can determine which locales are associated with each country and returns a string with the names of the country locales.

Manuel Lemos
Picture of Peter Kahl
  Performance   Level  
Name: Peter Kahl <contact>
Classes: 37 packages by
Country: United Kingdom
Age: ???
All time rank: 41721 in United Kingdom
Week rank: 91 Up4 in United Kingdom Up
Innovation award
Innovation award
Nominee: 23x

Winner: 2x



Downloads Download per Month License If this project has business value for you then don't hesitate to support me with a small donation.

Determine locale from country code.


use peterkahl\locale\locale;

echo locale::country2locale('hk')."\n";
echo locale::country2locale('DE')."\n";
echo locale::country2locale('gb')."\n";

/* Prints:

  Files folder image Files  
File Role Description
Files folder imagesrc (1 file)
Accessible without login Plain text file composer.json Data Auxiliary data
Accessible without login Plain text file LICENSE Lic. License text
Accessible without login Plain text file Doc. Documentation

  Files folder image Files  /  src  
File Role Description
  Plain text file locale.php Class Class source

 Version Control Unique User Downloads Download Rankings  
This week:0
All time:7,138
This week:560Up
 User Ratings  
 All time