PHP code example of mgcodeur / laravel-translation-loader

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

    

mgcodeur / laravel-translation-loader example snippets




use Mgcodeur\LaravelTranslationLoader\Translations\TranslationMigration;

return new class extends TranslationMigration
{
    public function up(): void
    {
        $this->add('en', 'welcome.title', 'Welcome to Our App');
        $this->add('fr', 'welcome.title', 'Bienvenue dans notre application');
        $this->add('es', 'welcome.title', 'Bienvenido a nuestra aplicación');
    }

    public function down(): void
    {
        $this->delete('en', 'welcome.title');
        $this->delete('fr', 'welcome.title');
        $this->delete('es', 'welcome.title');

        // or you can just do: $this->deleteAll('welcome.title');
        // $this->deleteAll('key1', 'key2', 'key3');
    }
};

// In controllers, views, or anywhere
echo __('welcome.title'); // Outputs: "Welcome to Our App" (if en is active)

$this->addMany('en', [
    'email' => 'Email',
    'password' => 'Password',
]);

$this->addMany('fr', [
    'email' => 'Email',
    'password' => 'Mot de passe',
]);

$this->addMany([
    'en' => [
        'login' => 'Login',
        'logout' => 'Logout',
    ],
    'fr' => [
        'login' => 'Se connecter',
        'logout' => 'Se déconnecter',
    ],
]);

$this->update('en', 'welcome.title', 'Welcome to Our Awesome App');
bash
php artisan laravel-translation-loader:install
bash
php artisan migrate
bash
php artisan make:translation welcome
bash
php artisan translation:migrate
bash
php artisan translation:rollback
bash
php artisan translation:status
bash
php artisan translation:generate