Improve uppercase/lowercase/ucfirst attrib handling in rcube::gettext()

- Make ucfirst mode compatible with UTF-8
- Fix bug which made uppercase=FIRST non-working
- Replace \n with real line-break before converting char case
pull/5514/head
Aleksander Machniak 8 years ago
parent 322f443d17
commit 68221ed4ae

@ -599,7 +599,7 @@ class rcube
*
* @return string Localized text
*/
public function gettext($attrib, $domain=null)
public function gettext($attrib, $domain = null)
{
// load localization files if not done yet
if (empty($this->texts)) {
@ -633,18 +633,25 @@ class rcube
}
}
// format output
if (($attrib['uppercase'] && strtolower($attrib['uppercase'] == 'first')) || $attrib['ucfirst']) {
return ucfirst($text);
// replace \n with real line break
$text = strtr($text, array('\n' => "\n"));
// case folding
if (($attrib['uppercase'] && strtolower($attrib['uppercase']) == 'first') || $attrib['ucfirst']) {
$case_mode = MB_CASE_TITLE;
}
else if ($attrib['uppercase']) {
return mb_strtoupper($text);
$case_mode = MB_CASE_UPPER;
}
else if ($attrib['lowercase']) {
return mb_strtolower($text);
$case_mode = MB_CASE_LOWER;
}
if (isset($case_mode)) {
$text = mb_convert_case($text, $case_mode);
}
return strtr($text, array('\n' => "\n"));
return $text;
}
/**

Loading…
Cancel
Save