torann / localization
Laravel 的简单子域本地化。
2.0.2
2024-03-22 18:51 UTC
Requires
- php: ^8.0.2
- illuminate/http: ^8.0|^9.0|^10.0|^11.0
- illuminate/routing: ^8.0|^9.0|^10.0|^11.0
- illuminate/support: ^8.0|^9.0|^10.0|^11.0
Requires (Dev)
- mockery/mockery: ^1.3
- phpstan/phpstan: ^0.12.14
- phpunit/phpunit: ^8.0
- squizlabs/php_codesniffer: ^3.5
README
基于应用子域的 Laravel 简化本地化。
目录
安装
Composer
在命令行中运行
$ composer require torann/localization
Laravel
安装完成后,您需要将服务提供程序注册到应用程序中。打开 config/app.php
并找到 providers
键。
'providers' => [ \Torann\Localization\LocalizationServiceProvider::class, ]
发布配置
在项目的根目录下从命令行运行此命令
php artisan vendor:publish --provider="Torann\Localization\LocalizationServiceProvider"
将配置文件发布到 config/localization.php
。
方法
以下方法可用
getDefaultLocale(): string
getCurrentLocale(): string
setLocale(string $locale = null): string|null
getLocales(): array
getLocale(string $key, mixed $default = null): mixed
getLocaleDirection(string $locale = 'current'): string
getLocaleKeys(): array
getLocalizedURL(string $url = null, mixed $locale = false, array $extra = []): string
isSupported(mixed $key): bool
getConfig(string $key, mixed $default = null): mixed
辅助函数
Laravel 本地化包含一些辅助方法
localization()
返回 Torann\Localization\LocaleManager
实例。
localize_url($url = null, $locale = null, $attributes = []): string
返回适应提供的区域设置的给定 URL。
确定区域设置
按子域
为了使其工作,子域需要与启用的支持的区域设置键匹配。
按主机
当确定给定的子域无效时,系统可以设置区域设置,具体取决于当前主机。您需要使用 hosts 配置选项设置应用程序的区域设置到主机的映射。
许可证
本地化是开源软件,许可协议为 BSD 2-Clause 许可证。