php-translation/common
Shared contracts and utilities for the PHP Translation ecosystem. Provides common interfaces, models, and helpers used across translation bundles to keep integrations consistent and reduce duplication, making it easier to build and maintain translation features in PHP apps.
Architecture Fit
The php-translation/common package excels as a standardized translation abstraction layer for Laravel applications, particularly those requiring multi-language support, pluralization, or locale-specific formatting. Its contract-first design aligns with Laravel’s dependency injection and service container, enabling seamless integration without tight coupling. The package’s framework-agnostic core (Symfony-compatible interfaces) makes it ideal for Laravel projects leveraging Symfony components (e.g., validation, HTTP clients) or planning future Symfony adoption. Key strengths include:
TranslatorInterface, Message, LoaderInterface) that reduce duplication and enforce consistency.Integration Feasibility
trans() helper, language files (resources/lang), and service container. For example:
// Bind the package’s Translator to Laravel’s container
$this->app->singleton(\PhpTranslation\Common\TranslatorInterface::class, function ($app) {
return new \PhpTranslation\Common\Translator(
new \PhpTranslation\Common\Loader\FileLoader($app['path.lang'])
);
});
Validator, HttpFoundation). The package’s Symfony 7 support ensures compatibility with Laravel’s growing reliance on Symfony (e.g., Laravel 11’s Symfony 7.x dependencies).Technical Risk
trans() helper integration).Key Questions
Validator, Mailer)? Are they on Symfony 7.x?Stack Fit
trans() helper, Lang facade) for consistent, maintainable i18n.Migration Path
trans(), Lang::get(), custom helpers).resources/lang) and custom logic.Translator with the package’s implementation:
$this->app->singleton(\PhpTranslation\Common\TranslatorInterface::class, function ($app) {
return new \PhpTranslation\Common\Translator(
new \PhpTranslation\Common\Loader\FileLoader($app['path.lang'])
);
});
trans() helper to use the new translator:
facade('trans', \PhpTranslation\Common\TranslatorInterface::class);
Compatibility
| Component | Compatibility Notes |
|---|---|
| Laravel 10/11 | Full support (PHP 8.1+). Use Symfony 7.x components if needed. |
| Laravel 9.x | Possible with PHP 8.1, but Symfony 7 may cause conflicts. |
| Symfony 7.x | Native support. Critical for projects using Symfony components. |
| Symfony 6.x | Unverified; may require polyfills or workarounds. |
| PHP 8.2–8.3 | Required. Laravel 10/11 projects are already aligned. |
| Third-Party | Test conflicts with packages like spatie/laravel-translatable or laravel-localization. |
Sequencing
Translator to Laravel’s container.trans() helper usage in non-critical modules.Validator, HttpFoundation).Message objects for pluralization).Maintenance
^3.3 in composer.json to balance stability and updates.Support
How can I help you explore Laravel packages today?