Replace DEFAULT_LOCALE const with get_default_locale() func

This commit is contained in:
Dmitriy Simushev 2014-07-11 14:36:37 +00:00
parent 803863571b
commit cca081b5c7
2 changed files with 27 additions and 16 deletions

View File

@ -25,17 +25,6 @@ define('LOCALE_COOKIE_NAME', 'mibew_locale');
// Test and set default locales
/**
* Verified value of the $default_locale configuration parameter (see
* "configs/default_config.yml" for details)
*/
define(
'DEFAULT_LOCALE',
(locale_pattern_check($configs['default_locale']) && locale_exists($configs['default_locale'])
? $configs['default_locale']
: 'en')
);
/**
* Verified value of the $home_locale configuration parameter (see
* "configs/default_config.yml" for details)
@ -141,11 +130,33 @@ function get_user_locale()
}
}
if (locale_pattern_check(DEFAULT_LOCALE) && locale_exists(DEFAULT_LOCALE)) {
return DEFAULT_LOCALE;
return get_default_locale();
}
/**
* Returns a value of the default locale.
*
* Generally it should be used if a user does not provide known lang.
*
* In fact the function returns verified value of "default_locale" variable from
* the system configurations file.
*
* @return string Locale code.
*/
function get_default_locale()
{
static $default_locale = null;
if (is_null($default_locale)) {
$configs = load_system_configs();
$is_correct = !empty($configs['default_locale'])
&& locale_pattern_check($configs['default_locale'])
&& locale_exists($configs['default_locale']);
$default_locale = $is_correct ? $configs['default_locale'] : 'en';
}
return 'en';
return $default_locale;
}
/**

View File

@ -86,12 +86,12 @@ function mail_template_load($name, $locale, $strict = false)
}
// There is no template in the database.
if ($locale == DEFAULT_LOCALE) {
if ($locale == get_default_locale()) {
// The template is still not found.
$template = false;
} else {
// Try to load the template for the default locale.
$template = mail_template_load($name, DEFAULT_LOCALE);
$template = mail_template_load($name, get_default_locale());
}
}