Skip to content

A simple trait to translate data from database through Laravel model

License

Notifications You must be signed in to change notification settings

adlanarifzr/translatr

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

14 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Table of Contents

Introduction

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.

Installation

  1. Install the package through composer
composer require adlanarifzr/translatr
  1. Use the Translatr in your Model
use Translatr\Translatr;

class ModelName extends Model
{
    use Translatr;
}

Usage

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.

Support & Thanks

I would be really grateful if you would contribute to support my development in Laravel packages. I can be reached at [email protected].

License

The MIT License (MIT). Please see License File for more information.

About

A simple trait to translate data from database through Laravel model

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages