thejano / laravel-multi-lang
Polymorphic translation support for Laravel models with caching, helpers, and facade.
Installs: 3
Dependents: 0
Suggesters: 0
Security: 0
Stars: 1
Watchers: 0
Forks: 0
Open Issues: 0
pkg:composer/thejano/laravel-multi-lang
Requires
- php: >=8.1
- illuminate/database: ^10.0|^11.0|^12.0
- illuminate/support: ^10.0|^11.0|^12.0
Requires (Dev)
- guzzlehttp/guzzle: ^7.5
- laravel/pint: ^1.20.0|^1.25.0
- orchestra/testbench: ^8.0|^9.0|^10.0
- pestphp/pest: ^2.34
- pestphp/pest-plugin-laravel: ^2.4
README
Polymorphic translations for Laravel models with a batteries-included developer experience—helper functions, eager-loading scopes, caching, CLI tooling, pluralisation helpers, import/export pipelines, and more.
Documentation
Visit docs for the complete guide—including Overview, Core Concepts, Querying Translations, Automation & CLI, Extensibility, Middleware, and Testing.
https://multi-lang.thejano.com
Requirements
- PHP 8.1 or higher
- Laravel 10.x, 11.x, or 12.x
- Database with JSON or text column support (MySQL, PostgreSQL, SQLite, etc.)
Why you’ll love it
- Laravel-native ergonomics – fluent query scopes, helpers, Blade directives, and facades.
- Performance ready – eager loading, translation caching (including Redis-backed stores), and grouped predicates.
- Robust workflows – soft deletes with automatic restoration, batch setters, JSON import/export, audit command, pluralisation helpers.
Install
composer require thejano/laravel-multi-lang php artisan vendor:publish --tag=multi-lang-config php artisan vendor:publish --tag=multi-lang-migrations php artisan migrate
Five-minute setup
use Illuminate\Database\Eloquent\Model; use TheJano\MultiLang\Traits\Translatable; class Post extends Model { use Translatable; protected $fillable = ['title', 'content']; protected array $translatableFields = ['title', 'content']; }
$post = Post::create(['title' => 'Original Title']); $post->setTranslation('title', 'ناونیشان', 'ckb'); $post->translate('title', 'ckb'); // ناونیشان $post->translateOrOriginal('title', 'fr'); // Falls back to original value trans_model_choice($post, 'visits', 5, ['count' => 5]);
Query like native Laravel:
Post::whereTranslate('title', 'ناونیشان', 'ckb')->get(); Post::whereTranslateWithFallback('title', 'عنوان', 'ckb', 'ar')->get(); Post::withTranslations(['ckb', 'ar'])->get();
CLI & automation
php artisan multi-lang:audit– surface missing translations.php artisan multi-lang:export– JSON export (use--missing,--ids,--locales).php artisan multi-lang:import– merge/replace import with--only-missingsupport.
Pair exports/imports with your favourite translation service or CI workflow.
Caching tips
Translations cache per model and can share stores:
'cache_store' => [ 'driver' => 'redis', // null uses default cache store 'prefix' => 'multi_lang:translations', 'ttl' => 3600, ],
Reset across tests/jobs with Post::resetTranslationCacheStore();.
Testing & contributing
- Run the Pest suite:
composer test - Issues or pull requests welcome—add tests and a short summary when contributing.
- Security reports: pshtiwan@janocode.com
License
Laravel Multi-Lang is open-source software licensed under the MIT license.