From 82bdc3abb49d7f8b19135624d6050a73334111fb Mon Sep 17 00:00:00 2001 From: SirDomin Date: Tue, 20 Apr 2021 10:02:35 +0200 Subject: [PATCH 1/3] add spec to en locale --- spec/Processor/LocaleProcessorSpec.php | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/spec/Processor/LocaleProcessorSpec.php b/spec/Processor/LocaleProcessorSpec.php index 52ea53b8..c0d675ba 100644 --- a/spec/Processor/LocaleProcessorSpec.php +++ b/spec/Processor/LocaleProcessorSpec.php @@ -21,4 +21,9 @@ function it_returns_same_locale_if_it_is_valid(): void $this->process('ja_JP_TRADITIONAL')->shouldReturn('ja_JP_TRADITIONAL'); $this->process('sd_Arab_PK')->shouldReturn('sd_Arab_PK'); } + + function it_returns_correct_locale_for_en_locale(): void + { + $this->process('en')->shouldReturn('en_EN'); + } } From d6c2cd0800b5924fa651cc4cb69cb4b67c2f2cec Mon Sep 17 00:00:00 2001 From: SirDomin Date: Tue, 20 Apr 2021 11:17:22 +0200 Subject: [PATCH 2/3] locale processor supports en locale --- spec/Processor/LocaleProcessorSpec.php | 2 +- src/Processor/LocaleProcessor.php | 5 +++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/spec/Processor/LocaleProcessorSpec.php b/spec/Processor/LocaleProcessorSpec.php index c0d675ba..68ab9f25 100644 --- a/spec/Processor/LocaleProcessorSpec.php +++ b/spec/Processor/LocaleProcessorSpec.php @@ -24,6 +24,6 @@ function it_returns_same_locale_if_it_is_valid(): void function it_returns_correct_locale_for_en_locale(): void { - $this->process('en')->shouldReturn('en_EN'); + $this->process('en')->shouldReturn('en_US'); } } diff --git a/src/Processor/LocaleProcessor.php b/src/Processor/LocaleProcessor.php index 58e7f12e..d27e28a7 100644 --- a/src/Processor/LocaleProcessor.php +++ b/src/Processor/LocaleProcessor.php @@ -17,11 +17,12 @@ public function process(string $locale): string $locales = array_filter(Locales::getLocales(), function (string $targetLocale) use ($locale): bool { return strpos($targetLocale, $locale) === 0 && - strpos($targetLocale, '_') !== false + strpos($targetLocale, '_') !== false && + strlen($targetLocale) === 5 ; }); - return $locales[array_key_first($locales)]; + return preg_replace('/en_[A-Z]{2}/', 'en_US', $locales[array_key_first($locales)]); } private function isValidLocale(string $locale): bool From 51623cd7a09cf4377cbc298e629c5f6880cbfa79 Mon Sep 17 00:00:00 2001 From: SirDomin Date: Thu, 22 Apr 2021 11:45:26 +0200 Subject: [PATCH 3/3] pr-fix --- src/Processor/LocaleProcessor.php | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/Processor/LocaleProcessor.php b/src/Processor/LocaleProcessor.php index d27e28a7..533be637 100644 --- a/src/Processor/LocaleProcessor.php +++ b/src/Processor/LocaleProcessor.php @@ -14,6 +14,10 @@ public function process(string $locale): string return $locale; } + if ($locale === 'en') { + return 'en_US'; + } + $locales = array_filter(Locales::getLocales(), function (string $targetLocale) use ($locale): bool { return strpos($targetLocale, $locale) === 0 && @@ -22,7 +26,7 @@ public function process(string $locale): string ; }); - return preg_replace('/en_[A-Z]{2}/', 'en_US', $locales[array_key_first($locales)]); + return $locales[array_key_first($locales)]; } private function isValidLocale(string $locale): bool