PHP code example of bab55z / laravel-locale-switcher

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

    

bab55z / laravel-locale-switcher example snippets


'languages' => [
        /**
         * Key is the Laravel locale code
         * Index 0 of sub-array is the Carbon locale code
         * Index 1 of sub-array is the PHP locale code for setlocale()
         * Index 2 of sub-array is whether or not to use RTL (right-to-left) css for this language
         * Index 3 of sub-array is displayable name
         */
        'en'    => ['en', 'en_US', false, 'English'],
        'de'    => ['de', 'de_DE', false, 'Deutsch'],
        'pl'    => ['pl', 'pl_PL', false, 'Polski'],
        'fr'    => ['fr', 'fr_FR', false, 'Français'],
        'es'    => ['es', 'es_ES', false, 'Español'],
        'it'    => ['it', 'it_IT', false, 'Italiano'],
        'pt'    => ['pt_BR', 'pt_PT', false, 'Português'],
        /*'ar'    => ['ar', 'ar_AR', true, 'العربية'],
        'da'    => ['da', 'da_DK', false, 'Dansk'],
        'sv'    => ['sv', 'sv_SE', false, 'Svenska'],
        'th'    => ['th', 'th_TH', false, 'Thailändisch'],*/
    ],

<div class="navbar-dropdown is-boxed is-medium">
  @foreach(config('langswitcher.languages') as $locale => $localeDetails)
    {{--highlight active language --}}
    @if(strtolower(app()->getLocale()) == strtolower($locale))
      <a class="navbar-item is-menu disabled" href="/#">
        <img src="/img/{{$locale}}.png" alt="lang"> &nbsp; 
          <span style="{{strtolower(app()->getLocale()) == strtolower($locale) ? 'font-weight:bold;':''}}">
            {{$localeDetails[3]}}
          </span>
      </a>
    @endif
  @endforeach
  <hr class="navbar-divider">
  @foreach(config('langswitcher.languages') as $locale => $localeDetails)
      @if(strtolower(app()->getLocale()) != strtolower($locale))
        <a class="navbar-item is-menu" href="/lang/{{$locale}}">
          <img src="/img/{{$locale}}.png" alt="lang"> &nbsp;
          <span style="{{strtolower(app()->getLocale()) == strtolower($locale) ? 'font-weight:bold;':''}}">
            {{$localeDetails[3]}}
          </span>
        </a>
      @endif
  @endforeach
</div>