PHP code example of thinktomorrow / locale

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

    

thinktomorrow / locale example snippets


# config/thinktomorrow/locale.php

'locales' => [
        '*' => [
            'en' => 'en',
            '/'  => 'nl',
        ],
    ],

# config/thinktomorrow/locale.php

'locales' => [
        'fr.example.com' => 'fr',
        '*' => 'nl',
    ],

        'locales' => [
            '*' => [
                'nl',
                'en',
            ]
        ],
    

        'locales' => [
            'https://awesome-domain-nl.com' => [
                '/' => 'nl',
            ],
            'https://awesome-domain-en.com' => [
                '/' => 'en',
            ]
        ],
    

        'locales' => [
            'https://awesome-domain.com' => [
                'en'    => 'en',
                '/'     => 'nl',
            ]
        ],
    
 bash
    php artisan vendor:publish --provider="Thinktomorrow\Locale\LocaleServiceProvider"
 php
    
    Route::group(['prefix' => localeRoutePrefix()],function(){
        
        // Routes registered within this group will be localized
        
    });
    
 php
    route('pages.about'); // prints out http://example.com/en/about (if en is the active locale)
 php
    
    // Generate localized url from uri (resolves as laravel url() function)
    localeroute('about','en'); // http://example.com/en/about
    
    // Generate localized url from named route (resolves as laravel route() function)
    localeroute('pages.about','en'); // http://example.com/en/about  
    
    // Add additional parameters as third parameter
    localeroute('products.show','en',['slug' => 'tablet'])); // http://example/en/products/tablet
    
 php
    Locale::set('en'); // Sets a new application locale and returns the locale slug