定制 jbernavaprah/lighthouse-translation 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

jbernavaprah/lighthouse-translation

Composer 安装命令:

composer require jbernavaprah/lighthouse-translation

包简介

Translation support for Laravel Lighthouse

README 文档

README

Software License GitHub Tests Action Status Coverage Status PHPStan Latest Version on Packagist Total Downloads

Is not PRODUCTION READY.

Requirements

Installation

1. Install using composer:

composer require jBernavaPrah/lighthouse-translation

2. UseTranslation

Apply the JBernavaPrah\Translation\UseTranslation trait to your models.

use JBernavaPrah\UseTranslation ;
use Illuminate\Database\Eloquent\Model;

/**
 * @property \JBernavaPrah\LighthouseTranslation\Translate $name
 * 
 */
class Item extends Model 
{
    use UseTranslation;
    
    public function translationColumns(): array{
        return ["name"]
    }
    
    
}

3. Declare field type as Translate on GraphQL schema

type Item {

    name: Translate!

    # ...

}

Usage

Enable Translation

The directive localize accepts as a parameter the lang to use to return the localized data.

If is not founded on the column, null is returned.

query {
    item(id: 1) @localize(lang: "en") {
        name {
            ...on Localized{
                lang
                text
            }
        }
    }
}

In case the directive is not used on that query/mutation, the RawTranslation type is returned.

query {
    item(id: 1) {
        name {
            ... on RawTranslation {
                data {
                    lang
                    text
                }
            }
        }
    }
}

Credits:

A lot of ideas came thanks to daniel-de-wit/lighthouse-sanctum. Big thanks to him and his beautiful code!
Also the authors of nuwave/lighthouse did a great job on the documentation and code.

统计信息

  • 总下载量: 252
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 1
  • 点击次数: 0
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 1
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2022-05-25