Use SN.msg() and onEndScriptMessages() to export localized UI messages from Realtime plugin and its descendents.

This commit is contained in:
Brion Vibber 2010-11-02 13:12:58 -07:00
parent 5a9bb0adc4
commit 86201761ea
3 changed files with 28 additions and 27 deletions

View File

@ -311,10 +311,10 @@ class Action extends HTMLOutputter // lawsuit
$messages = array_merge($messages, $this->getScriptMessages()); $messages = array_merge($messages, $this->getScriptMessages());
} }
Event::handle('EndScriptMessages', array($this, &$messages));
if ($messages) { if ($messages) {
$this->inlineScript('SN.messages=' . json_encode($messages)); $this->inlineScript('SN.messages=' . json_encode($messages));
} }
Event::handle('EndScriptMessages', array($this, &$messages));
return $messages; return $messages;
} }

View File

@ -106,9 +106,7 @@ class RealtimePlugin extends Plugin
$realtimeUI = ' RealtimeUpdate.initActions("'.$url.'", "'.$timeline.'", "'. $pluginPath .'");'; $realtimeUI = ' RealtimeUpdate.initActions("'.$url.'", "'.$timeline.'", "'. $pluginPath .'");';
} }
$i18n = $this->_getMessages();
$script = ' $(document).ready(function() { '. $script = ' $(document).ready(function() { '.
'RealtimeUpdate._messages=' . json_encode($i18n) . ';' .
$realtimeUI. $realtimeUI.
$this->_updateInitialize($timeline, $user_id). $this->_updateInitialize($timeline, $user_id).
'}); '; '}); ';
@ -329,25 +327,29 @@ class RealtimePlugin extends Plugin
} }
/** /**
* Any i18n messages that need to be loaded at runtime. * Export any i18n messages that need to be loaded at runtime...
* @return array of string key to output text string pairs *
* @param Action $action
* @param array $messages
*
* @return boolean hook return value
*/ */
function _getMessages() function onEndScriptMessages($action, &$messages)
{ {
return array( // TRANS: Text label for realtime view "play" button, usually replaced by an icon.
// TRANS: Text label for realtime view "play" button, usually replaced by an icon. $messages['realtime_play'] = _m('BUTTON', 'Play');
'play' => _m('BUTTON', 'Play'), // TRANS: Tooltip for realtime view "play" button.
// TRANS: Tooltip for realtime view "play" button. $messages['realtime_play_tooltip'] = _m('TOOLTIP', 'Play');
'play_tooltip' => _m('TOOLTIP', 'Play'), // TRANS: Text label for realtime view "pause" button
// TRANS: Text label for realtime view "pause" button $messages['realtime_pause'] = _m('BUTTON', 'Pause');
'pause' => _m('BUTTON', 'Pause'), // TRANS: Tooltip for realtime view "pause" button
// TRANS: Tooltip for realtime view "pause" button $messages['realtime_pause_tooltip'] = _m('TOOLTIP', 'Pause');
'pause_tooltip' => _m('TOOLTIP', 'Pause'), // TRANS: Text label for realtime view "popup" button, usually replaced by an icon.
// TRANS: Text label for realtime view "popup" button, usually replaced by an icon. $messages['realtime_popup'] = _m('BUTTON', 'Pop up');
'popup' => _m('BUTTON', 'Pop up'), // TRANS: Tooltip for realtime view "popup" button.
// TRANS: Tooltip for realtime view "popup" button. $messages['realtime_popup_tooltip'] = _m('TOOLTIP', 'Pop up in a window');
'popup_tooltip' => _m('TOOLTIP', 'Pop up in a window'),
); return true;
} }
function _updateInitialize($timeline, $user_id) function _updateInitialize($timeline, $user_id)

View File

@ -40,7 +40,6 @@ RealtimeUpdate = {
_documenttitle: '', _documenttitle: '',
_paused:false, _paused:false,
_queuedNotices:[], _queuedNotices:[],
_messages:{},
init: function(userid, replyurl, favorurl, repeaturl, deleteurl) init: function(userid, replyurl, favorurl, repeaturl, deleteurl)
{ {
@ -263,8 +262,8 @@ RealtimeUpdate = {
$('#realtime_playpause').remove(); $('#realtime_playpause').remove();
$('#realtime_actions').prepend('<li id="realtime_playpause"><button id="realtime_pause" class="pause"></button></li>'); $('#realtime_actions').prepend('<li id="realtime_playpause"><button id="realtime_pause" class="pause"></button></li>');
$('#realtime_pause').text(RealtimeUpdate._messages['pause']) $('#realtime_pause').text(SN.msg('realtime_pause'))
.attr('title', RealtimeUpdate._messages['pause_tooltip']) .attr('title', SN.msg('realtime_pause_tooltip'))
.bind('click', function() { .bind('click', function() {
RealtimeUpdate.removeNoticesHover(); RealtimeUpdate.removeNoticesHover();
RealtimeUpdate.showPlay(); RealtimeUpdate.showPlay();
@ -277,8 +276,8 @@ RealtimeUpdate = {
RealtimeUpdate.setPause(true); RealtimeUpdate.setPause(true);
$('#realtime_playpause').remove(); $('#realtime_playpause').remove();
$('#realtime_actions').prepend('<li id="realtime_playpause"><span id="queued_counter"></span> <button id="realtime_play" class="play"></button></li>'); $('#realtime_actions').prepend('<li id="realtime_playpause"><span id="queued_counter"></span> <button id="realtime_play" class="play"></button></li>');
$('#realtime_play').text(RealtimeUpdate._messages['play']) $('#realtime_play').text(SN.msg('realtime_play'))
.attr('title', RealtimeUpdate._messages['play_tooltip']) .attr('title', SN.msg('realtime_play_tooltip'))
.bind('click', function() { .bind('click', function() {
RealtimeUpdate.showPause(); RealtimeUpdate.showPause();
return false; return false;
@ -338,8 +337,8 @@ RealtimeUpdate = {
initAddPopup: function(url, timeline, path) initAddPopup: function(url, timeline, path)
{ {
$('#realtime_timeline').append('<button id="realtime_popup"></button>'); $('#realtime_timeline').append('<button id="realtime_popup"></button>');
$('#realtime_popup').text(RealtimeUpdate._messages['popup']) $('#realtime_popup').text(SN.msg('realtime_popup'))
.attr('title', RealtimeUpdate._messages['popup_tooltip']) .attr('title', SN.msg('realtime_popup_tooltip'))
.bind('click', function() { .bind('click', function() {
window.open(url, window.open(url,
'', '',