maplesnow / laravel-yaml-translation
Provide YAML file support to Laravel language translation
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: 2025-03-22 07:35:39 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"
Validation
将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']));
License
laravel-yaml-translation is free software distributed under the terms of the MIT license.