Download the PHP package mosaiqo/translatable without Composer
On this page you can find all versions of the php package mosaiqo/translatable. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download mosaiqo/translatable
More information about mosaiqo/translatable
Files in mosaiqo/translatable
Package translatable
Short Description A Laravel package for easy implementation of multilingual models in mongo.
License MIT
Informations about the package translatable
Mosaiqo Translatable
This is a Laravel 5 package to have multi language models. It is prepared to use with MongoDB and Eloquent (it is planed to make it work also with MySQL).
This package was created to easily store the multi language models by embedsOne
relations.
Its a Plug & Play package, if you are using Laravel MondoDB.
Instalation
Install it via composer
Require it with composer :
or put it in your composer.json file
Add this to your config/app.php
Publish the config:
You can change the values, if you like.
Issues
We are still working on this package. It will be nice if you can get us some feedback.
If you find some errors or have an idea feel free to open a new issue .
Use it
Models
- You need to
use
theMosaiqo\Translatable\Traits\Translatable
in the models you want to have multi language ability. - You also need to create a Translation model. The convention is to use the model's name for that you want to use with translatable and append
Locale
to it (You can override it in the config file). - Optional you can specify the model to use for the translation, if not set it will search by default for a model with the current
modelname
and appendLocale
to it. - Set the attributes you want to be translatable with
protected $translatableAttributes
.
The translation model should look similar to this. It is necesary to make the attributes fillable for the MassAsignment.
Documentation
Create a Multilanguage Model
It's very esay like with a normal model, the only difference is that you pass the translatable attributes inside an array and the key is the locale value.
There is an other method, you can first create the model and than assign it the translations.
Get the translations
Assuming you have a model stored in the DDBB.
This will output the attribute in the language you use, in this particular cas es()
will return 'Mi titulo'.
And here 'My title'.
You also can assign it to a variable to use it later.
There is a more verbose mode if you like.
What if the translation doesn't exists, doesn't mather you can try with the default fallback language if the one you need is not available, just passing the second argument true
.
Or you can use the alias for it
You can also set the fallback language for this particular call if you want to display it diferent.
You can know if a Model has a translation or not. This will return wheter true/false.
You can get the hole translations instance, it will return a collection of the ArticleLocale