richan-fongdasen / laravel-i18n
Laravel中简单的路由和优雅的本地化/翻译
3.3.0
2024-03-13 04:04 UTC
Requires
- php: ^8.0
- illuminate/database: ^8.0|^9.0|^10.0|^11.0
- illuminate/support: ^8.0|^9.0|^10.0|^11.0
- nesbot/carbon: ^2.16|^3.0
Requires (Dev)
- ekino/phpstan-banned-code: ^1.0
- fakerphp/faker: ^1.9
- larastan/larastan: ^1.0|^2.0
- mockery/mockery: ^1.4
- orchestra/testbench: ^6.0|^7.0|^8.0|9.x-dev
- phpmd/phpmd: ^2.11
- phpstan/phpstan-deprecation-rules: ^1.0
- phpstan/phpstan-strict-rules: ^1.0
- phpunit/phpunit: ^9.5|^10.0|^11.0
README
Laravel I18n
Laravel中的简单路由本地化和Eloquent翻译
概述
此包提供了方便的设置数据库翻译和路由本地化的方法。
目录
设置
通过Composer安装包
$ composer require richan-fongdasen/laravel-i18n
发布包资源
使用此php artisan
命令发布包资源文件
$ php artisan vendor:publish --provider="RichanFongdasen\I18n\ServiceProvider"
上述命令将在您的应用程序中创建三个新文件,例如
- 新的配置文件
/config/i18n.php
- 新的数据库迁移文件
/database/migrations/0000_00_00_000000_create_languages_table.php
- 新的语言JSON文件
/storage/i18n/languages.json
配置
return [ /* |-------------------------------------------------------------------------- | Language repository driver |-------------------------------------------------------------------------- | | Define your language repository driver here. The available options are: | database and json. | */ 'driver' => 'json', /* |-------------------------------------------------------------------------- | Language repository datasource |-------------------------------------------------------------------------- | | Define your language repository datasource here. | - Define your database table name, when you're using database driver. | - Define your json file path, when you're using json driver. | */ 'language_datasource' => storage_path('i18n/languages.json'), // 'language_datasource' => 'languages', /* |-------------------------------------------------------------------------- | Cache duration |-------------------------------------------------------------------------- | | Define how long we should cache the language dataset in seconds. | */ 'cache_duration' => 60 * 60 * 24, /* |-------------------------------------------------------------------------- | Language key |-------------------------------------------------------------------------- | | Define which language key in datasource that we should use. | Available options are: | - language, ie: en, es, de, etc. | - ietfCode, ie: en-US, en-UK, de-DE, etc. | */ 'language_key' => 'language', /* |-------------------------------------------------------------------------- | API query key |-------------------------------------------------------------------------- | | Define the query parameter name which will be used as language selector | in every API request. | e.g: http://localhost:8000/api/articles?lang=en | */ 'api_query_key' => 'lang', /* |-------------------------------------------------------------------------- | Language negotiator class |-------------------------------------------------------------------------- | | Define your language negotiator class here. | The class should implement LanguageNegotiator contract / interface. | */ 'negotiator' => \RichanFongdasen\I18n\Negotiators\BrowserNegotiator::class, /* |-------------------------------------------------------------------------- | Locale URL segment number |-------------------------------------------------------------------------- | | Define which url segment number that will be used to put the current | locale information. URL segment is started with '1'. | e.g: http://my-application.app/en/home | */ 'locale_url_segment' => 1, /* |-------------------------------------------------------------------------- | Translation table suffix |-------------------------------------------------------------------------- | | Define your preferred suffix to be appended to your database's | translation table name. | */ 'translation_table_suffix' => 'translations', /* |-------------------------------------------------------------------------- | Enable Store to the cache |-------------------------------------------------------------------------- | | Toggle store locale to the cache | */ 'enable_cache' => env('I18N_ENABLE_CACHE', true), ];
文档
请在此处查看文档https://laravel-i18n.richan.id/
鸣谢
- mcamara/laravel-localization - 此存储库中的路由本地化概念受到此包的启发。
- Wico Chandra - 此存储库中的数据库翻译概念受到他的
Model Translation
概念的启发。 - dimsav/laravel-translatable - 此存储库中的一些数据库翻译概念受到此包的启发。
许可
MIT许可(MIT)。有关更多信息,请参阅许可文件。