emma/internationalization

A PHP 7.0+ 国际化库和服务,用于获取所有世界国家、国家州、国家的货币/货币、符号、区域和语言。它还包括:数字格式化器、十进制格式化器和货币格式化器。通过国家名称、isoAlphaCode2 或 i 进行货币格式化。

v1.0.1 2023-05-27 22:46 UTC

This package is auto-updated.

Last update: 2024-09-30 02:26:11 UTC


README

A PHP 7.0+ 国际化库和服务,用于获取所有

  • 世界国家、
  • 国家州、
  • 国家的货币/货币、
  • 符号、区域和
  • 语言。

它还包括

  • 数字格式化器、
  • 十进制格式化器和
  • 货币格式化器:通过国家名称、isoAlphaCode2 或 isoAlphaCode3 进行货币格式化。

我不想用一大堆文字来说明为什么你应该或不应该使用这个库,因为我坚信没有人会拒绝解决问题的工具。所以,这里有一些例子,说明它可以用来解决国际化问题。

use Emma\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.

如果你查看 Countries 类,你会发现有很多函数可以用来进行各种国际化操作。上面的例子只是展示了这个库对你有多有用。 :)