Create "get_locale_info" function to improve code readability

This commit is contained in:
Dmitriy Simushev 2014-06-17 14:27:52 +00:00
parent 56357c4d40
commit 47880fa951
3 changed files with 22 additions and 6 deletions

View File

@ -84,9 +84,8 @@ class ChatStyle extends AbstractStyle implements StyleInterface
$data['mibewVersion'] = MIBEW_VERSION;
$data['currentLocale'] = CURRENT_LOCALE;
$locales = get_locales();
$data['rtl'] = isset($locales[CURRENT_LOCALE])
&& $locales[CURRENT_LOCALE]['rtl'];
$locale_info = get_locale_info(CURRENT_LOCALE);
$data['rtl'] = $locale_info && $locale_info['rtl'];
$data['stylePath'] = MIBEW_WEB_ROOT . '/' . $this->getFilesPath();
$data['styleName'] = $this->getName();

View File

@ -84,9 +84,8 @@ class PageStyle extends AbstractStyle implements StyleInterface
$data['mibewVersion'] = MIBEW_VERSION;
$data['currentLocale'] = CURRENT_LOCALE;
$locales = get_locales();
$data['rtl'] = isset($locales[CURRENT_LOCALE])
&& $locales[CURRENT_LOCALE]['rtl'];
$locale_info = get_locale_info(CURRENT_LOCALE);
$data['rtl'] = $locale_info && $locale_info['rtl'];
$data['stylePath'] = MIBEW_WEB_ROOT . '/' . $this->getFilesPath();
$data['styleName'] = $this->getName();

View File

@ -360,6 +360,24 @@ function get_locales()
);
}
/**
* Returns locale info by its code.
*
* It is a wrapper for {@link get_locales()} function and can be used to improve
* readability of the code.
*
* @param string $locale
* @return array|false Associative array of locale info or boolean false if the
* locale is unknown. See {@link get_locales()} description for details of the
* info array keys.
*/
function get_locale_info($locale)
{
$locales = get_locales();
return isset($locales[$locale]) ? $locales[$locale] : false;
}
/**
* Load localized messages id some service locale info.
*