Installation Add the package via Composer (though note the read-only warning):
composer require beloop/language-bundle
Register the bundle in config/bundles.php:
return [
// ...
Beloop\LanguageBundle\BeloopLanguageBundle::class => ['all' => true],
];
First Use Case Translate a string in a controller or template:
use Beloop\LanguageBundle\Translator\Translator;
class MyController extends AbstractController {
public function index(Translator $translator) {
$translated = $translator->trans('Hello world');
return new Response($translated);
}
}
Or in Twig:
{{ 'Hello world'|trans }}
Where to Look First
config/packages/beloop_language.yaml (if auto-generated).BeloopLanguageBundle::getServices() in the bundle class.translations/messages.{locale}.yml (Symfony standard).Translation Management
translations/messages.{locale}.yml:
# translations/messages.en.yml
hello: "Hello, %name%!"
Use placeholders with %var% syntax.$translator->trans('hello', ['%name%' => 'John']);
Integration with Symfony Components
TranslatorInterface, so use it like any Symfony translator.kernel.request events to modify translations dynamically.Custom Domains
validation.yml) by extending the bundle’s configuration:
# config/packages/beloop_language.yaml
beloop_language:
domains: ['messages', 'validation']
config/packages/beloop_language.yaml:
beloop_language:
fallback_locales: ['en', 'fr']
LocaleListener (if included) to switch locales via URL parameters:
// In a controller
$request->setLocale('fr');
Archived Status:
Outdated Dependencies:
Missing Documentation:
src/Resources/config/services.yaml (service definitions).src/DependencyInjection/ (compiler passes, extensions).translations/messages.{locale}.yml and the domain is registered.
php bin/console debug:translation --all
LocaleListener is enabled (if used) and the locale route parameter is configured in your router.config/services.yaml:
services:
Beloop\LanguageBundle\Translator\Translator:
arguments:
$loader: '@your_custom_loader'
Loader class to support JSON/XML translations:
class CustomLoader extends \Beloop\LanguageBundle\Loader\YamlFileLoader {
public function load($resource, $locale, $domain = 'messages') {
// Custom logic
}
}
BeloopLanguageBundleEvents::TRANSLATION_MODIFIED (if exposed) to intercept translations.config/packages/beloop_language.yaml or fall back to Symfony’s default:
beloop_language:
default_locale: 'en'
php bin/console cache:clear
How can I help you explore Laravel packages today?