定制 aaix/eloquent-translatable 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

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

aaix/eloquent-translatable

最新稳定版本:v1.2.1

Composer 安装命令:

composer require aaix/eloquent-translatable

包简介

High performance translations for Laravel models.

README 文档

README

Laravel Eloquent Translatable Logo

Laravel Eloquent Translatable

High performance, developer-first translations for Laravel models.

Latest Version on Packagist Total Downloads GitHub Actions License

Eloquent Translatable is a Laravel package built for raw performance and a clean, focused developer experience. It uses direct, indexed database queries instead of relying on JSON columns or complex Eloquent model hydration, making it significantly fast and memory-efficient.

Key Features

  • ✨ Intuitive API: A clean, fluent, and predictable interface.
  • 🤝 Spatie-Compatible: Optional API compatibility with spatie/laravel-translatable.
  • 🚀 Performance-First: Designed for speed at scale. No Eloquent overhead, no JSON parsing.
  • 🔒 Secure by Default: Explicitly define which attributes are translatable.
  • ⚙️ Artisan Command: Scaffold translation migrations with a single command.
  • 🛡️ Enum-Powered: Ships with a Locale enum for type-safe, readable code.

Documentation

For the full documentation, please visit our documentation website.

Installation

You can install the package via Composer:

composer require aaix/eloquent-translatable

Quick Example

  1. Prepare your model:

    // app/Models/Product.php
    namespace App\Models;
    
    use Aaix\EloquentTranslatable\Traits\HasTranslations;
    use Illuminate\Database\Eloquent\Model;
    
    class Product extends Model
    {
        use HasTranslations;
    
        public array $translatable = ['name', 'description'];
    }
  2. Store and access translations:

    use Aaix\EloquentTranslatable\Enums\Locale;
    
    $product = Product::create(['name' => 'My awesome product']);
    
    // Store a translation
    $product->storeTranslation('name', Locale::GERMAN, 'Mein tolles Produkt');
    
    // Access it (will fall back to the app's locale)
    app()->setLocale('de');
    echo $product->name; // Output: Mein tolles Produkt
    
    // Or get a specific locale
    echo $product->getTranslation('name', Locale::GERMAN); // Output: Mein tolles Produkt

Testing

To run the package's test suite, clone the repository and run:

composer install
composer test

Contributing

Contributions are welcome!

License

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

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2025-07-21

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固