1. Go to this page and download the library: Download stromcom/php-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/ */
stromcom / php-i18n example snippets
// config/dependencies.php
use Stromcom\I18n\Config\I18nConfig;
use Stromcom\I18n\Config\I18nServiceProvider;
use Stromcom\I18n\Runtime\MissingKeyPolicy;
return array_merge(I18nServiceProvider::definitions(), [
I18nConfig::class => static fn () => new I18nConfig(
projectId: 'auth-stromcom-cz',
token: (string) ($_ENV['I18N_TOKEN'] ?? ''),
baseUrl: 'https://translator.stromcom.cz',
sourceLocale: 'en',
targetLocales: ['cs', 'en', 'de', 'sk'],
fallbackLocale: 'en',
bundlesDir: dirname(__DIR__) . '/build/locales',
scanPaths: [dirname(__DIR__) . '/src', dirname(__DIR__) . '/templates'],
missingKeyPolicy: MissingKeyPolicy::LogAndFallback,
isDevelop: false,
// Optional — only for projects with notification templates (`<i18n:email>`).
notificationBundlesDir: dirname(__DIR__) . '/translations/notifications',
),
// … your own DI definitions …
]);
$app->add(\Stromcom\I18n\Runtime\LocaleMiddleware::class);
// LocaleMiddleware must run after the session and before the route handler.
foreach (\Stromcom\I18n\Config\I18nServiceProvider::consoleCommands() as $cmd) {
$app->addCommand($container->get($cmd));
}
// In a handler / domain service
$msg = $this->translator->trans('email.password_reset.subject', 'Reset your password');
// With ICU values
$msg = $this->translator->trans('admin.users.deleted', '{count, plural, one {# user deleted} other {# users deleted}}', ['count' => $n]);
// With a note (3rd positional / named arg `note:`) — the scanner extracts it as metadata
// for translators, the runtime ignores it:
$msg = $this->translator->trans('signup.title', 'Sign up', note: 'Page heading');