PHP code example of lase-peco / localization

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

    

lase-peco / localization example snippets


'web' => [
     // Other middlewares
     //
     \LasePeco\Localization\Http\Middleware\Localization::class,
],
 php
php artisan  vendor:publish --provider="LasePeco\Localization\LocalizationServiceProvider"
 php
Localization::getCurrentLocale() 
 php
Localization::getCurrentLocaleName() 
 php
Localization::getCurrentLocaleNativeName() 
 php
Localization::getCurrentLocaleRegional()
 php
Localization::getSupportedLanguagesKeys() 
 php
//return
[
  0 => "ar"
  1 => "en"
  2 => "de"
]
 php
Localization::getSupportedLocales()
 php
//return
[
  "en" => [
    "direction" => "ltr"
    "regional" => "en_GB"
    "name" => "English"
    "native" => "English"
  ]
  "de" => [
    "direction" => "ltr"
    "regional" => "de_DE"
    "name" => "German"
    "native" => "Deutsch"
  ]
]
 php
route('locale', [$key]) // $key = "en" or "de" or ...
 php
//return
'Sep 14, 2021'   // 'en' 
'14.09.2021'     // 'de'
'14 sept. 2021'  // 'fn'
'١٤‏/٠٩‏/٢٠٢١'    // 'ar'
 php
//return
'1:27 PM'  // 'en' 
'13:27'    // 'de'
'١:٢٧ م'   // 'ar'
 html
@foreach(Localization::getSupportedLocales() as $key => $locale)
    <a href="{{ route('locale', [$key]) }}"
       class="block px-4 py-2 text-sm text-gray-700 hover:bg-gray-100"
       role="menuitem"><span class="flex items-center"><span class="inline-block h-4 w-auto mr-2">{!! Localization::getSupportedLocalesFlags()[$key] !!}</span>{{$locale['native']}}</span></a>
@endforeach