承接 corecave/laratrans 相关项目开发

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

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

corecave/laratrans

Composer 安装命令:

composer require corecave/laratrans

包简介

Laravel helper package for building database mutli-lang websites.

README 文档

README

GitHub issues GitHub forks GitHub stars GitHub license

Laravel translation package for building database localized mutli-lang websites..

Contents

Installation

You can install the package via composer:

composer require corecave/laratrans

Laravel auto-discovery with discover the service provicer
OR
Add the service provider manually:

// config/app.php
'providers' => [
    // ...
    CoreCave\Laratrans\LaratransServiceProvider::class,
],

Append CoreCave\Laratrans\Middleware\Locale to the $routeMiddleware array in app\Http\Kernel.php file.

// app\Http\Kernel.php
  protected $routeMiddleware = [
        // ...

        'laratrans' => \CoreCave\Laratrans\Middleware\Locale::class,
    ];

Put your database credentials to your .env file

Then you should migrate the database

php artisan migrate

Usage

After you have installed laratrans package you need to add the MasterTranslatable and DetailsTranslatable traits to your models that you want to make localizable. Additionaly,
NOTE:- Please note that slave model must be proceeded with underscore _ and its related table must be proceeded by double underscore __ (e.g. Person => _Person , people => __people)
Then, define the fields required by the package for localization to work properly on your migration:

//app\Person.php

<?php

namespace App;

use CoreCave\Laratrans\Translation\MasterTranslatable;
use Illuminate\Database\Eloquent\Model;

class Person extends Model
{
    use MasterTranslatable;
}
//app\_Person.php

<?php

namespace App;

use CoreCave\Laratrans\Translation\DetailsTranslatable;
use Illuminate\Database\Eloquent\Model;

class _Person extends Model
{
    use DetailsTranslatable;
}

If you need to specify a different foreign key name for your model, just override getForeignKeyName on MasterTranslatable trait.

//database\migrations\2020_07_06_185838_create_people_table.php

<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

class CreatePeopleTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('people', function (Blueprint $table) {
            $table->id();
            $table->integer('age');
            $table->float('hight');
            $table->float('weight');
            $table->timestamps();
        });

        Schema::create('__people', function (Blueprint $table) {
            $table->id();
            $table->string('name');
            $table->mediumText('bio');
            $table->integer('person_id');
            $table->integer('locale_id');
            $table->timestamps();
        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::dropIfExists('people');
        Schema::dropIfExists('__people');
    }
}

Then, setup some models, migrations, factories and seeders for locales, people and __people tables or just you can publish them for faster development:

php artisan vendor:publish --tag="laratrans"

If you want to see localization in action, just setup some dummy routes in your routes/web.php)file.

// routes/web.php

use App\Person;
use Illuminate\Support\Facades\Route;

Route::get('/', function () {
    return Person::first()->trans();
});

Route::get('/ar', function () {
    return Person::first()->trans('ar');
});

Route::middleware('laratrans:web')->get('/trans', function () {
    return Person::first()->trans();
});

Change Application Locale.

To change your application localication code. Issue a GET request to http://yourdomain.com/localize/web/en.

This route is constructed as http://yourdomain.com/localize/{guard}/{locale-code}

Consider a donation

Become a patreon and encourage us to do more. [Become a patreon]

Credits

License

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

corecave/laratrans 适用场景与选型建议

corecave/laratrans 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 6 次下载、GitHub Stars 达 1, 最近一次更新时间为 2020 年 07 月 06 日, 在 PHP 生态内属于活跃度较高的组件。

我们在过去多个企业项目中使用过 corecave/laratrans 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 corecave/laratrans 我们能提供哪些服务?
定制开发 / 二次开发

基于 corecave/laratrans 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2020-07-06