1. Go to this page and download the library: Download wilycode/translation 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/ */
use WilyCode\Translation\LocaleFormatter\LocaleFormatterFactory;
$factory = new LocaleFormatterFactory(
__DIR__ . '/resources/locales',
'pl-PL',
);
$formatter = $factory->forCode('pl-PL');
use WilyCode\Translation\TranslatorInterface;
final readonly class WelcomeService
{
public function __construct(
private TranslatorInterface $translator,
) {}
public function message(string $name): string
{
return $this->translator->translate(
'messages',
'welcome',
['name' => $name],
);
}
}
use WilyCode\Translation\TranslatorInterface;
function itemSummary(TranslatorInterface $translator, int $count): string
{
return $translator->translatePlural(
'shop',
'items',
$count,
['count' => $count],
);
}