Replace HOME_LOCALE const with get_home_locale() func

This commit is contained in:
Dmitriy Simushev 2014-07-11 14:47:41 +00:00
parent cca081b5c7
commit a63215f299
8 changed files with 41 additions and 23 deletions

View File

@ -148,7 +148,7 @@ class CommonController extends AbstractController
$params['left_messages_locale'] = $request->request->get('leftmessageslocale'); $params['left_messages_locale'] = $request->request->get('leftmessageslocale');
if (!in_array($params['left_messages_locale'], get_available_locales())) { if (!in_array($params['left_messages_locale'], get_available_locales())) {
$params['left_messages_locale'] = HOME_LOCALE; $params['left_messages_locale'] = get_home_locale();
} }
if ($params['email'] && !is_valid_email($params['email'])) { if ($params['email'] && !is_valid_email($params['email'])) {

View File

@ -108,7 +108,7 @@ class WidgetController extends AbstractController
// Get operator info // Get operator info
$operator = operator_by_id($thread->agentId); $operator = operator_by_id($thread->agentId);
$locale = $request->query->get('locale', ''); $locale = $request->query->get('locale', '');
$operator_name = ($locale == HOME_LOCALE) $operator_name = ($locale == get_home_locale())
? $operator['vclocalename'] ? $operator['vclocalename']
: $operator['vccommonname']; : $operator['vccommonname'];

View File

@ -597,7 +597,7 @@ class ThreadProcessor extends ClientSideProcessor
// Get message locale // Get message locale
$message_locale = Settings::get('left_messages_locale'); $message_locale = Settings::get('left_messages_locale');
if (!locale_exists($message_locale)) { if (!locale_exists($message_locale)) {
$message_locale = HOME_LOCALE; $message_locale = get_home_locale();
} }
// Create thread // Create thread

View File

@ -81,7 +81,7 @@ class Settings
'max_connections_from_one_host' => 10, 'max_connections_from_one_host' => 10,
'thread_lifetime' => 600, 'thread_lifetime' => 600,
'email' => '', /* inbox for left messages */ 'email' => '', /* inbox for left messages */
'left_messages_locale' => HOME_LOCALE, 'left_messages_locale' => get_home_locale(),
'sendmessagekey' => 'center', 'sendmessagekey' => 'center',
'enableban' => '0', 'enableban' => '0',
'enablessl' => '0', 'enablessl' => '0',

View File

@ -698,7 +698,7 @@ class Thread
*/ */
public function checkForReassign($operator) public function checkForReassign($operator)
{ {
$operator_name = ($this->locale == HOME_LOCALE) $operator_name = ($this->locale == get_home_locale())
? $operator['vclocalename'] ? $operator['vclocalename']
: $operator['vccommonname']; : $operator['vccommonname'];
@ -922,7 +922,7 @@ class Thread
{ {
$take_thread = false; $take_thread = false;
$message = ''; $message = '';
$operator_name = ($this->locale == HOME_LOCALE) $operator_name = ($this->locale == get_home_locale())
? $operator['vclocalename'] ? $operator['vclocalename']
: $operator['vccommonname']; : $operator['vccommonname'];

View File

@ -23,19 +23,6 @@ use Symfony\Component\Translation\Loader\PoFileLoader;
*/ */
define('LOCALE_COOKIE_NAME', 'mibew_locale'); define('LOCALE_COOKIE_NAME', 'mibew_locale');
// Test and set default locales
/**
* Verified value of the $home_locale configuration parameter (see
* "configs/default_config.yml" for details)
*/
define(
'HOME_LOCALE',
(locale_pattern_check($configs['home_locale']) && locale_exists($configs['home_locale'])
? $configs['home_locale']
: 'en')
);
function locale_exists($locale) function locale_exists($locale)
{ {
return file_exists(MIBEW_FS_ROOT . "/locales/$locale/translation.po"); return file_exists(MIBEW_FS_ROOT . "/locales/$locale/translation.po");
@ -136,7 +123,8 @@ function get_user_locale()
/** /**
* Returns a value of the default locale. * Returns a value of the default locale.
* *
* Generally it should be used if a user does not provide known lang. * Generally, the locale returned by the function, should be used as a user
* locale if does not provide known lang.
* *
* In fact the function returns verified value of "default_locale" variable from * In fact the function returns verified value of "default_locale" variable from
* the system configurations file. * the system configurations file.
@ -159,6 +147,33 @@ function get_default_locale()
return $default_locale; return $default_locale;
} }
/**
* Returns a value of the home locale.
*
* Generally, the locale returned by the function, should be used as a locale
* for operators' native names.
*
* In fact the function returns verified value of "home_locale" variable from
* the system configurations file.
*
* @return string Locale code.
*/
function get_home_locale()
{
static $home_locale = null;
if (is_null($home_locale)) {
$configs = load_system_configs();
$is_correct = !empty($configs['home_locale'])
&& locale_pattern_check($configs['home_locale'])
&& locale_exists($configs['home_locale']);
$home_locale = $is_correct ? $configs['home_locale'] : 'en';
}
return $home_locale;
}
/** /**
* Retrieves locale for the current request. * Retrieves locale for the current request.
* *

View File

@ -72,7 +72,10 @@ function group_by_name($name)
*/ */
function get_group_name($group) function get_group_name($group)
{ {
if (HOME_LOCALE == get_current_locale() || !isset($group['vccommonname']) || !$group['vccommonname']) { $use_local_name = (get_home_locale() == get_current_locale())
|| !isset($group['vccommonname'])
|| !$group['vccommonname'];
if ($use_local_name) {
return $group['vclocalname']; return $group['vclocalname'];
} else { } else {
return $group['vccommonname']; return $group['vccommonname'];
@ -242,7 +245,7 @@ function group_is_away($group)
*/ */
function get_group_description($group) function get_group_description($group)
{ {
$use_local_description = HOME_LOCALE == get_current_locale() $use_local_description = (get_home_locale() == get_current_locale())
|| !isset($group['vccommondescription']) || !isset($group['vccommondescription'])
|| !$group['vccommondescription']; || !$group['vccommondescription'];

View File

@ -509,7 +509,7 @@ function is_operator_online($operator_id)
*/ */
function get_operator_name($operator) function get_operator_name($operator)
{ {
if (HOME_LOCALE == get_current_locale()) { if (get_home_locale() == get_current_locale()) {
return $operator['vclocalename']; return $operator['vclocalename'];
} else { } else {
return $operator['vccommonname']; return $operator['vccommonname'];