internetguru/laravel-translatable 问题修复 & 功能扩展

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

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

internetguru/laravel-translatable

最新稳定版本:v0.2.3

Composer 安装命令:

composer require internetguru/laravel-translatable

包简介

README 文档

README

A Laravel package for translating Eloquent model attributes.

Branch Status Code Coverage
Main tests coverage
Staging tests coverage
Dev tests coverage

Installation

  1. Install the package via Composer:

    # First time installation
    composer require internetguru/translatable
    # For updating the package
    composer update internetguru/translatable

Run Tests Locally

In Visual Studio Code you can simpy use Ctrl+Shift+B to run the tests.

To run the tests manually, you can use the following commands:

# Build the Docker image
docker build -t laravel-translatable .
# Run the tests
docker run --rm laravel-translatable
# Both steps combined
docker build -t laravel-translatable . && docker run --rm laravel-translatable

Usage

  1. Add the Translatable trait to your Eloquent model:

    use InternetGuru\Translatable\Translatable;
    
    class Room extends Model
    {
        use Translatable;
    }
  2. Define the translatable attributes in the model. Do not use $fillable for translatable attributes:

    protected $translatable = ['name'];
  3. Use translatable attributes:

    app()->setLocale('en');
    app()->setFallbackLocale('en');
    
    $room = new Room();
    $room->save();
    
    // No translation set
    echo $room->name; // null
    
    $room->name = 'Living Room';
    echo $room->name; // Living Room
    
    app()->setLocale('cs');
    $room->name = 'Obývací pokoj';
    echo $room->name; // Obývací pokoj
    
    app()->setLocale('en');
    echo $room->name; // Living Room
    
    app()->setLocale('cs');
    echo $room->name; // Obývací pokoj
    
    // Fallback to the fallback locale
    app()->setLocale('de');
    echo $room->name; // Living Room
    
    // Fallback to the first translation if fallback locale not found
    app()->setFallbackLocale('fr');
    echo $room->name; // Living Room

License & Commercial Terms

License

Copyright © 2026 Internet Guru

This software is licensed under the Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International (CC BY-NC-SA 4.0) license.

Disclaimer: This software is provided "as is", without warranty of any kind, express or implied. In no event shall the authors or copyright holders be liable for any claim, damages or other liability.

Commercial Use

The standard CC BY-NC-SA license prohibits commercial use. If you wish to use this software in a commercial environment or product, we offer flexible commercial licenses tailored to:

  • Your company size.
  • The nature of your project.
  • Your specific integration needs.

Note: In many instances (especially for startups or small-scale tools), this may result in no fees being charged at all. Please contact us to obtain written permission or a commercial agreement.

Contact for Licensing: info@internetguru.io

Professional Services

Are you looking to get the most out of this project? We are available for:

  • Custom Development: Tailoring the software to your specific requirements.
  • Integration & Support: Helping your team implement and maintain the solution.
  • Training & Workshops: Seminars and hands-on workshops for your developers.

Reach out to us at info@internetguru.io — we are more than happy to assist you!

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2024-10-28

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固