sokil/php-isocodes
PHP library for ISO code datasets with localized names: countries (ISO 3166-1/2/3), currencies (ISO 4217), languages (ISO 639-3) and scripts (ISO 15924). Supports Gettext or Symfony Translation drivers, with locale configuration.
Globalization & Localization (G11N/L10N) Features:
Data Integrity & Compliance:
Build vs. Buy Decision:
Roadmap Priorities:
Performance vs. Accuracy Tradeoffs:
php-isocodes-db-i18n for full localization (higher memory usage) or php-isocodes-db-only for lightweight code-only needs.pycountry for Python).| Scenario | Alternative | Pros | Cons |
|---|---|---|---|
| Lightweight needs | league/iso3166 |
Smaller footprint, ISO 3166-1 only | No subdivisions/languages/currencies |
| Real-time updates | ISO API (e.g., ISO Online Browsing) | Live data | Requires API calls, not local storage |
| Custom extensions | Build in-house | Full control | High maintenance burden |
| Symfony-only projects | Symfony’s Intl component |
Native integration | Limited to PHP’s Intl capabilities |
"This package solves a critical gap in our global product roadmap: accurate, localized ISO codes for countries, languages, and currencies—without manual updates or compliance risks. For example:
- E-commerce: Display product prices in local currencies (e.g., €, $, ¥) with correct names (e.g., ‘Euro’ vs. ‘EUR’).
- Regulatory compliance: Automatically validate addresses using ISO 3166-2 subdivisions (e.g., US states, EU regions).
- User experience: Let customers select their country in their native language (e.g., ‘Brasil’ in Portuguese vs. ‘Brazil’ in English).
It’s a turnkey solution—MIT-licensed, actively maintained, and integrates with our Laravel stack. The cost? Zero (open-source) vs. the risk of errors or delays if we build this in-house. Let’s prioritize this for [Q1 roadmap] to enable [global expansion/market feature]."
"Problem: Managing ISO codes manually is error-prone, especially for languages/currencies that change (e.g., new countries, renamed currencies).
Solution:
sokil/php-isocodesprovides:
- Comprehensive ISO standards: 3166-1/2/3 (countries/subdivisions), 639-3 (languages), 4217 (currencies), 15924 (scripts).
- Localization support: Works with Symfony Translation (for Symfony apps) or Gettext (Laravel). Example:
$country = (new IsoCodesFactory())->getCountries()->getByAlpha2('UA'); echo $country->getLocalName(); // 'Україна' (Ukrainian)- Flexible deployment:
- Lightweight:
php-isocodes-db-only(~1MB) for code-only needs.- Full i18n:
php-isocodes-db-i18n(~5MB) for localized names.- Self-hosted updates: Run
./bin/update_iso_codes_db.shvia CI/CD or cron.- Performance: Choose between partitioned files (low memory) or preloaded JSON (fast reads).
Integration:
- Laravel: Use the Symfony Translation driver or wrap in a service provider.
- Symfony: Native support via
SymfonyTranslationDriver.- Testing: Includes Dockerized tests for validation.
Risks:
- Memory usage (~5MB for full DB); mitigate by using
db-onlyvariant if localization isn’t needed.- Dependency on Composer updates; schedule quarterly reviews to align with ISO changes.
Recommendation: Start with
php-isocodes-db-i18nfor [Feature X] and evaluate memory impact. If overhead is prohibitive, usedb-onlyand add localization later via a separate translation layer."*
*"Quick Start:
- Install:
composer require sokil/php-isocodes-db-i18n # Full i18n # OR composer require sokil/php-isocodes-db-only # Codes only- Basic usage:
$isoCodes = new \Sokil\IsoCodes\IsoCodesFactory(); $country = $isoCodes->getCountries()->getByAlpha2('US'); echo $country->getName(); // 'United States' echo $country->getLocalName(); // Localized name (e.g., 'États-Unis' for French)- Symfony/Laravel: Configure the
SymfonyTranslationDriverorGettextExtensionDriverfor localization.Pro Tips:
- For subdivisions (e.g., US states), use
getSubdivisions()->getByCode('US-CA').- Update DB: Run
./bin/update_iso_codes_db.sh all /path/to/storagein CI/CD.- Memory optimization: Use partitioned mode (default) for low-memory environments.
Example Use Cases:
- Dropdowns: Populate country/language selectors with localized names.
- APIs: Return currency names in the user’s language (e.g.,
currency: { code: 'EUR', name: 'Euro' }).- Validation: Check if a country code is valid (e.g.,
if ($isoCodes->getCountries()->hasAlpha2('ZZ')) { ... })."*
How can I help you explore Laravel packages today?