PHP code example of preflow / i18n
1. Go to this page and download the library: Download preflow/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/ */
preflow / i18n example snippets
return [
'default' => 'en',
'available' => ['en', 'de'],
'fallback' => 'en',
'url_strategy' => 'prefix', // 'prefix' | 'none'
];
return [
'title' => 'My Blog',
'published' => 'Published on :date',
'post_count' => '{0} No posts|{1} One post|[2,*] :count posts',
];
$translator = new Translator(
langPath: __DIR__ . '/lang',
locale: 'en',
fallbackLocale: 'en',
);
$translator->get('blog.title'); // "My Blog"
$translator->get('blog.published', ['date' => '2026-01-01']); // "Published on 2026-01-01"
$translator->choice('blog.post_count', 5); // "5 posts"
$translator->setLocale('de');
$translator->getLocale(); // "de"
$middleware = new LocaleMiddleware(
translator: $translator,
availableLocales: ['en', 'de'],
defaultLocale: 'en',
urlStrategy: 'prefix', // request to /de/blog strips /de, sets locale to "de"
);
$twig->addExtension(new TranslationExtension($translator));