Download the PHP package sokil/php-isocodes without Composer
On this page you can find all versions of the php package sokil/php-isocodes. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download sokil/php-isocodes
More information about sokil/php-isocodes
Files in sokil/php-isocodes
Package php-isocodes
Short Description ISO country, subdivision, language, currency and script definitions and their translations. Based on pythons pycountry and Debian's iso-codes.
License MIT
Informations about the package php-isocodes
Stand With Ukraine 🇺🇦
PHP ISO Codes
:star: This library used to get localized names of countries, currencies, languages and scripts.
:package: Based on Python's pycountry and Debian's iso-codes.
:tongue: Current translation status: https://salsa.debian.org/iso-codes-team/iso-codes#status-of-translations
Table of contents
- ISO Standards
- Installation
- Translation drivers
- Gettext extension driver
- Locale configuration
- Symfony Translation driver
- Dummy driver
- Usage
- Locale configuration
- Countries database (ISO 3166-1)
- Subdivisions database (ISO 3166-2)
- Historic countries database (ISO 3166-3)
- Scripts database (ISO 15924)
- Currencies database (ISO 4217)
- Languages database (ISO 639-3)
- Tests
ISO Standards
- ISO 3166-1: Country codes (alpha-2, alpha-3, numeric)
- ISO 3166-2: Principal subdivisions (e.g., provinces or states) of all countries coded in ISO 3166-1
- ISO 3166-3: Historic countries (alpha-2, alpha-3, alpha-4, numeric)
- ISO 15924: Scripts
- ISO 4217: Currencies
- ISO 639-3: Languages
Installation
You may use this library in different modes:
sokil/php-isocodes
(this library) - install library without database and messages and setup periodic updates of database and messages by yourself with cron or inside CI/CD pipeline with./bin/update_iso_codes_db.sh
- sokil/php-isocodes-db-only - if you do not need internationalisation, use this library. Database already inside. To update database just periodically update this library.
- sokil/php-isocodes-db-i18n - if you need internationalisation, use this library. Database and messages already inside. To update database just periodically update this library.
💾 Library with included database and localization
To install library with database and i18n:
💾 Library with included database and without localization
You may also install library with only database (no i18n will be available):
💾 Library without database and localization, requires manual database installation and updates
You can install library through Composer:
Database and gettext files located in related packages inside databases
and messages
directories.
This packages periodically updated with package version increment.
If you want to update database, use script ./bin/update_iso_codes_db.sh
.
Call this script by cron, during deploy process or when build your docker image.
Argument | Required | Description | |
---|---|---|---|
mode | Required | May be "all" or "db_only". In "all" mode update database (json files) and locallisation (po and mo files), in "db_only" only database will update | |
base_dir | Required | Dir where to place database and messages | \ |
build_dir | Optional. Default: "/tmp/iso-codes-build" | Dir where source directory cloned and files original files processed. |
Now you need to configure factory to use this directory:
Translation drivers
- Gettext extension driver
- Locale configuration
- Symfony Translation driver
- Dummy driver
Translation drivers required when need to get local names of iso entities.
Translation driver must implement Sokil\IsoCodes\TranslationDriver\TranslationDriverInterface
.
Instance of driver may be passed to IsoCodesFactory
. If it not passed, default GettextExtensionDriver
will be used.
Gettext extension driver
This is default translation driver. It requires ext-gettext
.
Locale configuration
Before using IsoCodes database you need to setup valid locale to get translations worked,
because ext-gettext
uses system local, configured by setlocale
.
To get list of available locales, execute under console:
If you don't see required locales in list, you may install them manually (for Ubuntu):
Symfony Translation driver
Dummy driver
This driver may be used, when localisation of names does not require, and only database of codes is required.
Usage
- Factory
- Countries database (ISO 3166-1)
- Subdivisions database (ISO 3166-2)
- Historic countries database (ISO 3166-3)
- Scripts database (ISO 15924)
- Currencies database (ISO 4217)
- Languages database (ISO 639-3)
Factory
All databases may be created through factory:
There are large databases: subdivisions and languages. Loading of entire database into memory may require lot of RAM and time to create all entries in memory.
So there are scenarios of usage: with optimisations of memory and with optimisation of time.
Memory optimisation
Database splits into partition files.
Fetching some entry will load only little part of database. Loaded entries not stored statically.
This scenario may be useful when just few entries need to be loaded, for example on web request when one entry fetched.
This may require a lot of file read operations.
Input-output optimisations
Entire database loaded into memory from single JSON file once.
All entries created and stored into RAM. Next read of save entry will just return it without io operations with files and building objects.
This scenario may be useful for daemons to decrease file operations, or when most entries will be fetched from database.
This may require a lot of RAM for storing all entries.
Countries database (ISO 3166-1)
Country contains next names:
Name | Description | Example |
---|---|---|
Name | Required | Moldova, Republic of |
Official Name | Optional | Republic of Moldova |
Common Name | Optional | Moldova |
Localised Name | Optional | Молдова |
This names may be get from country entity:
Also you may get flag of country:
Get localized name of country by it's alpha2 code:
Get localized name of country by it's alpha3 code:
Get localized name of country by it's numeric code:
Get localised list of countries
Subdivisions database (ISO 3166-2)
Historic countries database (ISO 3166-3)
Scripts database (ISO 15924)
Currencies database (ISO 4217)
Languages database (ISO 639-3)
Tests
To start docker tests run following command:
For example for PHP 7.1 run following command:
See also
- State Classifier of objects of administrative and territorial structure of Ukraine - generates database of detailed list of cities and settlements of Ukraine
- A Symfony's PHP replacement layer for the C intl extension that also provides access to the localization data of the ICU library
- FamFacFam icon pack with flags
All versions of php-isocodes with dependencies
ext-json Version *