summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--js/util.js11
-rw-r--r--lib/action.php49
-rw-r--r--plugins/OStatus/classes/Ostatus_profile.php3
-rw-r--r--plugins/Realtime/RealtimePlugin.php40
-rw-r--r--plugins/Realtime/realtimeupdate.js13
5 files changed, 88 insertions, 28 deletions
diff --git a/js/util.js b/js/util.js
index 1989e92c0..1be3f3053 100644
--- a/js/util.js
+++ b/js/util.js
@@ -56,6 +56,15 @@ var SN = { // StatusNet
NoticeDataGeoCookie: 'NoticeDataGeo',
NoticeDataGeoSelected: 'notice_data-geo_selected',
StatusNetInstance:'StatusNetInstance'
+ },
+ },
+
+ messages: {},
+ msg: function(key) {
+ if (typeof SN.messages[key] == "undefined") {
+ return '[' + key + ']';
+ } else {
+ return SN.messages[key];
}
},
@@ -416,7 +425,7 @@ var SN = { // StatusNet
});
return false;
- });
+ }).attr('title', SN.msg('showmore_tooltip'));
}
else {
$.fn.jOverlay.options = {
diff --git a/lib/action.php b/lib/action.php
index 01bb0f7e9..766cfca26 100644
--- a/lib/action.php
+++ b/lib/action.php
@@ -283,6 +283,7 @@ class Action extends HTMLOutputter // lawsuit
if (Event::handle('StartShowStatusNetScripts', array($this)) &&
Event::handle('StartShowLaconicaScripts', array($this))) {
$this->script('util.js');
+ $this->showScriptMessages();
// Frame-busting code to avoid clickjacking attacks.
$this->inlineScript('if (window.top !== window.self) { window.top.location.href = window.self.location.href; }');
Event::handle('EndShowStatusNetScripts', array($this));
@@ -293,6 +294,54 @@ class Action extends HTMLOutputter // lawsuit
}
/**
+ * Exports a map of localized text strings to JavaScript code.
+ *
+ * Plugins can add to what's exported by hooking the StartScriptMessages or EndScriptMessages
+ * events and appending to the array. Try to avoid adding strings that won't be used, as
+ * they'll be added to HTML output.
+ */
+ function showScriptMessages()
+ {
+ $messages = array();
+ if (Event::handle('StartScriptMessages', array($this, &$messages))) {
+ // Common messages needed for timeline views etc...
+
+ // TRANS: Localized tooltip for '...' expansion button on overlong remote messages.
+ $messages['showmore_tooltip'] = _m('TOOLTIP', 'Show more');
+
+ $messages = array_merge($messages, $this->getScriptMessages());
+ }
+ Event::handle('EndScriptMessages', array($this, &$messages));
+ if ($messages) {
+ $this->inlineScript('SN.messages=' . json_encode($messages));
+ }
+ return $messages;
+ }
+
+ /**
+ * If the action will need localizable text strings, export them here like so:
+ *
+ * return array('pool_deepend' => _('Deep end'),
+ * 'pool_shallow' => _('Shallow end'));
+ *
+ * The exported map will be available via SN.msg() to JS code:
+ *
+ * $('#pool').html('<div class="deepend"></div><div class="shallow"></div>');
+ * $('#pool .deepend').text(SN.msg('pool_deepend'));
+ * $('#pool .shallow').text(SN.msg('pool_shallow'));
+ *
+ * Exports a map of localized text strings to JavaScript code.
+ *
+ * Plugins can add to what's exported on any action by hooking the StartScriptMessages or
+ * EndScriptMessages events and appending to the array. Try to avoid adding strings that won't
+ * be used, as they'll be added to HTML output.
+ */
+ function getScriptMessages()
+ {
+ return array();
+ }
+
+ /**
* Show OpenSearch headers
*
* @return nothing
diff --git a/plugins/OStatus/classes/Ostatus_profile.php b/plugins/OStatus/classes/Ostatus_profile.php
index 03fcb71df..90bf671eb 100644
--- a/plugins/OStatus/classes/Ostatus_profile.php
+++ b/plugins/OStatus/classes/Ostatus_profile.php
@@ -588,7 +588,8 @@ class Ostatus_profile extends Memcached_DataObject
// We mark up the attachment link specially for the HTML output
// so we can fold-out the full version inline.
- // TRANS: Shown when a notice is longer than supported and/or when attachments are present.
+ // @fixme I18N this tooltip will be saved with the site's default language
+ // TRANS: Shown when a notice is longer than supported and/or when attachments are present. At runtime this will usually be replaced with localized text from StatusNet core messages.
$showMoreText = _m('Show more');
$attachUrl = common_local_url('attachment',
array('attachment' => $attachment->id));
diff --git a/plugins/Realtime/RealtimePlugin.php b/plugins/Realtime/RealtimePlugin.php
index 23e8fb4d9..99d1ff9c1 100644
--- a/plugins/Realtime/RealtimePlugin.php
+++ b/plugins/Realtime/RealtimePlugin.php
@@ -105,9 +105,7 @@ class RealtimePlugin extends Plugin
$realtimeUI = ' RealtimeUpdate.initActions("'.$url.'", "'.$timeline.'", "'. $pluginPath .'");';
}
- $i18n = $this->_getMessages();
$script = ' $(document).ready(function() { '.
- 'RealtimeUpdate._messages=' . json_encode($i18n) . ';' .
$realtimeUI.
$this->_updateInitialize($timeline, $user_id).
'}); ';
@@ -328,25 +326,29 @@ class RealtimePlugin extends Plugin
}
/**
- * Any i18n messages that need to be loaded at runtime.
- * @return array of string key to output text string pairs
+ * Export any i18n messages that need to be loaded at runtime...
+ *
+ * @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.
- 'play' => _m('BUTTON', 'Play'),
- // TRANS: Tooltip for realtime view "play" button.
- 'play_tooltip' => _m('TOOLTIP', 'Play'),
- // TRANS: Text label for realtime view "pause" button
- 'pause' => _m('BUTTON', 'Pause'),
- // TRANS: Tooltip for realtime view "pause" button
- 'pause_tooltip' => _m('TOOLTIP', 'Pause'),
- // TRANS: Text label for realtime view "popup" button, usually replaced by an icon.
- 'popup' => _m('BUTTON', 'Pop up'),
- // TRANS: Tooltip for realtime view "popup" button.
- 'popup_tooltip' => _m('TOOLTIP', 'Pop up in a window'),
- );
+ // TRANS: Text label for realtime view "play" button, usually replaced by an icon.
+ $messages['realtime_play'] = _m('BUTTON', 'Play');
+ // TRANS: Tooltip for realtime view "play" button.
+ $messages['realtime_play_tooltip'] = _m('TOOLTIP', 'Play');
+ // TRANS: Text label for realtime view "pause" button
+ $messages['realtime_pause'] = _m('BUTTON', 'Pause');
+ // TRANS: Tooltip for realtime view "pause" button
+ $messages['realtime_pause_tooltip'] = _m('TOOLTIP', 'Pause');
+ // TRANS: Text label for realtime view "popup" button, usually replaced by an icon.
+ $messages['realtime_popup'] = _m('BUTTON', 'Pop up');
+ // TRANS: Tooltip for realtime view "popup" button.
+ $messages['realtime_popup_tooltip'] = _m('TOOLTIP', 'Pop up in a window');
+
+ return true;
}
function _updateInitialize($timeline, $user_id)
diff --git a/plugins/Realtime/realtimeupdate.js b/plugins/Realtime/realtimeupdate.js
index f764ca738..f49cef95e 100644
--- a/plugins/Realtime/realtimeupdate.js
+++ b/plugins/Realtime/realtimeupdate.js
@@ -40,7 +40,6 @@ RealtimeUpdate = {
_documenttitle: '',
_paused:false,
_queuedNotices:[],
- _messages:{},
init: function(userid, replyurl, favorurl, repeaturl, deleteurl)
{
@@ -263,8 +262,8 @@ RealtimeUpdate = {
$('#realtime_playpause').remove();
$('#realtime_actions').prepend('<li id="realtime_playpause"><button id="realtime_pause" class="pause"></button></li>');
- $('#realtime_pause').text(RealtimeUpdate._messages['pause'])
- .attr('title', RealtimeUpdate._messages['pause_tooltip'])
+ $('#realtime_pause').text(SN.msg('realtime_pause'))
+ .attr('title', SN.msg('realtime_pause_tooltip'))
.bind('click', function() {
RealtimeUpdate.removeNoticesHover();
RealtimeUpdate.showPlay();
@@ -277,8 +276,8 @@ RealtimeUpdate = {
RealtimeUpdate.setPause(true);
$('#realtime_playpause').remove();
$('#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'])
- .attr('title', RealtimeUpdate._messages['play_tooltip'])
+ $('#realtime_play').text(SN.msg('realtime_play'))
+ .attr('title', SN.msg('realtime_play_tooltip'))
.bind('click', function() {
RealtimeUpdate.showPause();
return false;
@@ -338,8 +337,8 @@ RealtimeUpdate = {
initAddPopup: function(url, timeline, path)
{
$('#realtime_timeline').append('<button id="realtime_popup"></button>');
- $('#realtime_popup').text(RealtimeUpdate._messages['popup'])
- .attr('title', RealtimeUpdate._messages['popup_tooltip'])
+ $('#realtime_popup').text(SN.msg('realtime_popup'))
+ .attr('title', SN.msg('realtime_popup_tooltip'))
.bind('click', function() {
window.open(url,
'',