From 9ddaba0b4cfd66caf6cc3eb0488460572034bd1f Mon Sep 17 00:00:00 2001 From: Dmitriy Simushev Date: Thu, 5 Jun 2014 08:08:22 +0000 Subject: [PATCH] Replace "getlocal_" function with "getlocal" --- src/mibew/install/index.php | 2 +- .../Controller/CannedMessageController.php | 2 +- .../Controller/TranslationController.php | 2 +- src/mibew/libs/classes/Mibew/Thread.php | 17 ++++++---- src/mibew/libs/common/locale.php | 34 +++---------------- src/mibew/libs/invitation.php | 2 +- 6 files changed, 18 insertions(+), 41 deletions(-) diff --git a/src/mibew/install/index.php b/src/mibew/install/index.php index 75051396..8957fa02 100644 --- a/src/mibew/install/index.php +++ b/src/mibew/install/index.php @@ -310,7 +310,7 @@ function add_canned_messages($link){ $result = array(); foreach (get_available_locales() as $locale) { if (! in_array($locale, $existlocales)) { - foreach (explode("\n", getlocal_('chat.predefined_answers', $locale)) as $answer) { + foreach (explode("\n", getlocal('chat.predefined_answers', null, $locale)) as $answer) { $result[] = array('locale' => $locale, 'vctitle' => cut_string($answer, 97, '...'), 'vcvalue' => $answer); } } diff --git a/src/mibew/libs/classes/Mibew/Controller/CannedMessageController.php b/src/mibew/libs/classes/Mibew/Controller/CannedMessageController.php index 8cca6af7..9395d3a9 100644 --- a/src/mibew/libs/classes/Mibew/Controller/CannedMessageController.php +++ b/src/mibew/libs/classes/Mibew/Controller/CannedMessageController.php @@ -46,7 +46,7 @@ class CannedMessageController extends AbstractController foreach ($all_locales as $id) { $locales_with_label[] = array( 'id' => $id, - 'name' => getlocal_($id, 'names') + 'name' => getlocal($id, null, 'names') ); } $page['locales'] = $locales_with_label; diff --git a/src/mibew/libs/classes/Mibew/Controller/TranslationController.php b/src/mibew/libs/classes/Mibew/Controller/TranslationController.php index d78c640d..32e70a5c 100644 --- a/src/mibew/libs/classes/Mibew/Controller/TranslationController.php +++ b/src/mibew/libs/classes/Mibew/Controller/TranslationController.php @@ -59,7 +59,7 @@ class TranslationController extends AbstractController $locales_list = array(); $all_locales = get_available_locales(); foreach ($all_locales as $loc) { - $locales_list[] = array("id" => $loc, "name" => getlocal_("localeid", $loc)); + $locales_list[] = array('id' => $loc, 'name' => getlocal('localeid', null, $loc)); } // Extract needed localization constants. diff --git a/src/mibew/libs/classes/Mibew/Thread.php b/src/mibew/libs/classes/Mibew/Thread.php index 85b66286..8404e44b 100644 --- a/src/mibew/libs/classes/Mibew/Thread.php +++ b/src/mibew/libs/classes/Mibew/Thread.php @@ -364,7 +364,7 @@ class Thread // Send message $thread->postMessage( self::KIND_EVENTS, - getlocal_("chat.status.user.reopenedthread", $thread->locale, true) + getlocal('chat.status.user.reopenedthread', null, $thread->locale, true) ); return $thread; @@ -600,8 +600,9 @@ class Thread // Check if user chatting at the moment if ($this->state == self::STATE_CHATTING) { // Send message to user - $message_to_post = getlocal_( - "chat.status.operator.dead", + $message_to_post = getlocal( + 'chat.status.operator.dead', + null, $this->locale, true ); @@ -625,8 +626,9 @@ class Thread $this->lastPingUser = 0; // And send a message to operator - $message_to_post = getlocal_( - "chat.status.user.dead", + $message_to_post = getlocal( + 'chat.status.user.dead', + null, $this->locale, true ); @@ -865,8 +867,9 @@ class Thread if ($this->state == self::STATE_INVITED) { $this->postMessage( self::KIND_FOR_AGENT, - getlocal_( - "chat.visitor.invitation.canceled", + getlocal( + 'chat.visitor.invitation.canceled', + null, $this->locale, true ) diff --git a/src/mibew/libs/common/locale.php b/src/mibew/libs/common/locale.php index a9c4066d..1863e314 100644 --- a/src/mibew/libs/common/locale.php +++ b/src/mibew/libs/common/locale.php @@ -141,7 +141,7 @@ function get_locale_links() return null; } foreach ($all_locales as $k) { - $locale_links[$k] = getlocal_($k, "names"); + $locale_links[$k] = getlocal($k, null, 'names'); } return $locale_links; @@ -278,46 +278,20 @@ function get_localized_string($string, $locale) return "!" . $string; } -function getlocal_($text, $locale, $raw = false) -{ - $localized = load_messages($locale); - if (isset($localized[$text])) { - return $raw - ? $localized[$text] - : sanitize_string($localized[$text], 'low', 'moderate'); - } - if ($locale != 'en') { - return getlocal_($text, 'en', $raw); - } - - return "!" . ($raw ? $text : sanitize_string($text, 'low', 'moderate')); -} - function getlocal2_($text, $params, $locale, $raw = false) { - $string = getlocal_($text, $locale, true); - for ($i = 0; $i < count($params); $i++) { - $string = str_replace("{" . $i . "}", $params[$i], $string); - } - - return $raw ? $string : sanitize_string($string, 'low', 'moderate'); + return getlocal($text, $params, $locale, $raw); } function getlocal2($text, $params, $raw = false) { - $string = getlocal_($text, CURRENT_LOCALE, true); - - for ($i = 0; $i < count($params); $i++) { - $string = str_replace("{" . $i . "}", $params[$i], $string); - } - - return $raw ? $string : sanitize_string($string, 'low', 'moderate'); + return getlocal($text, $params, CURRENT_LOCALE, $raw); } /* prepares for Javascript string */ function get_local_for_js($text, $params) { - $string = getlocal_($text, CURRENT_LOCALE); + $string = get_localized_string($text, CURRENT_LOCALE); $string = str_replace("\"", "\\\"", str_replace("\n", "\\n", $string)); for ($i = 0; $i < count($params); $i++) { $string = str_replace("{" . $i . "}", $params[$i], $string); diff --git a/src/mibew/libs/invitation.php b/src/mibew/libs/invitation.php index f58b6a52..53fc612f 100644 --- a/src/mibew/libs/invitation.php +++ b/src/mibew/libs/invitation.php @@ -271,7 +271,7 @@ function invitation_close_old() $thread = Thread::createFromDbInfo($thread_info); $thread->postMessage( Thread::KIND_FOR_AGENT, - getlocal_('chat.visitor.invitation.ignored', $thread->locale, true) + getlocal('chat.visitor.invitation.ignored', null, $thread->locale, true) ); unset($thread); }