1. Go to this page and download the library: Download signifly/laravel-translator library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
signifly / laravel-translator example snippets
// Add the trait to your translatable models
use Signifly\Translator\Concerns\Translatable;
class Post extends Model
{
use Translatable;
/** @var array */
protected $translatable = [
'title', 'description',
];
}
$post = Post::find(1);
$post->translate('en', [
'title' => 'Some title',
'description' => 'description',
]);
// returns a Illuminate\Support\Collection of translations
return [
/*
* The active language code that is used by the package
* to return the correct language for a model.
*/
'active_language_code' => null,
/*
* By default the package will not translate model attributes automatically.
* It should be used with caution as it performs extra requests.
* Remember to eager load the translations
* in order to optimize performance.
*/
'auto_translate_attributes' => false,
/*
* The default language code that is used by the package
* to make comparisons against other languages
* in order to provide statistics.
*/
'default_language_code' => 'en',
/*
* By default the package will use the `lang` paramater
* to set the active language code.
*/
'language_parameter' => 'lang',
/*
* This determines if the translations can be soft deleted.
*/
'soft_deletes' => false,
/*
* This is the name of the table that will be created by the migration and
* used by the Translation model shipped with this package.
*/
'table_name' => 'translations',
/*
* This model will be used to store translations.
* It should be implements the Signifly\Translator\Contracts\Translation interface
* and extend Illuminate\Database\Eloquent\Model.
*/
'translation_model' => \Signifly\Translator\Models\Translation::class,
];