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.
- Install the package through composer
composer require adlanarifzr/translatr
- Use the Translatr in your Model
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.
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.
I would be really grateful if you would contribute to support my development in Laravel packages. I can be reached at [email protected].
The MIT License (MIT). Please see License File for more information.