PHP code example of switon / i18n

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

    

switon / i18n example snippets


use Switon\Core\Attribute\Autowired;
use Switon\Core\LocaleInterface;
use Switon\Core\TranslatorInterface;

class WelcomeService
{
    #[Autowired] protected TranslatorInterface $translator;
    #[Autowired] protected LocaleInterface $locale;

    public function message(string $name): string
    {
        $this->locale->set('en');

        return $this->translator->translate('hello', ['name' => $name]);
    }
}