barisdemirhan/laravel-polyglot-model 问题修复 & 功能扩展

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

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

barisdemirhan/laravel-polyglot-model

Composer 安装命令:

composer require barisdemirhan/laravel-polyglot-model

包简介

Elegant model translations for Laravel with polymorphic storage and eager loading support

README 文档

README

Laravel Polyglot Model

Latest Version on Packagist GitHub Tests Action Status Total Downloads License

Elegant model translations for Laravel with polymorphic storage and eager loading support.

Documentation · Report Bug · Request Feature

✨ Features

  • 🚀 Simple API - Intuitive trait-based approach
  • 🔄 Polymorphic Storage - Single translations table for all models
  • Eager Loading - Optimized for performance with relationship loading
  • 🎯 Magic Getters - Access translations like regular attributes
  • 🔍 Query Scopes - Search across translated fields
  • 💾 Caching - Built-in cache support for better performance
  • 🎭 Events - Hooks for translation create/update/delete

📋 Requirements

  • PHP 8.1+
  • Laravel 10.x, 11.x, or 12.x

📦 Installation

composer require barisdemirhan/laravel-polyglot-model

Publish and run migrations:

php artisan vendor:publish --tag="polyglot-model-migrations"
php artisan migrate

Optionally publish the config file:

php artisan vendor:publish --tag="polyglot-model-config"

🚀 Quick Start

1. Add the trait to your model

<?php

namespace App\Models;

use PolyglotModel\Contracts\TranslatableContract;
use PolyglotModel\Traits\HasTranslations;
use Illuminate\Database\Eloquent\Model;

class Post extends Model implements TranslatableContract
{
    use HasTranslations;

    protected array $translatableFields = [
        'title',
        'slug',
        'content',
    ];
}

2. Set and get translations

// Create a post
$post = Post::create([
    'title' => 'Hello World',
    'slug' => 'hello-world',
]);

// Set translations
$post->setTranslate('title', 'tr', 'Merhaba Dünya');
$post->setTranslate('title', 'de', 'Hallo Welt');

// Get translations
$post->getTranslate('title', 'tr'); // "Merhaba Dünya"

// Magic getter (uses current locale)
App::setLocale('tr');
$post->title; // "Merhaba Dünya"

3. Query translations

// Search in translated field
Post::searchTranslatable('title', 'Merhaba', 'tr')->get();

// Get posts with complete translations
Post::hasAllRequiredFieldsForLocaleScope('tr')->get();

🛠️ Available Methods

Method Description
setTranslate($field, $locale, $value) Set translation
getTranslate($field, $locale) Get translation
hasTranslation($field, $locale) Check if exists
getAllTranslations() Get all as array
setPreferredLanguage($locale) Set preferred language

⚙️ Configuration

// config/polyglot-model.php
return [
    'source_locale' => 'en',
    'fallback_locale' => 'en',
    'supported_locales' => ['en', 'tr', 'de', 'es', 'fr'],
    'cache' => [
        'enabled' => true,
        'ttl' => 3600,
    ],
];

🔧 Artisan Commands

php artisan polyglot:stats
php artisan polyglot:clean-orphaned

🧪 Testing

composer test

📄 License

MIT License. See License File for more information.

Made with ❤️ by Barış Demirhan

barisdemirhan/laravel-polyglot-model 适用场景与选型建议

barisdemirhan/laravel-polyglot-model 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 33 次下载、GitHub Stars 达 0, 最近一次更新时间为 2026 年 01 月 20 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「i18n」 「translations」 「trait」 「laravel」 「localization」 「polyglot」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

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

围绕 barisdemirhan/laravel-polyglot-model 我们能提供哪些服务?
定制开发 / 二次开发

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

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

GitHub 信息

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

其他信息

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