A simple trait to translate data from database through Laravel model
To display a translated static text might be easy with Laravel, yet to display a translated data from database/model would usually require a little bit of efforts and lines of code. Translatr helps to simplify the translation concept by integrating a simple trait into the Models without having to have extra tables and such., (*1)
composer require adlanarifzr/translatr
use Translatr\Translatr; class ModelName extends Model { use Translatr; }
You can translate any data in your database by adding column name with _locale
at the end of the column/attribute name. For example description_en
for English and description_my
for Malay language., (*2)
echo $model->description;
This command will display the description based on your current locale. To add more language, simply add new column with different locale., (*3)
I would be really grateful if you would contribute to support my development in Laravel packages. I can be reached at adlanarifzr@gmail.com., (*4)
The MIT License (MIT). Please see License File for more information., (*5)