Skip to content

Commit

Permalink
Add differentiation between "en-gb" & "en-us",…
Browse files Browse the repository at this point in the history
Closes #1
  • Loading branch information
urbantrout committed Oct 7, 2019
1 parent 5c5a6d3 commit 8dcd32c
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 9 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# 1.1.0

- Add differentiation between "en-gb" & "en-us", etc. (Fixes https://github.com/urbantrout/site-language-redirection/issues/1)

# 1.0.5

- Update composer dependencies to also support TYPO3 10
Expand Down
20 changes: 12 additions & 8 deletions Classes/Middleware/RedirectionMiddleware.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,10 +77,8 @@ protected function getRedirectResponseByBrowserLanguage(ServerRequestInterface $
if (!empty($acceptLanguages)) {
$acceptLanguages = array_unique(
array_map(function ($language) {
return explode('-', $language)[0];
}, array_map(function ($language) {
return explode(';', $language)[0];
}, explode(',', $acceptLanguages[0])))
}, explode(',', $acceptLanguages[0]))
);
} else {
// Do not redirect if no accept languages are set.
Expand All @@ -93,10 +91,16 @@ protected function getRedirectResponseByBrowserLanguage(ServerRequestInterface $
function ($language) use ($siteLanguages) {
return in_array(
$language,
array_map(function ($siteLanguage) {
/** @var SiteLanguage $siteLanguage */
return $siteLanguage->getTwoLetterIsoCode();
}, $siteLanguages)
array_merge(
array_map(function ($siteLanguage) {
/** @var SiteLanguage $siteLanguage */
return $siteLanguage->getHreflang();
}, $siteLanguages),
array_map(function ($siteLanguage) {
/** @var SiteLanguage $siteLanguage */
return $siteLanguage->getTwoLetterIsoCode();
}, $siteLanguages)
)
);
}
);
Expand All @@ -106,7 +110,7 @@ function ($language) use ($siteLanguages) {
}, array_map(function ($matchingSiteLanguage) use ($siteLanguages) {
return array_filter($siteLanguages, function ($siteLanguage) use ($matchingSiteLanguage) {
/** @var SiteLanguage $siteLanguage */
return $siteLanguage->getTwoLetterIsoCode() === $matchingSiteLanguage;
return $siteLanguage->getHreflang() === $matchingSiteLanguage || $siteLanguage->getTwoLetterIsoCode() === $matchingSiteLanguage;
});
}, $matchingSiteLanguages));

Expand Down
2 changes: 1 addition & 1 deletion ext_emconf.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
'description' => 'PSR-15 middleware to redirect user to correct site language via HTTP headers (Accept-Language)',
'category' => 'misc',
'shy' => 0,
'version' => '1.0.5',
'version' => '1.1.0',
'state' => 'stable',
'uploadfolder' => 0,
'clearcacheonload' => 0,
Expand Down

0 comments on commit 8dcd32c

Please sign in to comment.