PHP code example of palgoals / locale-package

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

    

palgoals / locale-package example snippets


->withMiddleware(function (Middleware $middleware) {
    $middleware->alias([
        'setLocale' => \App\Http\Middleware\SetLocale::class,
    ]);
})

protected $middlewareAliases = [
    'setLocale' => \App\Http\Middleware\SetLocale::class,
];

Route::middleware(['setLocale'])->group(function () {
    



view()->composer('*', function ($view) {
    $view->with([
        'currentLocale'   => app()->getLocale(),
        'currentLanguage' => \App\Models\Language::where('code', app()->getLocale())->first(),
        'languages'       => \App\Models\Language::where('is_active', true)->get(),
    ]);
});

return [
    // Optional: resolve default language from your own settings model
    'default_language_resolver' => function () {
        return \App\Models\GeneralSetting::first()?->default_language_code
            ?? config('app.locale');
    },

    // Auto-create missing translation keys in the DB
    'auto_create' => env('TRANSLATION_AUTO_CREATE', true),

    // Cache duration in seconds
    'cache_ttl' => env('TRANSLATION_CACHE_TTL', 60),
];
bash
php artisan locale:install
bash
> php artisan locale:install --seed
> 
json
"autoload": {
    "files": [
        "app/helpers_locale.php"
    ]
}
bash
composer dump-autoload