Commit 9093b16f authored by Fabrice Gangler's avatar Fabrice Gangler 🎨 Committed by Matthieu FAURE
Browse files

FIX: improve for HTTP Accept-Language header not supported

Refs: #910
parent 6e511a9e
Pipeline #9892 failed with stage
in 4 minutes and 17 seconds
...@@ -974,7 +974,7 @@ class UsersController extends AppController ...@@ -974,7 +974,7 @@ class UsersController extends AppController
$reviewsNumber = count($user->reviews); $reviewsNumber = count($user->reviews);
if ($reviewsNumber === 0) { if ($reviewsNumber === 0) {
$lang = I18n::locale(); $lang = $this->selectedLanguage;
$this->redirect("$lang/users/$id", 301); $this->redirect("$lang/users/$id", 301);
} else { } else {
$this->set(compact('user')); $this->set(compact('user'));
......
...@@ -183,7 +183,7 @@ class AppController extends Controller ...@@ -183,7 +183,7 @@ class AppController extends Controller
$data['title'] = trim(filter_var($linkData['title'], FILTER_SANITIZE_STRING)); $data['title'] = trim(filter_var($linkData['title'], FILTER_SANITIZE_STRING));
} }
if (isset($linkData['url'])) { if (isset($linkData['url'])) {
$lang = I18n::locale(); $lang = $this->selectedLanguage;
$urlPart = $linkData['url']; $urlPart = $linkData['url'];
$data['url'] = "/$lang/$urlPart"; $data['url'] = "/$lang/$urlPart";
} }
...@@ -195,7 +195,6 @@ class AppController extends Controller ...@@ -195,7 +195,6 @@ class AppController extends Controller
public function beforeFilter(Event $event) public function beforeFilter(Event $event)
{ {
$this->Auth->allow(['index', 'logout', 'view', 'request', 'search']); $this->Auth->allow(['index', 'logout', 'view', 'request', 'search']);
$this->setLocale(); $this->setLocale();
$this->setOpenGraph(); $this->setOpenGraph();
parent::beforeFilter($event); parent::beforeFilter($event);
...@@ -208,17 +207,20 @@ class AppController extends Controller ...@@ -208,17 +207,20 @@ class AppController extends Controller
*/ */
protected function setLocale() protected function setLocale()
{ {
$selectedLanguage = I18n::locale();
if ($this->request->param('language')) { if ($this->request->param('language')) {
$lang = $this->request->param('language'); $lang = $this->request->param('language');
} else { } else {
$lang = preg_replace('/_\w*/', "", I18n::locale()); $lang = preg_replace('/_\w*/', "", I18n::locale());
} }
if ($lang && isset($this->availableLanguages[$lang])) { if (isset($this->availableLanguages[$lang])) {
I18n::locale($lang); I18n::locale($lang);
$selectedLanguage = $this->availableLanguages[$lang]; $selectedLanguage = $this->availableLanguages[$lang];
} else {
I18n::locale('en');
$selectedLanguage = I18n::locale();
} }
$this->selectedLanguage = $selectedLanguage; $this->selectedLanguage = $selectedLanguage;
$this->set('selectedLanguage', $selectedLanguage); $this->set('selectedLanguage', $selectedLanguage);
$this->set('availableLanguages', $this->availableLanguages); $this->set('availableLanguages', $this->availableLanguages);
......
...@@ -129,7 +129,7 @@ class ReviewHelper extends ListItemHelper ...@@ -129,7 +129,7 @@ class ReviewHelper extends ListItemHelper
'created' => $this->Time->format( 'created' => $this->Time->format(
$review->created->toUnixString(), $review->created->toUnixString(),
[IntlDateFormatter::SHORT, -1], [IntlDateFormatter::SHORT, -1],
I18n::locale() $selectedLanguage
), ),
'stars' => $this->Rating->display($review->evaluation), 'stars' => $this->Rating->display($review->evaluation),
] ]
...@@ -155,7 +155,7 @@ class ReviewHelper extends ListItemHelper ...@@ -155,7 +155,7 @@ class ReviewHelper extends ListItemHelper
'created' => $this->Time->format( 'created' => $this->Time->format(
$review->created->toUnixString(), $review->created->toUnixString(),
[IntlDateFormatter::SHORT, -1], [IntlDateFormatter::SHORT, -1],
I18n::locale() $selectedLanguage
), ),
'stars' => $this->Rating->display($review->evaluation), 'stars' => $this->Rating->display($review->evaluation),
] ]
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment