[ticket/17191] Make sure user_lang from DB is considered, with fallback

PHPBB3-17191
This commit is contained in:
Christian Schnegelberger 2023-09-22 17:30:23 +02:00 committed by Marc Alexander
parent a54f5c0ca0
commit 14b7caecd1
No known key found for this signature in database
GPG key ID: 50E0D2423696F995
2 changed files with 15 additions and 2 deletions

View file

@ -3,6 +3,7 @@ services:
class: phpbb\language\language_file_helper class: phpbb\language\language_file_helper
arguments: arguments:
- '%core.root_path%' - '%core.root_path%'
- '@user'
language: language:
class: phpbb\language\language class: phpbb\language\language

View file

@ -15,6 +15,7 @@ namespace phpbb\language;
use DomainException; use DomainException;
use phpbb\json\sanitizer as json_sanitizer; use phpbb\json\sanitizer as json_sanitizer;
use phpbb\user;
use Symfony\Component\Finder\Finder; use Symfony\Component\Finder\Finder;
/** /**
@ -27,14 +28,19 @@ class language_file_helper
*/ */
protected $phpbb_root_path; protected $phpbb_root_path;
/** @var user */
protected $user;
/** /**
* Constructor * Constructor
* *
* @param string $phpbb_root_path Path to phpBB's root * @param string $phpbb_root_path Path to phpBB's root
* @param user $user User Object
*/ */
public function __construct(string $phpbb_root_path) public function __construct(string $phpbb_root_path, \phpbb\user $user)
{ {
$this->phpbb_root_path = $phpbb_root_path; $this->phpbb_root_path = $phpbb_root_path;
$this->user = $user;
} }
/** /**
@ -76,7 +82,13 @@ class language_file_helper
public function get_lang_key_value($lang_key) : string public function get_lang_key_value($lang_key) : string
{ {
$available_languages = $this->get_available_languages(); $available_languages = $this->get_available_languages();
return $available_languages[0][$lang_key];
foreach ($available_languages as $key => $value)
{
$available_languages[$value['iso']] = $value;
}
$user_lang = $this->user->data['user_lang'] ?? 'en';
return $available_languages[$user_lang][$lang_key];
} }
/** /**