PHP code example of jersyfi / laravel-localization
1. Go to this page and download the library: Download jersyfi/laravel-localization 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/ */
jersyfi / laravel-localization example snippets
return [
/**
* Applications default locale need to be set because the config('app.locale')
* gives back the current locale and not the value from config
*/
'default_locale' => 'de',
/**
* Application locales determines all locals that exists in the application
* You can ignore or delete the locales from app.locales if you set some
*/
'locales' => [
'en',
'de'
],
/**
* Redirect to default locale when not found
*/
'redirect_default' => false,
/**
* Detect user locale via http header
* When no locale is stored in session user gets redirected
*/
'detect_locale' => false,
/**
* Application can store the prefered_locale in the users database table
*/
'store_users_database' => true,
/**
* Setup for the users database table
* Only if 'store_users_database' is set to true
*/
'database' => [
'users_table_name' => 'users',
'prefered_locale_column_name' => 'prefered_locale',
],
];
use Jersyfi\Localization\Http\Controllers\LocaleController;
Route::get('/', [LocaleController::class, 'localize'])
->name('locale');
Route::prefix('{locale}')
->middleware('locale')
->group(function () {
// your localized routes here
});
$slug = Localization::getLocaleSlug('en_GB'); // en-gb
$slug = Localization::getLocaleSlug(); // de