Documentation

TranslatorServiceProvider
in package
implements ServiceProviderInterface

Registers the Translator as a singleton and sets the active locale from the database during the boot phase.

Tags
since
3.0.0

Table of Contents

Interfaces

ServiceProviderInterface
Interface for service providers that register services in the container.

Methods

boot()  : void
Read the user's locale preference from settings and apply it.
register()  : void
Register the Translator singleton.
resolveLocaleOverride()  : string|null
Resolve an explicit UI-language override from the request.

Methods

boot()

Read the user's locale preference from settings and apply it.

public boot(Container $container) : void

Runs after all providers are registered, so the DB is available. Silently defaults to English if the DB is not yet configured (e.g. during the setup wizard).

Parameters
$container : Container

The DI container

resolveLocaleOverride()

Resolve an explicit UI-language override from the request.

private resolveLocaleOverride(Translator $translator) : string|null

Precedence: a ?lang= query parameter (which is also persisted to the lwt_lang cookie) over an existing lwt_lang cookie. Both are validated against the available locales so only a real locale can be selected.

Parameters
$translator : Translator

Used to list the available locales.

Return values
string|null

The chosen locale, or null when none/invalid.


        
On this page

Search results