maplesnow / laravel-yaml-translation
为 Laravel 语言翻译提供 YAML 文件支持
v1.0.6
2022-07-22 01:57 UTC
Requires
- php: >=7.0.0
- illuminate/http: 5.5.*|5.6.*|5.7.*
- illuminate/support: 5.5.*|5.6.*|5.7.*
- illuminate/translation: 5.5.*|5.6.*|5.7.*
- symfony/yaml: 3.*
Requires (Dev)
- laravel/framework: ^5.5
This package is auto-updated.
Last update: 2024-09-22 06:32:52 UTC
README
提供yaml文件统一管理laravel语言包,兼容laravel的validation翻译。
安装
composer require maplesnow/laravel-yaml-translation
添加laravel支持
将 app/config/app.php 中的 Illuminate\Translation\TranslationServiceProvider
替换成 MapleSnow\Yaml\TranslationServiceProvider
发布yml文件到项目中
php artisan vendor:publish --provider="MapleSnow\Yaml\TranslationServiceProvider"
验证
将request
文件继承MapleSnow\Yaml\Request\BaseRequest.php
如果需要翻译指定模块的属性
# 添加自定义属性 attribute: module: name: '模块名称'
在Request
文件中rules
指定模块
class ModuleRequest extends BaseRequest { /** * Determine if the user is authorized to make this request. * * @return bool */ public function authorize() { return true; } /** * Get the validation rules that apply to the request. * * @return array */ public function rules() { # 指定模块 $this->setModule("module"); return [ 'name' => 'required' ]; } }
用法示例
dump(trans("lang.message.hello",['name','laravel-yaml']));
许可证
laravel-yaml-translation 是在MIT许可证条款下免费分发的软件。MIT license.