zooxsmart / los-i18n
I18N 中间件,提供所有语言的路线、国家和区域列表
1.0.2
2023-11-08 09:15 UTC
Requires
- php: ^8.2
- ext-json: *
- psr/container: ^1.0 || ^2.0
Requires (Dev)
- doctrine/coding-standard: ^12.0.0
- ergebnis/composer-normalize: ^2.39
- phpstan/phpstan: ^1.10.39
- squizlabs/php_codesniffer: ^3.7.2
- vimeo/psalm: ^5.15
Suggests
- zoxsmart/los-i18n-data: Data files for LosI18n.
README
简介
此中间件提供所有语言的翻译后的语言、国家和区域列表。
要求
PHP 7.4 | 8.0 和任何兼容 container-interopt 项目的项目。
安装
composer require zooxsmart/los-i18n
可选地,将配置文件复制到您的项目中。
I18n 数据
此模块需要来自 los-i18n-data 的数据。因此,您需要将模块添加到您的项目中
添加 los-i18n-data
composer require zooxsmart/los-i18n-data
文件格式
有 3 种格式:php、json 和 csv。如果您需要导入 json 文件,它位于:vendor/zooxsmart/los-i18n-data/data//languages.json vendor/zooxsmart/los-i18n-data/data//countries.json vendor/zooxsmart/los-i18n-data/data//regions.json
用法
语言列表
$languagesService = $sm->get('losi18n-countries'); // All languages translated to pt_BR $languages = $countriesService->getAllLanguages('pt_BR'); // All languages in their native names $languages = $countriesService->getNativeLanguages(); // Brazilian Portuguese in English $language = $countriesService->getLanguage('pt_BR', 'en);
国家列表
$countriesService = $sm->get('losi18n-countries'); // All officially assigned countries translated to English $countries = $countriesService->getAllCountries('en'); // All countries translated to English $countries = $countriesService->getAllCountries('en', false); // United States translated to Brazilian Portuguese $country = $countriesService->getCountry('US','pt_BR');
区域列表
$regionsService = $sm->get('losi18n-regions'); $regions = $countriesService->getAllRegions('pt_BR');