From 68221ed4aedc7899ad1eb661a76948fb33476fc1 Mon Sep 17 00:00:00 2001 From: Aleksander Machniak Date: Sat, 12 Nov 2016 12:20:39 +0100 Subject: [PATCH] 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 --- program/lib/Roundcube/rcube.php | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/program/lib/Roundcube/rcube.php b/program/lib/Roundcube/rcube.php index 9b8e6689c..833975cfe 100644 --- a/program/lib/Roundcube/rcube.php +++ b/program/lib/Roundcube/rcube.php @@ -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; } /**