maplesnow / laravel-yaml-translation
Provide YAML file support to Laravel language translation
Installs: 361
Dependents: 1
Suggesters: 0
Security: 0
Stars: 0
Watchers: 1
Forks: 0
Open Issues: 0
pkg:composer/maplesnow/laravel-yaml-translation
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-09-22 08:49:13 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.