PHP code example of yiisoft / i18n

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

    

yiisoft / i18n example snippets


$locale = new \Yiisoft\I18n\Locale('es-CL');
echo $locale->language(); // es
echo $locale->region(); // CL

$locale = $locale->withLanguage('en');
echo $locale->asString(); // en-CL

echo $locale
    ->fallbackLocale()
    ->asString(); // en

use \Yiisoft\I18n\LocaleProvider;

final class MyService
{
    public function __construct(
        private LocaleProvider $localeProvider
    ) {    
    }
    
    public function doIt(): void
    {
        $locale = $this->localeProvider->get();
        if ($this->localeProvider->isDefaultLocale()) {
            // ...
        }
        
        // ...        
    }
    
}