dominservice / data_locale_parser
数据区域解析器是一个针对Laravel 5.6 | 5.7 | 5.8 | 6.* | 7.* | 8.* | 9.* | 10.*的包,列出了所有国家、货币和语言,包括所有语言和格式下的名称和ISO 3166代码。
1.5.0
2023-05-29 09:36 UTC
Requires
- php: >=7.1.3
- ext-intl: *
- ext-mbstring: *
- laravel/framework: ^5.6|^5.7|^5.8|^6|^7|^8|^9|^10
README
数据区域解析器是一个针对Laravel 5.6 | 5.7 | 5.8 | 6.* | 7.* | 8.* | 9.* | 10.*的包,列出了所有国家、货币和语言,包括所有语言和格式下的名称和ISO 3166-1代码。
安装
使用Composer安装包:composer require dominservice/data_locale_parser
用法
- 区域设置(en, en_US, fr, fr_CA...)
- 如果没有提供区域设置(或者设置为null),则默认为'en'
声明用法
use \Dominservice\DataLocaleParser\DataParser;
(...)
private $dataParser;
(...)
public function __construct() { $this->dataParser = new DataParser(); }
获取所有国家
$this->dataParser->getListCountries('en');
获取所有货币
$this->dataParser->getListCurrencies('en');
获取所有语言
$this->dataParser->getListLanguages('en');
所有列表返回一个集合
获取国家
$this->dataParser->getCountry('PL', 'en');
获取货币
$this->dataParser->getCurrency('PLN', 'en');
获取语言
$this->dataParser->geLanguage('pl_PL', 'en');
如果您已收集所有数据,可以使用以下代码
$this->dataParser->parseAllDataPerCountry('pl_PL');
然后您将获得
Illuminate\Support\Collection {▼ #items: [ 0 => {#1992 ▼ +"so": "PL" +"iso3": "POL" +"iso_nr": "616" +"fips": "PL" +"continent": "EU" +"tld": ".pl" +"phone": "48" +"postal_code_format": "##-###" +"postal_code_regex": "^\d{2}-\d{3}$" +"currency": {#1991 ▼ +"name": "złoty polski" +"code": "PLN" +"symbol": "zł" } +"languages": array:1 [▼ "pl" => "polski" ] +"country": "Polska" +"subdivision_iso3166": Illuminate\Support\Collection {#2275 ▼ #items: array:16 [▼ "PL-02" => array:2 [▼ "name" => "Dolnośląskie" "name_ascii" => "Dolnoslaskie" ] "PL-04" => array:2 [▼ "name" => "Kujawsko-pomorskie" "name_ascii" => "Kujawsko-pomorskie" ] "PL-06" => array:2 [▼ "name" => "Lubelskie" "name_ascii" => "Lubelskie" ] "PL-08" => array:2 [▼ "name" => "Lubuskie" "name_ascii" => "Lubuskie" ] "PL-10" => array:2 [▼ "name" => "Łódzkie" "name_ascii" => "Lodzkie" ] "PL-12" => array:2 [▼ "name" => "Małopolskie" "name_ascii" => "Malopolskie" ] "PL-14" => array:2 [▼ "name" => "Mazowieckie" "name_ascii" => "Mazowieckie" ] "PL-16" => array:2 [▼ "name" => "Opolskie" "name_ascii" => "Opolskie" ] "PL-18" => array:2 [▼ "name" => "Podkarpackie" "name_ascii" => "Podkarpackie" ] "PL-20" => array:2 [▼ "name" => "Podlaskie" "name_ascii" => "Podlaskie" ] "PL-22" => array:2 [▼ "name" => "Pomorskie" "name_ascii" => "Pomorskie" ] "PL-24" => array:2 [▼ "name" => "Śląskie" "name_ascii" => "Slaskie" ] "PL-26" => array:2 [▶] "PL-28" => array:2 [▼ "name" => "Warmińsko-mazurskie" "name_ascii" => "Warminsko-mazurskie" ] "PL-30" => array:2 [▼ "name" => "Wielkopolskie" "name_ascii" => "Wielkopolskie" ] "PL-32" => array:2 [▼ "name" => "Zachodniopomorskie" "name_ascii" => "Zachodniopomorskie" ] ] } } ... }
您可能获得一个国家的完整数据
$this->dataParser->parseAllDataPerCountry('pl_PL', 'PL');