承接 dnj/laravel-localization 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

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

dnj/laravel-localization

最新稳定版本:v1.0.1

Composer 安装命令:

composer require dnj/laravel-localization

包简介

README 文档

README

Latest Version on Packagist Total Downloads Software License

This package helps you to manage and present your multi-language Eloquent models easier.

There is core concept: You have a record (like Product) and each record has some localized attribute (like title or descriptions). So you create a Eloquent model for your main entity:

<?php
namespace App\Models;

use dnj\Localization\Contracts\ITranslatableModel;
use dnj\Localization\Eloquent\HasTranslate;

class Product extends Model implements ITranslatableModel
{
	use HasTranslate;

	protected $table = "product";
}

And then create another model for its translates:

<?php
namespace App\Models;

use dnj\Localization\Contracts\ITranslateModel;
use dnj\Localization\Eloquent\IsTranslate;

class ProductTranslate extends Model implements ITranslateModel
{
	use IsTranslate;

	protected $table = "product_translate";
}

ITranslatableModel

This interface prodvide two methods for you which you can retrive translates for a model:

Method Description
getTranslate(string $locale): ?ITranslateModel Get translation for this model for $locale, if it's present.
getTranslates(): iterable Get all translates for this model.

To facilitate things there is a HasTranslate trait that taking care of implementing those methods. On top of that, this trait has some extra methods:

Method Description
getTranslateForUpdate(string $locale): ITranslateModel Get & lock the translation for update. If it's not exist an exception will throw
addTranslate(string $locale, array $fields): ITranslateModel Insert new translation for this object in $locale language.
deleteTranslate(string $locale): void Permanently destroy a translate for this object in $locale language.
updateTranslate(string $locale, array $fields): ITranslateModel Update the translation in $locale language for this object.
updateTranslate(array<string,array<string,string>> $changes): static Insert&Update&Delete translations based on input.

ITranslateModel

This model is much simpler. Just contains some getters.

Method Description
getLocale(): string Getter for the translation locale value.
getField(string $key): string Getter for the field with $key key. If $key does not exists an exception will throw
getFields(): array<string,string> All fields as an associative array.

And also there is IsTranslate trait which implements these methods for you.

Security

If you've found a bug regarding security please mail security@dnj.co.ir instead of using the issue tracker.

License

The MIT License (MIT). Please see License File for more information.

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2023-10-14