PHP code example of sertxudeveloper / laravel-translatable

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

    

sertxudeveloper / laravel-translatable example snippets


'locales' => ['es', 'en', 'it'],

'fallback_locale' => 'es',

"hide_fallback_locale" => true,

// Not Localized
Route::get('home', [HomeController::class, 'index'])->name('home');

// Localized
Route::localized(function () {
  Route::get('blog', [BlogController::class, 'index'])->name('blog')
  Route::get('{slug}', [PageController::class, 'index'])->name('page')
});

// Not Localized
Route::get('about', [AboutController::class, 'index'])->name('about');

trans_route($name, $parameters = [], $absolute = false, $locale = null)

trans_route('blog') // /en/blog

trans_route('page', ['help']) // /en/help

trans_route('page', ['help'], true) // https://yourdomain.test/en/help

trans_route('page', ['help'], false) // /en/help

trans_route('blog', [], false, 'it') // /it/blog

switch_to_locale('en') // Changes to 'en' locale without changing the route

'table_suffix' => '_translations'

$post = Post::find(1);
echo $post->getTranslated('name');
sh
php artisan vendor:publish --tag='trans-config'
sh
php artisan route:cache