feature #40554 [Contracts] Add TranslatorInterface::getLocale() (nicolas-grekas)

This PR was merged into the 5.3-dev branch.

Discussion
----------

[Contracts] Add `TranslatorInterface::getLocale()`

| Q             | A
| ------------- | ---
| Branch?       | 5.x
| Bug fix?      | no
| New feature?  | yes
| Deprecations? | yes
| Tickets       | Fix #40380
| License       | MIT
| Doc PR        | -

As discussed in https://github.com/symfony/symfony/issues/40380

Commits
-------

45d9a36794 [Contracts/Translation] Add `TranslatorInterface::getLocale()`
This commit is contained in:
Nicolas Grekas 2021-03-23 22:10:30 +01:00
commit 7f640123cb
6 changed files with 20 additions and 0 deletions

View File

@ -19,4 +19,9 @@ class StubTranslator implements TranslatorInterface
{
return '[trans]'.strtr($id, $parameters).'[/trans]';
}
public function getLocale(): string
{
return 'en';
}
}

View File

@ -111,4 +111,9 @@ class TranslatorWithTranslatorBag implements TranslatorInterface
public function trans(string $id, array $parameters = [], string $domain = null, string $locale = null): string
{
}
public function getLocale(): string
{
return 'en';
}
}

View File

@ -108,6 +108,11 @@ final class PseudoLocalizationTranslator implements TranslatorInterface
return $trans;
}
public function getLocale(): string
{
return $this->translator->getLocale();
}
private function getParts(string $originalTrans): array
{
if (!$this->parseHTML) {

View File

@ -5,6 +5,7 @@ CHANGELOG
---
* Add `HttpClientInterface::withOptions()`
* Add `TranslatorInterface::getLocale()`
2.3.0
-----

View File

@ -13,6 +13,8 @@ namespace Symfony\Contracts\Translation;
/**
* @author Fabien Potencier <fabien@symfony.com>
*
* @method string getLocale() Returns the default locale
*/
interface TranslatorInterface
{

View File

@ -32,6 +32,8 @@ trait TranslatorTrait
/**
* {@inheritdoc}
*
* @return string
*/
public function getLocale()
{