los/losi18n

提供路由、国家、地区和语言列表的多语言I18N中间件

资助包维护!
Lansoweb

3.0.0 2021-05-01 14:01 UTC

This package is auto-updated.

Last update: 2024-08-29 03:55:42 UTC


README

简介

此中间件提供语言、国家和地区的列表,支持所有语言的翻译。

需求

PHP 7.4 | 8.0 和任何与 container-interopt 兼容的项目。

安装

composer require los/losi18n

可选地,将配置文件复制到您的项目中。

I18n 数据

此模块需要从 losi18n-data 获取数据。因此,您需要将模块添加到您的项目中

添加 losi18n-data

composer require los/losi18n-data

文件格式

有三种格式:php、json 和 csv。如果您需要导入 json 文件,它位于:vendor/los/losi18n-data/data//languages.json vendor/los/losi18n-data/data//countries.json vendor/los/losi18n-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');