Replace "getlocal_" function with "getlocal"

This commit is contained in:
Dmitriy Simushev 2014-06-05 08:08:22 +00:00
parent 090166b780
commit 9ddaba0b4c
6 changed files with 18 additions and 41 deletions

View File

@ -310,7 +310,7 @@ function add_canned_messages($link){
$result = array(); $result = array();
foreach (get_available_locales() as $locale) { foreach (get_available_locales() as $locale) {
if (! in_array($locale, $existlocales)) { 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); $result[] = array('locale' => $locale, 'vctitle' => cut_string($answer, 97, '...'), 'vcvalue' => $answer);
} }
} }

View File

@ -46,7 +46,7 @@ class CannedMessageController extends AbstractController
foreach ($all_locales as $id) { foreach ($all_locales as $id) {
$locales_with_label[] = array( $locales_with_label[] = array(
'id' => $id, 'id' => $id,
'name' => getlocal_($id, 'names') 'name' => getlocal($id, null, 'names')
); );
} }
$page['locales'] = $locales_with_label; $page['locales'] = $locales_with_label;

View File

@ -59,7 +59,7 @@ class TranslationController extends AbstractController
$locales_list = array(); $locales_list = array();
$all_locales = get_available_locales(); $all_locales = get_available_locales();
foreach ($all_locales as $loc) { 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. // Extract needed localization constants.

View File

@ -364,7 +364,7 @@ class Thread
// Send message // Send message
$thread->postMessage( $thread->postMessage(
self::KIND_EVENTS, self::KIND_EVENTS,
getlocal_("chat.status.user.reopenedthread", $thread->locale, true) getlocal('chat.status.user.reopenedthread', null, $thread->locale, true)
); );
return $thread; return $thread;
@ -600,8 +600,9 @@ class Thread
// Check if user chatting at the moment // Check if user chatting at the moment
if ($this->state == self::STATE_CHATTING) { if ($this->state == self::STATE_CHATTING) {
// Send message to user // Send message to user
$message_to_post = getlocal_( $message_to_post = getlocal(
"chat.status.operator.dead", 'chat.status.operator.dead',
null,
$this->locale, $this->locale,
true true
); );
@ -625,8 +626,9 @@ class Thread
$this->lastPingUser = 0; $this->lastPingUser = 0;
// And send a message to operator // And send a message to operator
$message_to_post = getlocal_( $message_to_post = getlocal(
"chat.status.user.dead", 'chat.status.user.dead',
null,
$this->locale, $this->locale,
true true
); );
@ -865,8 +867,9 @@ class Thread
if ($this->state == self::STATE_INVITED) { if ($this->state == self::STATE_INVITED) {
$this->postMessage( $this->postMessage(
self::KIND_FOR_AGENT, self::KIND_FOR_AGENT,
getlocal_( getlocal(
"chat.visitor.invitation.canceled", 'chat.visitor.invitation.canceled',
null,
$this->locale, $this->locale,
true true
) )

View File

@ -141,7 +141,7 @@ function get_locale_links()
return null; return null;
} }
foreach ($all_locales as $k) { foreach ($all_locales as $k) {
$locale_links[$k] = getlocal_($k, "names"); $locale_links[$k] = getlocal($k, null, 'names');
} }
return $locale_links; return $locale_links;
@ -278,46 +278,20 @@ function get_localized_string($string, $locale)
return "!" . $string; 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) function getlocal2_($text, $params, $locale, $raw = false)
{ {
$string = getlocal_($text, $locale, true); return getlocal($text, $params, $locale, $raw);
for ($i = 0; $i < count($params); $i++) {
$string = str_replace("{" . $i . "}", $params[$i], $string);
}
return $raw ? $string : sanitize_string($string, 'low', 'moderate');
} }
function getlocal2($text, $params, $raw = false) function getlocal2($text, $params, $raw = false)
{ {
$string = getlocal_($text, CURRENT_LOCALE, true); return getlocal($text, $params, CURRENT_LOCALE, $raw);
for ($i = 0; $i < count($params); $i++) {
$string = str_replace("{" . $i . "}", $params[$i], $string);
}
return $raw ? $string : sanitize_string($string, 'low', 'moderate');
} }
/* prepares for Javascript string */ /* prepares for Javascript string */
function get_local_for_js($text, $params) 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)); $string = str_replace("\"", "\\\"", str_replace("\n", "\\n", $string));
for ($i = 0; $i < count($params); $i++) { for ($i = 0; $i < count($params); $i++) {
$string = str_replace("{" . $i . "}", $params[$i], $string); $string = str_replace("{" . $i . "}", $params[$i], $string);

View File

@ -271,7 +271,7 @@ function invitation_close_old()
$thread = Thread::createFromDbInfo($thread_info); $thread = Thread::createFromDbInfo($thread_info);
$thread->postMessage( $thread->postMessage(
Thread::KIND_FOR_AGENT, Thread::KIND_FOR_AGENT,
getlocal_('chat.visitor.invitation.ignored', $thread->locale, true) getlocal('chat.visitor.invitation.ignored', null, $thread->locale, true)
); );
unset($thread); unset($thread);
} }