8000 feature #40554 [Contracts] Add `TranslatorInterface::getLocale()` (ni… · symfony/symfony@7f64012 · GitHub
[go: up one dir, main page]

Skip to content

Commit 7f64012

Browse files
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 #40380 Commits ------- 45d9a36 [Contracts/Translation] Add `TranslatorInterface::getLocale()`
2 parents 45b53fe + 45d9a36 commit 7f64012

File tree

6 files changed

+20
-0
lines changed

6 files changed

+20
-0
lines changed

src/Symfony/Bridge/Twig/Tests/Extension/Fixtures/StubTranslator.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,9 @@ public function trans($id, array $parameters = [], $domain = null, $locale = nul
1919
{
2020
return '[trans]'.strtr($id, $parameters).'[/trans]';
2121
}
22+
23+
public function getLocale(): string
24+
{
25+
return 'en';
26+
}
2227
}

src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Compiler/DataCollectorTranslatorPassTest.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,4 +111,9 @@ class TranslatorWithTranslatorBag implements TranslatorInterface
111111
public function trans(string $id, array $parameters = [], string $domain = null, string $locale = null): string
112112
{
113113
}
114+
115+
public function getLocale(): string
116+
{
117+
return 'en';
118+
}
114119
}

src/Symfony/Component/Translation/PseudoLocalizationTranslator.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,11 @@ public function trans(string $id, array $parameters = [], string $domain = null,
108108
return $trans;
109109
}
110110

111+
public function getLocale(): string
112+
{
113+
return $this->translator->getLocale();
114+
}
115+
111116
private function getParts(string $originalTrans): array
112117
{
113118
if (!$this->parseHTML) {

src/Symfony/Contracts/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ CHANGELOG
55
---
66

77
* Add `HttpClientInterface::withOptions()`
8+
* Add `TranslatorInterface::getLocale()`
89

910
2.3.0
1011
-----

src/Symfony/Contracts/Translation/TranslatorInterface.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313

1414
/**
1515
* @author Fabien Potencier <fabien@symfony.com>
16+
*
17+
* @method string getLocale() Returns the default locale
1618
*/
1719
interface TranslatorInterface
1820
{

src/Symfony/Contracts/Translation/TranslatorTrait.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@ public function setLocale(string $locale)
3232

3333
/**
3434
* {@inheritdoc}
35+
*
36+
* @return string
3537
*/
3638
public function getLocale()
3739
{

0 commit comments

Comments
 (0)
0