Skip to content

Commit 1913770

Browse files
committed
Add a constructor for FallbackLocaleProvider
1 parent c49ab42 commit 1913770

File tree

2 files changed

+13
-0
lines changed

2 files changed

+13
-0
lines changed

src/Symfony/Component/Translation/FallbackLocaleProvider.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111

1212
namespace Symfony\Component\Translation;
1313

14+
use Symfony\Component\Translation\Exception\InvalidArgumentException;
15+
1416
/**
1517
* Derives fallback locales based on ICU parent locale information, by shortening locale
1618
* sub tags and ultimately by going through a list of configured fallback locales.
@@ -26,6 +28,16 @@ class FallbackLocaleProvider implements FallbackLocaleProviderInterface
2628

2729
private array $parentLocales;
2830

31+
/**
32+
* @param string[] $locales
33+
*
34+
* @throws InvalidArgumentException If a locale contains invalid characters
35+
*/
36+
public function __construct(array $locales = [])
37+
{
38+
$this->setFallbackLocales($locales);
39+
}
40+
2941
public function setFallbackLocales(array $locales): void
3042
{
3143
foreach ($locales as $locale) {

src/Symfony/Component/Translation/FallbackLocaleProviderInterface.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ public function setFallbackLocales(array $locales): void;
3232

3333
/**
3434
* @internal
35+
*
3536
* @return string[]
3637
*/
3738
public function getFallbackLocales(): array;

0 commit comments

Comments
 (0)