PHPackages                             dskripchenko/laravel-translatable - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Localization &amp; i18n](/categories/localization)
4. /
5. dskripchenko/laravel-translatable

ActiveLibrary[Localization &amp; i18n](/categories/localization)

dskripchenko/laravel-translatable
=================================

Dynamic Language Translation

2.0.0(3mo ago)01181MITPHP

Since May 14Pushed 3mo ago1 watchersCompare

[ Source](https://github.com/dskripchenko/laravel-translatable)[ Packagist](https://packagist.org/packages/dskripchenko/laravel-translatable)[ Docs](https://github.com/dskripchenko/laravel-translatable)[ RSS](/packages/dskripchenko-laravel-translatable/feed)WikiDiscussions main Synced today

READMEChangelogDependencies (9)Versions (17)Used By (1)

Laravel Translatable
====================

[](#laravel-translatable)

A comprehensive translation package for Laravel that combines **model translations**, **UI string localization**, and **CMS content blocks** in a single, unified solution.

Translations are stored in the database with two-level caching (in-memory + Redis/Memcached), automatic record creation, fallback locale support, and full integration with Laravel's `__()` / `trans()` helpers.

[![License: MIT](https://camo.githubusercontent.com/784362b26e4b3546254f1893e778ba64616e362bd6ac791991d2c9e880a3a64e/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f4c6963656e73652d4d49542d677265656e2e737667)](LICENSE.md)

> [README auf Deutsch](docs/README.de.md) | [README на русском](docs/README.ru.md) | [中文文档](docs/README.zh.md)

Why This Package?
-----------------

[](#why-this-package)

Most Laravel translation packages solve only one problem. If you need multilingual models, UI strings from the database, and CMS-managed content, you typically install 2-3 separate packages. This package provides all three in a unified architecture:

Capabilityspatie/translatableastrotomic/translatable**This package**Model field translationsJSON columnSeparate table per modelSingle `translations` tableUI strings (`__()` / `trans()`)--Built-in database loaderCMS content blocks--ContentBlockServiceTwo-level caching--In-memory + Cache::tagsFallback locale chain-YesYesQuery scopesJSON whereJOINwhereTranslation / orderByEvents--Created / UpdatedArtisan CLI tools--export / import / scanLanguage detection middleware--DetectLanguagePlural forms--tc() + MessageSelectorBatch operations--setTranslations / saveTranslationsLanguage management model--Full Language modelRequirements
------------

[](#requirements)

- PHP 8.1+
- Laravel 11 or 12
- Cache driver with tags support (Redis, Memcached, or Array)
- MySQL 5.7+ / PostgreSQL 12+ / SQLite 3.35+

Installation
------------

[](#installation)

```
composer require dskripchenko/laravel-translatable
```

The package uses Laravel auto-discovery. Run migrations:

```
php artisan migrate
```

Quick Start
-----------

[](#quick-start)

### 1. Create Languages

[](#1-create-languages)

```
use Dskripchenko\LaravelTranslatable\Models\Language;

Language::create(['code' => 'en', 'label' => 'English', 'is_active' => true, 'as_locale' => true]);
Language::create(['code' => 'de', 'label' => 'Deutsch', 'is_active' => true]);
Language::create(['code' => 'ru', 'label' => 'Russian', 'is_active' => true]);
```

### 2. Translate Model Fields

[](#2-translate-model-fields)

Add `TranslationTrait` to any Eloquent model:

```
use Dskripchenko\LaravelTranslatable\Traits\TranslationTrait;

class Product extends Model
{
    use TranslationTrait;

    protected $fillable = ['name', 'description', 'price'];
}
```

Read and write translations:

```
$product = Product::find(1);

// Read (uses current app locale)
$product->t('name');
$product->t('name', 'Default name');

// Read specific locale
$product->t('name', null, Language::byCode('de'));

// Write
$product->saveTranslation('name', 'Produktname', Language::byCode('de'));

// Batch write
$product->saveTranslations([
    'name' => 'Produktname',
    'description' => 'Eine Beschreibung',
], Language::byCode('de'));
```

### 3. Plural Forms

[](#3-plural-forms)

Store pluralized content using Laravel's syntax:

```
// In the database: "One item|:count items"
$product->tc('items_label', 1);                // "One item"
$product->tc('items_label', 5, ['count' => 5]); // "5 items"
```

### 4. Query by Translations

[](#4-query-by-translations)

```
// Find products by translated name
Product::whereTranslation('name', 'Laptop')->get();
Product::whereTranslation('name', 'like', '%Laptop%', 'en')->get();

// Sort by translated field
Product::orderByTranslation('name', 'asc', 'de')->get();
```

### 5. CMS Content Blocks

[](#5-cms-content-blocks)

Manage translatable content blocks tied to pages:

```
use Dskripchenko\LaravelTranslatable\Services\ContentBlockService;

$cms = new ContentBlockService();

// Simple text block (auto-linked to current page)
echo $cms->inline('hero.title', 'Hero Title', 'Welcome to our site');

// With parameter substitution
echo $cms->inline('greeting', 'Greeting', 'Hello, {name}!', ['name' => $user->name]);

// Global block (not tied to a page)
echo $cms->global('site.name', 'Site Name', 'My Application');

// HTML block via output buffering
$cms->begin('footer', 'Footer HTML');
?>
Default footer content
