hostitonline/laravel-translator 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

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

hostitonline/laravel-translator

最新稳定版本:v1.0.5

Composer 安装命令:

composer require hostitonline/laravel-translator

包简介

Translate models directly

README 文档

README

Installation, Configuration and Usage

To install run composer require hostitonline/laravel-translator

What does this package do?

This package will allow seamless translation integration with your laravel project. Most packages require you to define a relationship on your model and then call the relationship to display your translation. This package will remove this requirement to keep your code clean!

How to use it?

Model:

<?php

namespace App\Models;

use HostitOnline\LaravelTranslator\Traits\Translatable;

class Product extends Model
{
    use Translatable;

    /** @var array|string[]  */
    public array $translatable = [
        'name'
    ];

    protected $fillable = [
        'name'
    ];
}

How to create a new translation

$product = Product::create([
    'name' => 'Book'
]);

\HostitOnline\LaravelTranslator\Models\Translations::create([
    'value' => 'Boek',
    'translatable_id' => $product->id,
    'translatable_type' => Product::class,
    'iso_code' => 'nl',
    'translatable_column' => 'name'
]);

\HostitOnline\LaravelTranslator\Models\Translations::create([
    'value' => 'Livre',
    'translatable_id' => $product->id,
    'translatable_type' => Product::class,
    'iso_code' => 'fr',
    'translatable_column' => 'name'
]);

This package uses the app()->getLocale() to get the ISO code. This is usually handled in the middleware to ensure the correct language will be used.

GET /products/<id> HEADERS: [Content-Language => FR]

ProductController {

    public function show(Product $product)
    {
        dump($product->name); // Output: Livre
    }
}

License

Laravel-translator is open-sourced software licensed under the MIT license.

Contributing

Please report any issue you find in the issues page. Pull requests are more than welcome.

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2024-05-07