PHP code example of outerweb / localization

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

    

outerweb / localization example snippets


protected $middlewareGroups = [
    'web' => [
        // ...
        \Outerweb\Localization\Http\Middleware\SetLocale::class,
    ],
];

return [
    /**
     * The cookies that this package will use internally..
     * If your app already uses some other cookie name,
     * you can change it here to make it more uniform.
     */
    'cookies' => [
        'locale' => 'locale',
    ],

    /**
     * If you prefer to define this in config/app.php,
     * leave this as null. It will then fallback to
     * the app.fallback_locale config value.
     */
    'fallback_locale' => null,

    /**
     * If you prefer to define this in config/app.php,
     * leave this as null. It will then fallback to
     * the app.supported_locales config value.
     */
    'supported_locales' => null,

    /**
     * The name of the translations file in the
     * lang directory. (default: routes.php)
     */
    'translations_file_name' => 'routes',
];

Route::localized(function () {
    Route::get('/', function () {
        return view('welcome');
    })
        ->name('home');
});

Route::fallback(function () {
    return redirect()->localizedRoute('home');
});

return [
    'about-us' => 'about-us',
];

return [
    'about-us' => 'over-ons',
];

localizedRoute('home'); // http://example.com/en (route name: en.home)
localizedRoute('blog.show', ['blog' => 'my-blog-post']); // http://example.com/en/blog/my-blog-post (route name: en.blog.show)
localizedRoute('home', [], 'nl'); // http://example.com/nl (route name: nl.home)

localization()->localizedRoutesForCurrentRoute();

[
    'en' => 'http://example.com/en/about-us',
    'nl' => 'http://example.com/nl/over-ons',
]

localization()->localizedRoutesForRoute('home');

[
    'en' => 'http://example.com/en',
    'nl' => 'http://example.com/nl',
]
bash
php artisan vendor:publish --tag="localization-config"