r66062 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r66061‎ | r66062 | r66063 >
Date:12:25, 8 May 2010
Author:jeroendedauw
Status:deferred (Comments)
Tags:jsplural 
Comment:
Implemnted JS i18n functions
Modified paths:
  • /trunk/extensions/Storyboard/Storyboard.i18n.php (modified) (history)
  • /trunk/extensions/Storyboard/Storyboard.php (modified) (history)
  • /trunk/extensions/Storyboard/storyboard.js (modified) (history)
  • /trunk/extensions/Storyboard/tags/Storysubmission/Storysubmission_body.php (modified) (history)

Diff [purge]

Index: trunk/extensions/Storyboard/Storyboard.i18n.php
@@ -59,6 +59,9 @@
6060 'storyboard-alreadyexists' => '"$1" is already taken.',
6161 'storyboard-changetitle' => 'Change the title.',
6262 'storyboard-notsubmitted' => 'Authentication failed, no story has been saved.',
 63+ 'storyboard-charstomany' => '$1 characters to many!',
 64+ 'storyboard-morecharsneeded' => '$1 more characters needed',
 65+ 'storyboard-charactersleft' => '$1 characters left',
6366
6467 // Story review
6568 'storyreview' => 'Story review',
Index: trunk/extensions/Storyboard/tags/Storysubmission/Storysubmission_body.php
@@ -55,6 +55,8 @@
5656 $maxLen = array_key_exists( 'maxlength', $args ) && is_int( $args['maxlength'] ) ? $args['maxlength'] : $egStoryboardMaxStoryLen;
5757 $minLen = array_key_exists( 'minlength', $args ) && is_int( $args['minlength'] ) ? $args['minlength'] : $egStoryboardMinStoryLen;
5858
 59+ efStoryboardAddJSLocalisation( $parser );
 60+
5961 // Loading a seperate JS file would be overkill for just these 3 lines, and be bad for performance.
6062 $parser->getOutput()->addHeadItem(
6163 <<<EOT
Index: trunk/extensions/Storyboard/storyboard.js
@@ -8,6 +8,21 @@
99 */
1010
1111
 12+function stbMsg( key ) {
 13+ return wgStbMessages[key];
 14+}
 15+
 16+function stbMsgExt( key, values ) {
 17+ var message = stbMsg( key );
 18+
 19+ var n = values.length;
 20+ for ( var i = 0; i < n; i++ ) {
 21+ message = message.replace( '$' + ( i + 1 ), values[i] );
 22+ }
 23+
 24+ return message;
 25+}
 26+
1227 /**
1328 * Story submission/editting functions
1429 */
@@ -41,14 +56,14 @@
4257 var textlength = text.length;
4358 var info = document.getElementById( infodiv );
4459
45 - if(textlength > upperLimit) {
46 - info.innerHTML = -( upperLimit - textlength ) + ' characters to many!'; // TODO: i18n
 60+ if( textlength > upperLimit ) {
 61+ info.innerHTML = stbMsgExt( 'storyboard-charstomany', [-( upperLimit - textlength )] );
4762 return false;
48 - } else if (textlength < lowerLimit) {
49 - info.innerHTML = '('+ ( lowerLimit - textlength ) + ' more characters needed)'; // TODO: i18n
 63+ } else if ( textlength < lowerLimit ) {
 64+ info.innerHTML = stbMsgExt( 'storyboard-morecharsneeded', [lowerLimit - textlength] );
5065 return false;
5166 } else {
52 - info.innerHTML = '(' + ( upperLimit - textlength ) + ' characters left)'; // TODO: i18n
 67+ info.innerHTML = stbMsgExt( 'storyboard-charactersleft', [upperLimit - textlength] );
5368 return true;
5469 }
5570 }
Index: trunk/extensions/Storyboard/Storyboard.php
@@ -132,3 +132,27 @@
133133 return true;
134134 }
135135
 136+function efStoryboardAddJSLocalisation( $parser = false ) {
 137+ wfLoadExtensionMessages( 'Storyboard' );
 138+
 139+ $messages = array(
 140+ 'storyboard-charstomany',
 141+ 'storyboard-morecharsneeded',
 142+ 'storyboard-charactersleft'
 143+ );
 144+
 145+ $data = array();
 146+
 147+ foreach ( $messages as $msg ) {
 148+ $data[$msg] = wfMsgNoTrans( $msg );
 149+ }
 150+
 151+ $js = 'var wgStbMessages = ' . json_encode( $data ) . ';';
 152+
 153+ if ( $parser ) {
 154+ $parser->getOutput()->addHeadItem( Html::inlineScript( $js ) );
 155+ } else {
 156+ global $wgOut;
 157+ $wgOut->addInlineScript( $js );
 158+ }
 159+}
\ No newline at end of file

Follow-up revisions

RevisionCommit summaryAuthorDate
r66063Follow up to r66062jeroendedauw12:57, 8 May 2010
r66065Follow up to r66062jeroendedauw13:29, 8 May 2010
r66067Follow up to r66062jeroendedauw13:36, 8 May 2010
r66070Follow up to r66062jeroendedauw14:06, 8 May 2010

Comments

#Comment by Siebrand (talk | contribs)   13:12, 8 May 2010

New messages need plural support.

+ 'storyboard-charstomany' => '$1 characters to many!', + 'storyboard-morecharsneeded' => '$1 more characters needed', + 'storyboard-charactersleft' => '$1 characters left',

Also a typo: "to many" -> "too many"

#Comment by Jeroen De Dauw (talk | contribs)   13:19, 8 May 2010

Any suggestion how to support plural stuff in JS? If not, I first have to look at how to do this, which I'll do after implementing i18n support, which is now completely lacking.

#Comment by Siebrand (talk | contribs)   20:22, 8 May 2010

Suggest you speak with Michael Dale.

#Comment by Nikerabbit (talk | contribs)   09:50, 21 August 2011
#Comment by Jeroen De Dauw (talk | contribs)   14:43, 21 August 2011

Well sure, but dev of this extension has been dropped for some reason, so that won't be of much help here.

#Comment by Nikerabbit (talk | contribs)   15:40, 21 August 2011

What do you mean has been dropped? There was just a post on wikitech about it.

#Comment by Jeroen De Dauw (talk | contribs)   15:51, 21 August 2011

I created this extension about a year and a half ago and got it to 80%, maybe 90% completeness, after which nothing was done with it, and it has remained in this non-finished state ever since. No idea why this happened, I never got told.

> There was just a post on wikitech about it.

Link?

#Comment by Nikerabbit (talk | contribs)   16:02, 21 August 2011

Oh, you were talking about this extension, not the one I linked?

#Comment by Jeroen De Dauw (talk | contribs)   16:17, 21 August 2011

Yeah, I guess my message was a bit unclear on that :)

#Comment by Nikerabbit (talk | contribs)   09:52, 21 August 2011
  • json_encode -> FormatJson::encode
  • wfLoadExtensionMessages ?
#Comment by Jeroen De Dauw (talk | contribs)   14:44, 21 August 2011

Yeah, this code needs updating. It's also not using the RL.

Status & tagging log