maplesnow/laravel-yaml-translation

Provide YAML file support to Laravel language translation

v1.0.6 2022-07-22 01:57 UTC

This package is auto-updated.

Last update: 2024-04-22 05:42:27 UTC


README

提供yaml文件统一管理laravel语言包,兼容laravel的validation翻译。

安装

composer require maplesnow/laravel-yaml-translation

添加laravel支持

app/config/app.phpIlluminate\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.