umpirsky/language-list
Provides language name lists in many locales (ISO-based), ready for PHP apps. Includes localized language names and easy lookup, useful for forms, selectors, and internationalized UIs, with data sourced from standards/CLDR and kept up to date.
Installation Add the package via Composer:
composer require umpirsky/language-list
No additional configuration is needed—it’s a self-contained library.
First Use Case: Fetching Language Data Load the language list in a controller or service:
use Umpirsky\LanguageList\LanguageList;
$languageList = new LanguageList();
$languages = $languageList->getAllLanguages();
Outputs an array of all languages with ISO 639-1 codes and names in multiple languages.
Where to Look First
Umpirsky\LanguageList\LanguageList (main entry point).getAllLanguages() variants).Fetching Languages in a Specific Format
// JSON output
$json = $languageList->getAllLanguages('json');
// XML output
$xml = $languageList->getAllLanguages('xml');
Filtering Languages by Code
$english = $languageList->getLanguage('en');
// Returns: ['name' => 'English', 'native' => 'English', ...]
Localization in Views
// In a Blade template
@php
$languageList = new \Umpirsky\LanguageList\LanguageList();
$spanishName = $languageList->getLanguage('es')['native'];
@endphp
<select>
<option value="es">{{ $spanishName }}</option>
</select>
Integration with Laravel Localization
Combine with laravel-localization or spatie/laravel-translatable for dynamic language switching:
$currentLang = app()->getLocale();
$currentLangName = $languageList->getLanguage($currentLang)['native'];
Caching for Performance Cache the language list in a service provider:
public function boot()
{
$this->app->singleton(LanguageList::class, function () {
return Cache::remember('language-list', now()->addYear(), function () {
return new LanguageList();
});
});
}
ISO 639-1 vs. ISO 639-2/3
en, es).eng, spa), map them manually or use a helper:
$iso6391To6392 = [
'en' => 'eng',
'es' => 'spa',
// ...
];
Missing Codes
zh covers both Chinese variants).$languageList->getAllLanguages() for gaps.Memory Usage
Verify Data Integrity
$allCodes = array_column($languageList->getAllLanguages(), 'code');
sort($allCodes);
// Compare with expected ISO 639-1 list (e.g., from [Wikipedia](https://en.wikipedia.org/wiki/List_of_ISO_639-1_codes)).
Locale-Specific Names
If a language name is missing in a locale (e.g., ['native'] for fr in az):
$frenchInAzerbaijani = $languageList->getLanguage('fr')['native'] ?? 'French (Azerbaijani name missing)';
Custom Data Formats Extend the library by adding a new format method:
class ExtendedLanguageList extends LanguageList {
public function getAllLanguagesAsYaml()
{
return yaml_encode($this->getAllLanguages());
}
}
Merge with User Data Override or extend the data array before passing it to views:
$customLanguages = $languageList->getAllLanguages();
$customLanguages[] = ['code' => 'xx', 'name' => 'Custom Language', 'native' => 'Custom'];
Testing
Mock the LanguageList class in tests:
$mock = Mockery::mock(LanguageList::class);
$mock->shouldReceive('getLanguage')->andReturn(['code' => 'en', 'name' => 'Test']);
Performance Optimization
if (!function_exists('get_language_name')) {
function get_language_name($code) {
static $list;
if (!$list) {
$list = new LanguageList();
}
return $list->getLanguage($code)['native'] ?? $code;
}
}
How can I help you explore Laravel packages today?