mammut-alex/polyglot

在 Laravel 中翻译模型列

0.2.0 2017-03-14 09:57 UTC

This package is auto-updated.

Last update: 2024-09-25 06:16:21 UTC


README

Build Status Total Downloads Latest Stable Version License Code Climate StyleCI

安装

在您的 composer.json 中添加此包,并更新 composer。

"mammut-alex/polyglot": "0.2.*"

或者 composer require mammut-alex/polyglot

文档

翻译器与数据库协同工作,查找代码语言前缀

以下是一个迁移示例

    $table->string('name_en');
    $table->string('name_uk');
    $table->string('name_ru');

要使用 polyglot,将其连接到您的模型并使用翻译功能。

namespace App;

use Illuminate\Database\Eloquent\Model;
use MammutAlex\Polyglot\Polyglot;

class YouModel extends Model
{
	use Polyglot;
	
	public function name()
    	{
    		return $this->translation('name');
    	}
    ...

该函数将返回所选语言用户的翻译

Blade 中的使用示例

<h1>{{$model->name()}}</h1>

更多信息请参阅测试和正在开发的文档