PHP code example of arm092 / laravel-translation

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

    

arm092 / laravel-translation example snippets


Arm092\Translation\TranslationServiceProvider::class;
Arm092\Translation\TranslationBindingsServiceProvider::class;

'driver' => 'file', // file or database

'source_locale' => null,

'route_group_config' => [
    'middleware' => ['web'],
],

'route_group_config' => [
    'middleware' => ['web', 'auth'],
],

'route_group_config' => [
    'middleware' => ['web', 'auth'],
    'as' => 'translation.',
],

'authorization_gate' => null,

// app/Providers/AppServiceProvider.php
use App\Models\User;
use Illuminate\Support\Facades\Gate;

public function boot(): void
{
    Gate::define('manage-translations', function (User $user): bool {
        return $user->is_admin;
    });
}

// config/translation.php
'route_group_config' => [
    'middleware' => ['web', 'auth'],
],
'authorization_gate' => 'manage-translations',

'translation_methods' => ['trans', '__'],
'scan_paths' => [app_path(), resource_path()],
'scan_excluded_paths' => [storage_path(), base_path('vendor')],
'scan_ignored_keys' => [],
'scan_cache_path' => storage_path('framework/cache/translation-scan.json'),

'protected_locales' => ['en'],
'pagination' => 25,

'ui_url' => 'languages',

'database' => [
    'connection' => '',
    'languages_table' => 'languages',
    'translations_table' => 'translations',
],

'driver' => 'database',
shell
php artisan vendor:publish --provider="Arm092\Translation\TranslationServiceProvider" --tag=config
php artisan vendor:publish --provider="Arm092\Translation\TranslationServiceProvider" --tag=assets
shell
php artisan vendor:publish --provider="Arm092\Translation\TranslationServiceProvider"
shell
php artisan migrate
php artisan translation:sync-translations
shell
composer ptimize:clear