From 6d07852410221205a867c3233585e760804d58a4 Mon Sep 17 00:00:00 2001 From: Christian Schnegelberger Date: Thu, 21 Sep 2023 17:00:37 +0200 Subject: [PATCH] [ticket/17191] Add new direction and user_langto helper and language.php PHPBB3-17191 --- phpBB/includes/functions.php | 4 +++- phpBB/includes/functions_acp.php | 18 ++++++++++++++---- phpBB/phpbb/install/controller/helper.php | 16 ++++++++++++---- phpBB/phpbb/language/language.php | 10 +++++++++- 4 files changed, 38 insertions(+), 10 deletions(-) diff --git a/phpBB/includes/functions.php b/phpBB/includes/functions.php index 850b3ef28d..34e9dd66cb 100644 --- a/phpBB/includes/functions.php +++ b/phpBB/includes/functions.php @@ -3668,7 +3668,7 @@ function phpbb_get_avatar($row, $alt, $ignore_config = false, $lazy = false) function page_header($page_title = '', $display_online_list = false, $item_id = 0, $item = 'forum', $send_headers = true) { global $db, $config, $template, $SID, $_SID, $_EXTRA_URL, $user, $auth, $phpEx, $phpbb_root_path; - global $phpbb_dispatcher, $request, $phpbb_container, $phpbb_admin_path, $language_helper; + global $phpbb_dispatcher, $request, $phpbb_container, $phpbb_admin_path; if (defined('HEADER_INC')) { @@ -3824,6 +3824,8 @@ function page_header($page_title = '', $display_online_list = false, $item_id = $web_path = $phpbb_path_helper->get_web_root_path(); // Send a proper content-language to the output + // Get the language helper + /* @var $language_helper \phpbb\language\language_file_helper */ $language_file_helper = $phpbb_container->get('language.helper.language_file'); // Grab the users lang direction and store it for later use diff --git a/phpBB/includes/functions_acp.php b/phpBB/includes/functions_acp.php index 26d16aaae8..1b02c028a7 100644 --- a/phpBB/includes/functions_acp.php +++ b/phpBB/includes/functions_acp.php @@ -69,6 +69,16 @@ function adm_page_header($page_title) $phpbb_version_parts = explode('.', PHPBB_VERSION, 3); $phpbb_major = $phpbb_version_parts[0] . '.' . $phpbb_version_parts[1]; + // Get the language helper + /* @var $language_helper \phpbb\language\language_file_helper */ + $language_file_helper = $phpbb_container->get('language.helper.language_file'); + + // Grab the users lang direction and store it for later use + $direction = $language_file_helper->get_lang_key_value('direction'); + + // Get the user_lang string + $user_lang = $language_file_helper->get_lang_key_value('user_lang'); + $template->assign_vars(array( 'PAGE_TITLE' => $page_title, 'USERNAME' => $user->data['username'], @@ -109,11 +119,11 @@ function adm_page_header($page_title) 'ICON_SYNC_DISABLED' => '', 'S_USER_ID' => $user->data['user_id'], - 'S_USER_LANG' => $user->lang['USER_LANG'], - 'S_CONTENT_DIRECTION' => $user->lang['DIRECTION'], + 'S_USER_LANG' => $user_lang, + 'S_CONTENT_DIRECTION' => $direction, 'S_CONTENT_ENCODING' => 'UTF-8', - 'S_CONTENT_FLOW_BEGIN' => ($user->lang['DIRECTION'] == 'ltr') ? 'left' : 'right', - 'S_CONTENT_FLOW_END' => ($user->lang['DIRECTION'] == 'ltr') ? 'right' : 'left', + 'S_CONTENT_FLOW_BEGIN' => ($direction == 'ltr') ? 'left' : 'right', + 'S_CONTENT_FLOW_END' => ($direction == 'ltr') ? 'right' : 'left', 'CONTAINER_EXCEPTION' => $phpbb_container->hasParameter('container_exception') ? $phpbb_container->getParameter('container_exception') : false, )); diff --git a/phpBB/phpbb/install/controller/helper.php b/phpBB/phpbb/install/controller/helper.php index 1f936dda86..15e3586f17 100644 --- a/phpBB/phpbb/install/controller/helper.php +++ b/phpBB/phpbb/install/controller/helper.php @@ -253,11 +253,19 @@ class helper */ protected function page_header($page_title, $selected_language = false) { + global $phpbb_container; + // Path to templates $paths = array($this->phpbb_root_path . 'install/update/new/adm/', $this->phpbb_admin_path); $paths = array_filter($paths, 'is_dir'); $path = array_shift($paths); $path = substr($path, strlen($this->phpbb_root_path)); + // Get the language helper + /* @var $language_helper \phpbb\language\language_file_helper */ + $language_file_helper = $phpbb_container->get('language.helper.language_file'); + + // Grab the users lang direction and store it for later use + $direction = $language_file_helper->get_lang_key_value('direction'); $this->template->assign_vars(array( 'L_CHANGE' => $this->language->lang('CHANGE'), @@ -271,13 +279,13 @@ class helper 'T_TEMPLATE_PATH' => $this->path_helper->get_web_root_path() . $path . 'style', 'T_ASSETS_PATH' => $this->path_helper->get_web_root_path() . $path . '../assets', - 'S_CONTENT_DIRECTION' => $this->language->lang('DIRECTION'), - 'S_CONTENT_FLOW_BEGIN' => ($this->language->lang('DIRECTION') === 'ltr') ? 'left' : 'right', - 'S_CONTENT_FLOW_END' => ($this->language->lang('DIRECTION') === 'ltr') ? 'right' : 'left', + 'S_CONTENT_DIRECTION' => $direction, + 'S_CONTENT_FLOW_BEGIN' => ($direction === 'ltr') ? 'left' : 'right', + 'S_CONTENT_FLOW_END' => ($direction === 'ltr') ? 'right' : 'left', 'S_CONTENT_ENCODING' => 'UTF-8', 'S_LANG_SELECT' => $selected_language, - 'S_USER_LANG' => $this->language->lang('USER_LANG'), + 'S_USER_LANG' => $language_file_helper->get_lang_key_value('user_lang'), )); $this->render_navigation(); diff --git a/phpBB/phpbb/language/language.php b/phpBB/phpbb/language/language.php index d9f0721769..8f1eedb6ac 100644 --- a/phpBB/phpbb/language/language.php +++ b/phpBB/phpbb/language/language.php @@ -404,8 +404,16 @@ 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'); + + // Grab the users lang plural rule + $plural_rule_content = $language_file_helper->get_lang_key_value('plural_rule'); + $number = (int) $number; - $plural_rule = ($force_rule !== false) ? $force_rule : ((isset($this->lang['PLURAL_RULE'])) ? $this->lang['PLURAL_RULE'] : 1); + $plural_rule = ($force_rule !== false) ? $force_rule : ((isset($plural_rule_content)) ? $plural_rule_content : 1); /** * The following plural rules are based on a list published by the Mozilla Developer Network