mehr-it / lara-countries
可扩展的多语言国家列表,适用于Laravel
1.4.0
2022-12-20 10:38 UTC
Requires
- php: >=7.1
- ext-json: *
- laravel/framework: ^5.8|^6.0|^7.0|^8.0
- mehr-it/php-cache: ^1.0
- umpirsky/country-list: ^2.0
- umpirsky/language-list: ^1.1
Requires (Dev)
- orchestra/testbench: ^3.8|^4.0|^5.0|^6.0
- phpunit/phpunit: ^7.4|^8.0
This package is auto-updated.
Last update: 2024-09-20 00:03:15 UTC
README
包含所有ISO代码的本地化国家语言列表,适用于Laravel。
国家列表包含以下数据
- alpha-2国家代码(ISO 3166-1)
- alpha-3国家代码(ISO 3166-1)
- 国家名称(在所有地区)
- 电话区号(例如,德国为49)
语言列表包含以下数据
- alpha-2语言代码(ISO 639-1)
- 语言名称(在所有地区)
与其他许多包不同,它不使用硬编码的列表,而是将选定的数据导入数据库。为了提高性能,数据以PHP文件的形式本地缓存,并通过中央应用缓存同步。
这样您可以获得最佳性能,同时仍然可以自由编辑数据。
安装
使用composer安装此包。Laravel的包自动发现将为您完成剩余工作
composer require mehr-it/lara-countries
导入国家数据
安装后,您需要将数据导入数据库:要导入国家/语言列表,运行以下命令
artisan countries:import
artisan languages:import
这将导入国家/语言列表。如果您需要除“en”之外的其他地区,可以使用以下命令导入它们
artisan countries:importLocale de
artisan languages:importLocale de
用法
您可以使用Countries
外观访问国家信息
// get country information
Countries::get('US');
// get country information with other locale than the application locale
Countries::get('US', 'de');
// check if country code exists
Countries::exists('US');
// list all countries
Countries::all();
// list all countries with other locale than the application locale
Countries::all('de');
// list all iso2 codes
Countries::allIso2Codes();
您可以使用Languages
外观访问语言信息
// get language information
Languages::get('en');
// get language information with other locale than the application locale
Languages::get('en', 'de');
// check if language code exists
Languages::exists('US');
// list all languages
Languages::all();
// list all languages with other locale than the application locale
Languages::all('de');
// list all iso2 codes
Languages::allIso2Codes();