New

Just launched: Vueblocks, a brand-new search engine for Vue packages! Explore Vueblocks →

vortgo/laravel-translate

Translate system for laravel project
95 7

Larablocks Analysis

vortgo/laravel-translate works with Laravel 5 (latest release 1.0.0, May 27, 2017), which reached end of life: no more fixes, even for security.

Recommendation checks

Not advised

Not advised: no release or commit in over 2 years.

  • No release or commit in over 2 years
  • Supports only Laravel 5, past end of life
  • No release in the last 12 months (last: May 27, 2017)
  • 0 downloads a month (needs 10,000)
  • 7 GitHub stars (needs 100)

State

Likely abandoned
  • No release or commit in over 2 years.
  • Last stable release: May 27, 2017.
  • No releases in the last 12 months.
  • First released: May 27, 2017.
  • 0 open issues on GitHub.

Data from Packagist and GitHub, checked by Larablocks on Dec 3, 2026.

Install
composer require vortgo/laravel-translate
Latest Version:1.0.0
PHP:>=5.5.0
Laravel:5
License:MIT
Last Updated:May 27, 2017
Links: GitHub  ·  Packagist
Maintainer: vortgo

SensioLabsInsight

Translate entity

About package

This package is intended for adding multi language support to your models. If your application already be working and you need to add one or more aditional languages to your content in database it's be easy.

Installation

Require this package in your composer.json

$ composer reqiure vortgo/laravel-translate

Add the service provider to you config file config/app.php

Vortgo\Translate\ModelTranslateServiceProvider::class

Publish vendor

    $ php artisan vendor:publish

Run migration to create table for your translatable content

$ php artisan migrate

Add trait to your model which need to translate and setup your default language for your model

    class Category extends Model
    {
        use Translate;
        protected $defaultLocale = 'en';
    }

Usage

You can create entity with translate as usually:

        Category::create([
            'name' => 'name',
            'ru' => [
                'name' => 'название'
            ],
            'fr' => [
                'name' => 'fr name'
            ]
        ]);

For access the translate value you can use next variant:

Determine when calling

    $category->translate('fr')->name

Use your app locale

    App()->setLocale('fr')
    $category->name

Get all translations attributes for current model

$category->getTranslations('fr')

Bonuses

You can use relations for eager loader your model

    App()->setLocale('fr');
    $item = Item::with('category', 'category.rTranslate')->first();
    $item->category->name;

To array with relation

    App()->setLocale('fr');
    $item = Item::with('category', 'category.rTranslate')->first();
    $item->toArray();
    Result = [
        'id' =>1,
        'item_name' => 'name',
        'category' => [
            'name' => 'fr name'
        ]
    ];

If you want to override function toArray() use translateToArray() in your model

    public function toArray()
    {
        $array = $this->translateToArray(); //parent::toArray()

        // Your code here

        return $array;
    }

Related Packages

doctrine/dbal

Powerful PHP database abstraction layer (DBAL) with many features for database s...

670,032,257 9,703
laravel/framework

The Laravel Framework.

640,572,096 35,338
laravel/tinker

Powerful REPL for the Laravel framework.

546,909,908 7,440
laravel/serializable-closure

Laravel Serializable Closure provides an easy and secure way to serialize closur...

465,816,364 607
nunomaduro/collision

Cli error handling for console/command-line PHP applications.

431,187,642 4,660

Version History

Version Released PHP Laravel License
1.0.0 >=5.5.0 >=5.1 MIT