Skip to content

[rfc][translation] add getDefaultLocale to TranslatorInterface #40380

@gggeek

Description

@gggeek

Description
given the fact that the only method defined by TranslatorInterface allows the user to request that translation be executed using a 'default' target locale, it stands to reason that every concrete implementation of this interface has to define a default locale.
This default locale can be set up via configuration, DI injection and arbitrarily complex logic.
In some scenarios, it would be useful for end-user code, which usually has only access to a single translator instance, to be able to retrieve the current default locale without having to interact with the configuration logic.

Example
When building an app on top of an arbitrary framework based itself on symfony, it is quite common to write code that gets injected a Translator instance.
In some cases, that code will have to interact with an external system which can provide data in a locale-aware manner. Internalizing the translation of said data into the application is not desirable, as it is not in the ownership of the app itself.
In such scenario, it would be quite nice for the code to be able to do something like:

$this->getRemoteData($this->translator->getDefaultLocale();

without having to find out how the default locale is configured and managed by the specific framework in use.

Metadata

Metadata

Assignees

No one assigned

    Labels

    RFCRFC = Request For Comments (proposals about features that you want to be discussed)Translation

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions