-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
5439d93
commit 25a87f2
Showing
18 changed files
with
27,914 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,71 @@ | ||
# intlCountries | ||
|
||
|
||
A PHP 7.0+ internationalization library and services for getting all the | ||
- world countries, | ||
- country states, | ||
- country's currency/currencies, | ||
- symbols, locale and | ||
- languages. | ||
|
||
It also includes: | ||
- Number Formatter, | ||
- Decimal Formatter and | ||
- Currency Formatter : currency formatter by country name, isoAlphaCode2 or isoAlphaCode3. | ||
|
||
I am not going to bore you with lots of write-up to justify why you should or should not use this library as I strongly believe nobody says no to problem solving tools. So, here are the example as it can be used to solve internationalization problems: | ||
|
||
```php | ||
|
||
use Countries\Countries; | ||
|
||
//VERY IMPORTANT - All function that returns an object also has there corresponding function that returns an array data set. | ||
|
||
/** | ||
* GET ALL | ||
*/ | ||
//Get all - COUNTRIES | ||
$countries = Countries::getCountryRepository()->findAllCountry(); | ||
|
||
//Get all - CURRENCIES - countries and there currency(s) information | ||
$currencies = Countries::getCurrencyRepository()->findAllCountryAndCurrency(); | ||
|
||
//Get all - LANGUAGE - locales of all countries. Data incliudes: isoAlphaCode2, isoAlphaCode3, locales, defaultLocale, language of countries. | ||
$locales = Countries::getLocaleRepository()->findAllLocales(); | ||
|
||
|
||
/** | ||
* FIND SOMETHING SPECIFIC | ||
*/ | ||
//Get a particular country locales information - By countryName OR country isoAlphaCode2 OR country isoAlphaCode2. | ||
$countryNameORisoAlphaCode2ORisoAlphaCode2 = 'US'; //OR USD OR United States of America | ||
$countryLocales = Countries::getLocaleRepository()->findLocale(string $countryNameORisoAlphaCode2ORisoAlphaCode2) | ||
|
||
//Get a particular country information - By countryName OR country isoAlphaCode2 OR country isoAlphaCode2. | ||
//Data includes: name, all states in that country, currencies, default_country of that country, etc... | ||
$countryNameORisoAlphaCode2ORisoAlphaCode2 = 'US'; //OR USD OR United States of America | ||
$countryInformation = (Countries::getCountryRepository()->findCountry($countryNameORisoAlphaCode2ORisoAlphaCode2)); | ||
|
||
//Get a particular country currency detailed information. For example: | ||
$code = 'NGN'; | ||
$currency = (Countries::getCurrencyRepository()->findCurrencyDetails($code)); | ||
|
||
/** | ||
* FORMATTERS | ||
*/ | ||
//Format Currency using countryName OR country isoAlphaCode2 OR country isoAlphaCode2 | ||
echo $formatedAmount = Countries::formatCurrencyByCountry(5.0, 'NG'); | ||
echo $formatedAmount = Countries::formatCurrencyByCountry(5.0, 'NGA'); | ||
echo $formatedAmount = Countries::formatCurrencyByCountry(5.0, 'Nigeria'); | ||
|
||
//Similarly format Decimal Number By countryName OR country isoAlphaCode2 OR country isoAlphaCode2 | ||
echo $formatedAmount = Countries::formatDecimalByCountry(5.0, 'NG'); | ||
echo $formatedAmount = Countries::formatDecimalByCountry(5.0, 'NGA'); | ||
echo $formatedAmount = Countries::formatDecimalByCountry(5.0, 'Nigeria'); | ||
|
||
//VERY IMPORTANT - All function that returns an object also has there corresponding function that returns an array data set. | ||
|
||
``` | ||
|
||
If you check the `Countries` class, there are lots functions you can use for so many different internationalization. The example above are a few of how useful this library is to you. :) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
{ | ||
"name": "emma/internationalization", | ||
"description": "A PHP 7.0+ internationalization library and services for getting all the world countries, country states, country's currency/currencies, symbols, locale and languages. It also includes: number formatter, decimal formatter and currency formatter. currency formatter by country name, isoAlphaCode2 or isoAlphaCode3.", | ||
"authors": [ | ||
{ | ||
"name": "Ademola Aina", | ||
"email" : "debascoguy@gmail.com", | ||
"homepage": "https://github.com/debascoguy/intlCountries", | ||
"role": "Founder/Lead Software Developer" | ||
} | ||
], | ||
"require": { | ||
"php": ">=7.0" | ||
}, | ||
"autoload": { | ||
"psr-4": { | ||
"Countries\\": "Src/" | ||
} | ||
}, | ||
"license": "GPL-2.0-only" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
<?php | ||
|
||
namespace Countries; | ||
|
||
use Countries\Formatter\CurrencyFormatter; | ||
use Countries\Formatter\DecimalFormatter; | ||
use Countries\Repository\CountryRepository; | ||
use Countries\Repository\CurrencyRepository; | ||
use Countries\Repository\LocaleRepository; | ||
use Countries\Repository\StatesRepository; | ||
|
||
class Countries { | ||
|
||
/** | ||
* @return CountryRepository | ||
*/ | ||
public static function getCountryRepository(): CountryRepository | ||
{ | ||
return CountryRepository::getInstance(); | ||
} | ||
|
||
/** | ||
* @return CurrencyRepository | ||
*/ | ||
public static function getCurrencyRepository(): CurrencyRepository | ||
{ | ||
return CurrencyRepository::getInstance(); | ||
} | ||
|
||
/** | ||
* @return LocaleRepository | ||
*/ | ||
public static function getLocaleRepository(): LocaleRepository | ||
{ | ||
return LocaleRepository::getInstance(); | ||
} | ||
|
||
/** | ||
* @return StatesRepository | ||
*/ | ||
public static function getStatesRepository(): StatesRepository | ||
{ | ||
return StatesRepository::getInstance(); | ||
} | ||
|
||
/** | ||
* @param string $locale | ||
* @return string | ||
*/ | ||
public static function formatCurrencyByCountry(float $amount, string $countryNameORisoAlphaCode2ORisoAlphaCode2): string | ||
{ | ||
return CurrencyFormatter::formatCurrencyByCountry($amount, $countryNameORisoAlphaCode2ORisoAlphaCode2); | ||
} | ||
|
||
/** | ||
* @return string | ||
*/ | ||
public static function formatCurrencyBy(float $amount, string $locale, string $currency): string | ||
{ | ||
return CurrencyFormatter::createCurrencyFormatter($locale)->formatCurrency($amount, $currency); | ||
} | ||
|
||
/** | ||
* @return string | ||
*/ | ||
public static function formatDecimalByCountry(float $amount, string $countryNameORisoAlphaCode2ORisoAlphaCode2): string | ||
{ | ||
return DecimalFormatter::formatDecimalByCountry($amount, $countryNameORisoAlphaCode2ORisoAlphaCode2); | ||
} | ||
|
||
/** | ||
* @return string | ||
*/ | ||
public static function formatDecimalByLocale(float $amount, string $locale): string | ||
{ | ||
return DecimalFormatter::formatDecimalByLocale($amount, $locale); | ||
} | ||
|
||
} |
Oops, something went wrong.