Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/zabbix/zabbix.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'ui/include/classes/core/ZBase.php')
-rw-r--r--ui/include/classes/core/ZBase.php53
1 files changed, 9 insertions, 44 deletions
diff --git a/ui/include/classes/core/ZBase.php b/ui/include/classes/core/ZBase.php
index 08cda05787d..d689f965874 100644
--- a/ui/include/classes/core/ZBase.php
+++ b/ui/include/classes/core/ZBase.php
@@ -184,13 +184,8 @@ class ZBase {
$this->loadConfigFile();
$this->initDB();
$this->setServerAddress();
- $this->initLocales(CSettingsHelper::getGlobal(CSettingsHelper::DEFAULT_LANG));
$this->authenticateUser();
- if (CWebUser::$data['lang'] !== CSettingsHelper::get(CSettingsHelper::DEFAULT_LANG)) {
- $this->initLocales(CWebUser::$data['lang']);
- }
-
$this->initMessages();
$this->setLayoutModeByUrl();
$this->initComponents();
@@ -228,7 +223,6 @@ class ZBase {
$this->loadConfigFile();
$this->initDB();
$this->authenticateUser();
- $this->initLocales(CWebUser::$data['lang']);
$this->initComponents();
}
catch (ConfigFileException $e) {
@@ -419,47 +413,16 @@ class ZBase {
}
/**
- * Initialize translations.
+ * Initialize translations, set up translated date and time constants.
*
- * @param string $lang Language.
+ * @param string $lang Locale variant prefix like en_US, ru_RU etc.
*/
- public function initLocales(string $lang): void {
- init_mbstrings();
-
- $default_locales = ['C', 'POSIX', 'en', 'en_US', 'en_US.UTF-8', 'English_United States.1252'];
-
- if (function_exists('bindtextdomain')) {
- // initializing gettext translations depending on language selected by user
- $locales = zbx_locale_variants($lang);
- $locale_found = false;
- foreach ($locales as $locale) {
- // since LC_MESSAGES may be unavailable on some systems, try to set all of the locales
- // and then revert some of them back
- putenv('LC_ALL='.$locale);
- putenv('LANG='.$locale);
- putenv('LANGUAGE='.$locale);
- setlocale(LC_TIME, $locale);
-
- if (setlocale(LC_ALL, $locale)) {
- $locale_found = true;
- break;
- }
- }
-
- if (!$locale_found && strtolower($lang) !== strtolower(ZBX_DEFAULT_LANG)) {
- setlocale(LC_ALL, $default_locales);
- error('Locale for language "'.$lang.'" is not found on the web server. Tried to set: '.implode(', ', $locales).'. Unable to translate Zabbix interface.');
- }
- bindtextdomain('frontend', 'locale');
- bind_textdomain_codeset('frontend', 'UTF-8');
- textdomain('frontend');
+ public function initLocales(string $language): void {
+ if (!setupLocale($language, $error) && $error !== '') {
+ error($error);
}
- // reset the LC_NUMERIC locale so that PHP would always use a point instead of a comma for decimal numbers
- setlocale(LC_NUMERIC, $default_locales);
-
- // should be after locale initialization
- require_once 'include/translateDefines.inc.php';
+ require_once $this->getRootDir().'/include/translateDefines.inc.php';
}
/**
@@ -491,7 +454,7 @@ class ZBase {
}
/**
- * Authenticate user.
+ * Authenticate user, apply some user-specific settings.
*
* @throws Exception
*/
@@ -502,6 +465,8 @@ class ZBase {
CWebUser::setDefault();
}
+ $this->initLocales(CWebUser::$data['lang']);
+
if (!$session->session_start(CWebUser::$data['sessionid'])) {
throw new Exception(_('Session initialization error.'));
}