Skip to content

Commit

Permalink
Initial Src Commit
Browse files Browse the repository at this point in the history
  • Loading branch information
debascoguy committed May 24, 2023
1 parent 5439d93 commit 25a87f2
Show file tree
Hide file tree
Showing 18 changed files with 27,914 additions and 0 deletions.
69 changes: 69 additions & 0 deletions README.md
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. :)

21 changes: 21 additions & 0 deletions composer.json
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"
}
79 changes: 79 additions & 0 deletions src/Countries.php
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);
}

}
Loading

0 comments on commit 25a87f2

Please sign in to comment.