yiisoft/translator
Yii Translator provides a clean abstraction for message translation in PHP apps, with support for multiple message categories, locales, and fallback logic. Integrates with Yii components to load, format, and return translated strings consistently across your project.
#[\Override]) could simplify database-backed MessageSource implementations.composer.json and provide a ^3.1 branch for legacy support.#[\TranslationKey("key")]) could enable compile-time translation validation but may require Laravel 10+.#[\TranslationKey("user.greeting")] public string $greeting)?Locale and Catalog types to enforce stricter validation?Intl extension support simplify RTL or pluralization rule handling?composer.json to require php: ^8.5 and Laravel ^10.0.Translator service binding:
public function __construct(
private MessageSourceInterface $source,
private array $catalogs = [],
) {}
intl (for ICU), mbstring (for multibyte strings). PHP 8.5’s intl updates may improve Arabic/Hebrew pluralization.fiber for async translation workflows (experimental).make:translation commands with autocomplete.#[\TranslationKey]).composer.json and test with Laravel’s PHP 8.5 preset:
composer require php:^8.5 --dev
array_column → array_column($array, 'key')).#[TranslationKey("auth.login.title")]
public string $title;
enum Locale: string { case EN = 'en'; case ES = 'es'; }
$translations = Fiber::create(fn() => $api->translate($text, $locale))->start();
^3.1 branch.yiisoft/translator’s API.intl and mbstring are now mandatory (fail fast in composer.json).__() calls for PHP 8.5 deprecations (e.g., create_function).config/app.php to enforce PHP 8.5 types for translation arrays.OPcache).Intl improvements for RTL/pluralization.lang:publish commands.#[\TranslationKey] must match resources/lang/).Locale::ES instead of 'es').php:
- '8.5'
- '8.6'
AttributeErrorException for misconfigured #[\TranslationKey].#[Assert\All] to validate translation arrays at runtime.translate:keys command to generate a list of all #[\TranslationKey] usages.curl options).translation:override Artisan command with PHP 8.5’s interactive CLI.Fiber to batch API translation requests (e.g., 100 keys in parallel).#[ORM\Column(type: "json")] for nested translation structures.$semaphore = new Semaphore(10); // Max 10 concurrent requests
| Failure Scenario | Impact | Mitigation |
|---|---|---|
| PHP 8.5 JIT miscompilation | Slow translations | Disable JIT (OPcache.JitBufferSize=0) and fall back to interpreter. |
| Fiber memory leaks | OOM crashes | Use Fiber::suspend() and manual cleanup. |
| Attribute parsing errors | Broken translation keys | Fallback to legacy __() calls with deprecation warnings. |
| ` |
How can I help you explore Laravel packages today?