PHP code example of skachinsky / locale-translator

1. Go to this page and download the library: Download skachinsky/locale-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/ */

    

skachinsky / locale-translator example snippets


use Skachinsky\LocaleTranslator\Models\Translate;

$petType = PetType::find(1);
Translate::create([
    "type"=>$petType->getModelName(),
    "row_id"=>$petType->id,
    "locale"=>"en",
    "value"=>"dog"
]);
Translate::create([
    "type"=>$petType->getModelName(),
    "row_id"=>$petType->id,
    "locale"=>"ru",
    "value"=>"собака"
]);
//и т.д. для каждой строки pet_types

namespace App\Models;

use Skachinsky\LocaleTranslator\LocaleTranslator;

class PetType extends Model
{
    use LocaleTranslator;
    
    /*...*/
    
    public function getTitleAttribute() {
       return $this->translateAttribute($this->slug);
    }
}
sh
php artisan vendor:publish --provider="Skachinsky\LocaleTranslator\LocaleTranslatorServiceProvider"
sh
php artisan migrate