PHPackages                             jvdlaar/laravel-content-translation - 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. jvdlaar/laravel-content-translation

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

jvdlaar/laravel-content-translation
===================================

A Laravel 5 package to translate properties of a model.

v1.0.0-alpha1(9y ago)06MITPHPPHP ^7.0

Since Apr 7Pushed 9y agoCompare

[ Source](https://github.com/jvdlaar/laravel-content-translation)[ Packagist](https://packagist.org/packages/jvdlaar/laravel-content-translation)[ Docs](https://github.com/jvdlaar/laravel-content-translation)[ RSS](/packages/jvdlaar-laravel-content-translation/feed)WikiDiscussions master Synced 2mo ago

READMEChangelog (1)Dependencies (3)Versions (2)Used By (0)

[![Latest Version](https://camo.githubusercontent.com/89316f67af27c22b926474efd8d61e0b2a9c4f0be75ba242c2b9f81362eebc2b/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f72656c656173652f6a76646c6161722f6c61726176656c2d636f6e74656e742d7472616e736c6174696f6e2e7376673f7374796c653d666c61742d737175617265)](https://github.com/jvdlaar/laravel-content-translation/releases)[![Software License](https://camo.githubusercontent.com/55c0218c8f8009f06ad4ddae837ddd05301481fcf0dff8e0ed9dadda8780713e/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d627269676874677265656e2e7376673f7374796c653d666c61742d737175617265)](LICENSE.md)[![Total Downloads](https://camo.githubusercontent.com/5d058ef4d8ad1d60c71e4fa523aba61515082b4f8b53f56286ff4cd93a684774/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f6a76646c6161722f6c61726176656c2d636f6e74656e742d7472616e736c6174696f6e2e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/jvdlaar/laravel-content-translation)

Laravel content translation
===========================

[](#laravel-content-translation)

This package makes properties of your models translatable. For example when you have a Country model then you can make the country name translatable.

Todo
----

[](#todo)

- Add user interface to add translations.
- Add tests
- Method to disable the "static translations".

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

[](#installation)

This package can be installed through Composer.

```
composer require jvdlaar/laravel-content-translation
```

You must install this service provider.

```
// config/app.php
'providers' => [
    ...
    JvdLaar\ContentTranslation\ContentTranslationServiceProvider::class,
    ...
];
```

This package also comes with a facade, which provides an easy way to call the the class.

```
// config/app.php
'aliases' => [
    ...
    'ContentTranslation' => JvdLaar\ContentTranslation\ContentTranslationFacade::class,
    ...
];
```

You can publish the config file of this package with this command:

```
php artisan vendor:publish --provider="JvdLaar\ContentTranslation\ContentTranslationServiceProvider"
```

The following config file will be published in `config/content-translation.php`

```
return [
  'fallback_language' => 'en',

  'country' => [
    'class' => \App\Models\Country::class,
    'label_property' => 'name',
    'properties' => [
      'name' => ['required' => TRUE],
      'nationality' => ['required' => TRUE],
    ],
  ],

  'page' => [
    'class' => \App\Models\Test::class,
    'label_property' => 'title',
    'properties' => [
      'title' => ['required' => TRUE],
      'body' => ['nl2br' => TRUE],
    ],
  ],
];
```

The array key is they key with which the translations are stored in the database, "class" refers to the model class. "label\_property" is used to determine the translatable label of this model. E.g. the country name in the country model. "properties" is an array with the translatable properties and whether they are required and their output needs to be nl2br.

Usage
-----

[](#usage)

After installation and configuration you need to make models translatable by implementing the TranslatableContract. The HasTranslatables trait helps with this.

### Example model

[](#example-model)

```
namespace App\Models;

use App\Base\Model;
use App\Contracts\TranslatableContract;
use App\Models\Traits\HasTranslatables;

class Country extends Model implements TranslatableContract {

  use HasTranslatables;

  protected $table = 'countries';
  protected $fillable = ['code', 'admin_name'];
  public $timestamps = FALSE;
  public $users = FALSE;

  /**
   * ATTRIBUTES
   */

  /**
   * Getter for 'name'.
   */
  public function getNameAttribute() {
    return $this->displayTranslation('name', TRUE);
  }

  /**
   * Getter for 'nationality'.
   */
  public function getNationalityAttribute() {
    return $this->displayTranslation('nationality', TRUE);
  }

  /**
   * Return an default for a property in this content.
   */
  protected function getTranslationDefault($property) {
    return $this->admin_name;
  }

}
```

In above example $country-&gt;name and $country-&gt;nationality are translated. When there is no translation in the database the admin\_name property is used as fallback. The 2nd parameter of the function displayTranslation says that there is a default that should be used. The 3rd parameter is the locale of the translation, by default the current app locale will be used. 4th parameter determines that a fallback language should be used, this fallback language is set in the config.

### Eager load translations for multiple models.

[](#eager-load-translations-for-multiple-models)

```
Country::eagerLoadTranslations([1, 2, 3], 'nl');
dump(Country::find(1)->name);
```

In above example 3 countries are eager loaded. So loading the model later and requesting a translation doesn't need an additional query.

### Saving translations

[](#saving-translations)

You can add a translation to the database by using the facade:

```
\ContentTranslation::saveTranslation('country', $country->id, 'name', 'nl', 'Nederland');
```

Or by using a method on the model:

```
$country->saveTranslation('nl', ['name' => 'Nederland', 'nationality' => 'Nederlander']);
```

Security
--------

[](#security)

If you discover any security related issues, please email  instead of using the issue tracker.

About ezCompany
---------------

[](#about-ezcompany)

ezCompany is a webdevelopment agency in the Netherlands located in Tilburg, Breda and Utrecht. For more information see [our website](https://ezcompany.nl).

License
-------

[](#license)

The MIT License (MIT). Please see [License File](LICENSE.md) for more information.

###  Health Score

20

—

LowBetter than 14% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity4

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity44

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Unknown

Total

1

Last Release

3323d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/4dd4c0ce14bac47c7289375ed5f9ff3a5b1467ceea4de4bc3d3bb9cca8ff9f6f?d=identicon)[jvdlaar](/maintainers/jvdlaar)

---

Top Contributors

[![jvdlaar](https://avatars.githubusercontent.com/u/1094732?v=4)](https://github.com/jvdlaar "jvdlaar (2 commits)")

---

Tags

laravellaravel-5-packagemodel-translationstranslationlaraveltranslationmodelezcompany

### Embed Badge

![Health badge](/badges/jvdlaar-laravel-content-translation/health.svg)

```
[![Health](https://phpackages.com/badges/jvdlaar-laravel-content-translation/health.svg)](https://phpackages.com/packages/jvdlaar-laravel-content-translation)
```

###  Alternatives

[kkomelin/laravel-translatable-string-exporter

Translatable String Exporter for Laravel

3291.4M10](/packages/kkomelin-laravel-translatable-string-exporter)[opgginc/codezero-laravel-localized-routes

A convenient way to set up, manage and use localized routes in a Laravel app.

2770.1k1](/packages/opgginc-codezero-laravel-localized-routes)[longman/laravel-multilang

Package to integrate multi language (multi locale) functionality in Laravel 5.x

5514.4k1](/packages/longman-laravel-multilang)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
