mirror of
https://github.com/phpbb/phpbb.git
synced 2025-08-12 03:34:04 +02:00
[ticket/17191] Use di and avoid circular ref
PHPBB3-17191
This commit is contained in:
committed by
Marc Alexander
parent
14b7caecd1
commit
8abf9b66e1
@@ -13,6 +13,7 @@
|
||||
|
||||
namespace phpbb\language;
|
||||
|
||||
use phpbb\config\config;
|
||||
use phpbb\language\exception\invalid_plural_rule_exception;
|
||||
|
||||
/**
|
||||
@@ -70,15 +71,29 @@ class language
|
||||
*/
|
||||
protected $loader;
|
||||
|
||||
/**
|
||||
* @var language_file_helper
|
||||
*/
|
||||
protected $lang_helper;
|
||||
|
||||
/**
|
||||
* @var \phpbb\config\config
|
||||
*/
|
||||
protected $config;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param \phpbb\language\language_file_loader $loader Language file loader
|
||||
* @param language_file_helper $lang_helper
|
||||
* @param array|null $common_modules Array of common language modules to load (optional)
|
||||
* @param config $config The config
|
||||
*/
|
||||
public function __construct(language_file_loader $loader, $common_modules = null)
|
||||
public function __construct(language_file_loader $loader, language_file_helper $lang_helper, config $config, $common_modules = null)
|
||||
{
|
||||
$this->loader = $loader;
|
||||
$this->lang_helper = $lang_helper;
|
||||
$this->config = $config;
|
||||
|
||||
// Set up default information
|
||||
$this->user_language = null;
|
||||
@@ -403,13 +418,10 @@ class language
|
||||
*/
|
||||
public function get_plural_form($number, $force_rule = false)
|
||||
{
|
||||
global $phpbb_container;
|
||||
// Get the language helper
|
||||
/* @var $language_helper \phpbb\language\language_file_helper */
|
||||
$language_file_helper = $phpbb_container->get('language.helper.language_file');
|
||||
global $user;
|
||||
|
||||
// Grab the users lang plural rule
|
||||
$plural_rule_content = $language_file_helper->get_lang_key_value('plural_rule');
|
||||
$plural_rule_content = $this->lang_helper->get_lang_key_value('plural_rule', $user->data['user_lang']);
|
||||
|
||||
$number = (int) $number;
|
||||
$plural_rule = ($force_rule !== false) ? $force_rule : ((isset($plural_rule_content)) ? $plural_rule_content : 1);
|
||||
|
@@ -15,8 +15,8 @@ namespace phpbb\language;
|
||||
|
||||
use DomainException;
|
||||
use phpbb\json\sanitizer as json_sanitizer;
|
||||
use phpbb\user;
|
||||
use Symfony\Component\Finder\Finder;
|
||||
use phpbb\config\config;
|
||||
|
||||
/**
|
||||
* Helper class for language file related functions
|
||||
@@ -28,19 +28,22 @@ class language_file_helper
|
||||
*/
|
||||
protected $phpbb_root_path;
|
||||
|
||||
/** @var user */
|
||||
protected $user;
|
||||
/**
|
||||
* @var \phpbb\config\config
|
||||
*/
|
||||
protected $config;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param string $phpbb_root_path Path to phpBB's root
|
||||
* @param user $user User Object
|
||||
* @param string $phpbb_root_path Path to phpBB's root
|
||||
* @param config $config The config
|
||||
*
|
||||
*/
|
||||
public function __construct(string $phpbb_root_path, \phpbb\user $user)
|
||||
public function __construct(string $phpbb_root_path, config $config)
|
||||
{
|
||||
$this->phpbb_root_path = $phpbb_root_path;
|
||||
$this->user = $user;
|
||||
$this->config = $config;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -79,16 +82,18 @@ class language_file_helper
|
||||
* @return string
|
||||
*
|
||||
*/
|
||||
public function get_lang_key_value($lang_key) : string
|
||||
public function get_lang_key_value($lang_key, $user_lang_db) : string
|
||||
{
|
||||
$available_languages = $this->get_available_languages();
|
||||
|
||||
foreach ($available_languages as $key => $value)
|
||||
{
|
||||
$available_languages[$value['iso']] = $value;
|
||||
unset($available_languages[$key]);
|
||||
}
|
||||
$user_lang = $this->user->data['user_lang'] ?? 'en';
|
||||
return $available_languages[$user_lang][$lang_key];
|
||||
$board_default_lang = $this->config['default_lang'];
|
||||
$user_lang_db = $user_lang_db ?? $board_default_lang;
|
||||
return $available_languages[$user_lang_db][$lang_key];
|
||||
}
|
||||
|
||||
/**
|
||||
|
Reference in New Issue
Block a user