Skip to content

Commit

Permalink
Don't store user language in session
Browse files Browse the repository at this point in the history
So that we don't save it in every session on every page visit. Cookies are enough to remember selected language.
  • Loading branch information
Wruczek committed Jun 30, 2022
1 parent 8c93d31 commit 83d7d0b
Show file tree
Hide file tree
Showing 4 changed files with 4 additions and 5 deletions.
1 change: 0 additions & 1 deletion src/api/setlang.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
}

setcookie("tswebsite_language", $lang->getLanguageCode(), time() + (60 * 60 * 24) * 60, "/"); // 60 days
$_SESSION["userlanguageid"] = $lang->getLanguageId();

$returnTo = "../";

Expand Down
2 changes: 1 addition & 1 deletion src/private/php/Utils/Language/LanguageUtils.php
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ public function translate(string $identifier, $args = []): string {
}

$defaultlang = $this->getDefaultLanguage();
$lang = $this->getLanguageById(@$_SESSION["userlanguageid"]);
$lang = $this->getLanguageById(USER_LANGUAGE_ID);

if(!$lang && !$defaultlang) {
throw new \Exception("Cannot get user or default language");
Expand Down
2 changes: 1 addition & 1 deletion src/private/php/Utils/TemplateUtils.php
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ public function renderTemplateToString($templateName, $data = [], $loadLangs = t

if($loadLangs) {
$langUtils = LanguageUtils::i();
$userlang = $langUtils->getLanguageById($_SESSION["userlanguageid"]);
$userlang = $langUtils->getLanguageById(USER_LANGUAGE_ID);

if ($userlang === null) {
$userlang = $langUtils->getDefaultLanguage();
Expand Down
4 changes: 2 additions & 2 deletions src/private/php/load.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,14 +50,14 @@

// Try to guess user language and store it
// If the current language is not defined, or is invalid then return to default
if(!isset($_SESSION["userlanguageid"])) {
{
$lang = LanguageUtils::i()->detectUserLanguage();

if(!$lang) {
$lang = LanguageUtils::i()->getDefaultLanguage();
}

$_SESSION["userlanguageid"] = $lang->getLanguageId();
define("USER_LANGUAGE_ID", $lang->getLanguageId());
}

// Shortcut to language functions
Expand Down

0 comments on commit 83d7d0b

Please sign in to comment.