承接 liaosankai/laravel-eloquent-i18n 相关项目开发

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

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

liaosankai/laravel-eloquent-i18n

最新稳定版本:v1.2.1

Composer 安装命令:

composer require liaosankai/laravel-eloquent-i18n

包简介

无描述信息

README 文档

README

Requirements

  • PHP >= 7.0.0
  • Laravel >= 5.5.0

Installation

You can install the package via composer:

composer require liaosankai/laravel-eloquent-i18n 

Making a model translatable

use Illuminate\Database\Eloquent\Model; use Liaosankai\LaravelEloquentI18n\Models\TranslationTrait; class Book extends Model { use TranslationTrait; public $i18nable = [ 'title', 'content', 'author', ]; } 

Write translations data

Set raw attribute

$book = new Book(); $book->title = 'raw title'; 

Set single attribute of single locales

$book = new Book(); $book->title = 'raw title'; $book->i18n('zh-Hant')->title = '正體中文的標題'; $book->i18n('zh-Hans')->title = '简体中文的标题'; $book->save(); 

Set multiple locales of single attribute

$book = new Book(); $book->title = 'raw title'; $book->title = [ 'zh-Hant' => '正體中文的標題', 'zh-Hans' => '简体中文的标题', 'en' => 'english title', ]; $book->save(); 

Set multiple attribute of multiple locales

$book = new Book(); $book->title = 'raw title'; $book->i18n([ 'zh-Hant' => [ 'title' => '正體中文的標題', 'content' => '正體中文的內容', ], 'zh-Hans' => [ 'title' => '简体中文的标题', 'content' => '简体中文的內容', ], 'en' => [ 'title' => 'english title', 'content' => 'english content', ], ])->save(); 

Read translations data

Arrange presence translations data:

$book = new Book(); $book->title = 'raw title'; $book->content = 'raw content'; $book->author = 'raw author'; $book->i18n([ 'zh-Hant' => [ 'title' => '正體中文的標題', 'content' => '正體中文的內容', ], 'zh-Hans' => [ 'title' => '简体中文的标题', 'content' => '简体中文的內容', ], 'en' => [ 'title' => 'english title', 'content' => 'english content', ], ])->save(); 

i18n() use all locales array if unassigned any locale

App::setLocale('zh-Hant'); $book->i18n()->title; /* [ 'zh-Hant' => '正體中文的標題', 'zh-Hans' => '简体中文的标题', 'en' => 'english title', ] */ 

i18n() use assign locale

$book->i18n('zh-Hant')->title; // 正體中文的標題 $book->i18n('zh-Hans')->title; // 简体中文的标题 $book->i18n('zh-en')->title; // english title 

i18n() use app locale if assign locale not found

App::setLocale('zh-Hant'); $book->i18n('ja')->title; // 正體中文的標題 

i18n() use raw data if assign locale attribute not found

App::setLocale('zh-Hant'); $book->i18n('zh-Hant')->author; // raw author 

Use raw data without i18n()

$book->title; // raw title $book->content; // raw content 

filter translations data

use model scope where

$book->i18nLike([ 'filter' => [ 'title' => 'keywords for title', 'content' => 'keywords for content'. ], 'locale' => 'zh-Hant', ])->get(); 

LICENSE

laravel-eloquent-i18n is released under the MIT License

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2026-01-04

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固