1
0
mirror of https://github.com/phpbb/phpbb.git synced 2025-08-06 08:47:45 +02:00

[ticket/17191] Inject variables from composer.json when loading language files

PHPBB3-17191
This commit is contained in:
Marc Alexander
2023-10-04 21:16:54 +02:00
parent 4baa3e778d
commit dc9ef40669
10 changed files with 69 additions and 100 deletions

View File

@@ -71,29 +71,15 @@ class language
*/
protected $loader;
/**
* @var language_file_helper
*/
protected $lang_helper;
/**
* @var 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, language_file_helper $lang_helper, config $config, $common_modules = null)
public function __construct(language_file_loader $loader, $common_modules = null)
{
$this->loader = $loader;
$this->lang_helper = $lang_helper;
$this->config = $config;
// Set up default information
$this->user_language = null;
@@ -399,10 +385,27 @@ class language
$this->load_core_file($lang_file);
}
$this->inject_default_variables();
$this->common_language_files_loaded = true;
}
}
/**
* Inject default values based on composer.json
*
* @return void
*/
protected function inject_default_variables(): void
{
$lang_values = $this->loader->get_composer_lang_values($this->language_fallback);
$this->lang['DIRECTION'] = $lang_values['direction'] ?? 'ltr';
$this->lang['USER_LANG'] = $lang_values['user_lang'] ?? 'en-gb';
$this->lang['PLURAL_RULE'] = $lang_values['plural_rule'] ?? 1;
$this->lang['RECAPTCHA_LANG'] = $lang_values['recaptcha_lang'] ?? 'en-GB';
}
/**
* Determine which plural form we should use.
*
@@ -418,13 +421,8 @@ class language
*/
public function get_plural_form($number, $force_rule = false)
{
global $user;
// Grab the users lang 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);
$plural_rule = ($force_rule !== false) ? $force_rule : ((isset($this->lang['PLURAL_RULE'])) ? $this->lang['PLURAL_RULE'] : 1);
/**
* The following plural rules are based on a list published by the Mozilla Developer Network