jenkins-bot has submitted this change and it was merged.

Change subject: Implement completion counter
......................................................................


Implement completion counter

Change-Id: Id5f1542c9a0e96ed78fef1a82efceb98a9c9f28d
---
M Resources.php
M TranslateSandbox.i18n.php
M resources/js/ext.translate.special.translationstash.js
M specials/SpecialTranslationStash.php
4 files changed, 39 insertions(+), 5 deletions(-)

Approvals:
  Santhosh: Looks good to me, approved
  jenkins-bot: Verified



diff --git a/Resources.php b/Resources.php
index 0fa6c6a..b202090 100644
--- a/Resources.php
+++ b/Resources.php
@@ -378,8 +378,10 @@
                'ext.translate.editor',
                'ext.translate.messagetable',
                'ext.translate.translationstashstorage',
+               'mediawiki.language',
        ),
        'messages' => array(
+               'translate-translationstash-translations',
                'translate-translationstash-skip-button-label',
        ),
 ) + $resourcePaths;
diff --git a/TranslateSandbox.i18n.php b/TranslateSandbox.i18n.php
index 72eade9..44a6b0e 100644
--- a/TranslateSandbox.i18n.php
+++ b/TranslateSandbox.i18n.php
@@ -36,6 +36,7 @@
        'translate-translationstash-welcome' => 'Welcome {{GENDER:$1|$1}}, you 
are a new translator',
        'translate-translationstash-welcome-note' => 'Become familiar with the 
translation tools by translating some randomly selected messages.',
        'translate-translationstash-initialtranslation' => 'Your initial 
translation',
+       'translate-translationstash-translations' => '$1 completed 
{{PLURAL:$1|translation|translations}}',
        'translate-translationstash-skip-button-label' => 'Try another',
 );
 
@@ -69,6 +70,8 @@
 * $1 - user name of the new translator',
        'translate-translationstash-welcome-note' => 'Title note for the 
[[Special:TranslationStash]].',
        'translate-translationstash-initialtranslation' => 'Header for messages 
showing the progress of translations in [[Special:TranslationStash]].',
+       'translate-translationstash-translations' => 'Header for messages 
showing the progress of translations in [[Special:TranslationStash]]. Params:
+* $1 - the number of translations user has completed in the stash',
        'translate-translationstash-skip-button-label' => 'Label for the skip 
button in translation editor.
 {{Identical|Try another}}',
 );
diff --git a/resources/js/ext.translate.special.translationstash.js 
b/resources/js/ext.translate.special.translationstash.js
index a6e91ae..d1a2c50 100644
--- a/resources/js/ext.translate.special.translationstash.js
+++ b/resources/js/ext.translate.special.translationstash.js
@@ -94,6 +94,7 @@
                $messageWrapper.translateeditor( {
                        message: message,
                        storage: translationStashStorage,
+                       onSave: updateStats,
                        onReady: function () {
                                this.$editor.find( '.tux-editor-skip-button' )
                                        .text( mw.msg( 
'translate-translationstash-skip-button-label' ) );
@@ -101,6 +102,22 @@
                } );
        }
 
+       /**
+        * Updates the translation count at the top of the message list
+        * Relies on classes stash-stats and tux-status-translated.
+        */
+       function updateStats() {
+               var count,
+                       $target = $( '.stash-stats' );
+
+               count = $( '.tux-status-translated' ).length;
+
+               $target.text( mw.msg(
+                       'translate-translationstash-translations',
+                       mw.language.convertNumber( count )
+               ) );
+       }
+
        function loadMessages() {
                var $messageTable = $( '.tux-messagelist' ),
                        messagegroup = '!sandbox';
diff --git a/specials/SpecialTranslationStash.php 
b/specials/SpecialTranslationStash.php
index 5ebcac5..9389d8e 100644
--- a/specials/SpecialTranslationStash.php
+++ b/specials/SpecialTranslationStash.php
@@ -13,6 +13,9 @@
  * @ingroup SpecialPage TranslateSpecialPage
  */
 class SpecialTranslationStash extends SpecialPage {
+       ///< @param TranslationStashStorage
+       protected $stash;
+
        function __construct() {
                parent::__construct( 'TranslationStash' );
        }
@@ -20,6 +23,8 @@
        public function execute( $params ) {
                $this->setHeaders();
                $out = $this->getOutput();
+
+               $this->stash = new TranslationStashStorage( wfGetDB( DB_MASTER 
) );
 
                if ( !$this->hasPermissionToUse() ) {
                        $out->redirect( Title::newMainPage()->getLocalUrl() );
@@ -50,8 +55,7 @@
                                return true;
                        } elseif ( $request->getVal( 'integrationtesting' ) === 
'deactivatestash' ) {
                                $user->removeGroup( 'translate-sandboxed' );
-                               $stash = new TranslationStashStorage( wfGetDB( 
DB_MASTER ) );
-                               $stash->deleteTranslations( $user );
+                               $this->stash->deleteTranslations( $user );
 
                                return false;
                        }
@@ -69,16 +73,24 @@
         */
        protected function showPage() {
                // Easier to do this way than in JS
+               // @todo, but move to JS once it is easier there
                $token = Html::hidden( 'token', 
ApiTranslationStash::getToken(), array( 'id' => 'token' ) );
                $out = $this->getOutput();
+               $user = $this->getUser();
 
-               $name = $this->getUser()->getName();
+               $count = count( $this->stash->getTranslations( $user ) );
+               if ( $count === 0 ) {
+                       $progress = $this->msg( 
'translate-translationstash-initialtranslation' )->parse();
+               } else {
+                       $progress = $this->msg( 
'translate-translationstash-translations' )
+                               ->numParams( $count )->parse();
+               }
 
                $out->addHtml( <<<HTML
 <div class="grid">
        <div class="row translate-welcome-header">
                <h1>
-                       {$this->msg( 'translate-translationstash-welcome', 
$name )->parse()}
+                       {$this->msg( 'translate-translationstash-welcome', 
$user->getName() )->parse()}
                </h1>
                <p>
                        {$this->msg( 'translate-translationstash-welcome-note' 
)->parse()}
@@ -86,7 +98,7 @@
        </div>
        <div class="row translate-stash-control">
                <div class="six columns stash-stats">
-                       {$this->msg( 
'translate-translationstash-initialtranslation' )->parse()}
+                       {$progress}
                </div>
                <div class="six columns ext-translate-language-selector right">
                        {$this->tuxLanguageSelector()}

-- 
To view, visit https://gerrit.wikimedia.org/r/90089
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: merged
Gerrit-Change-Id: Id5f1542c9a0e96ed78fef1a82efceb98a9c9f28d
Gerrit-PatchSet: 2
Gerrit-Project: mediawiki/extensions/Translate
Gerrit-Branch: master
Gerrit-Owner: Nikerabbit <[email protected]>
Gerrit-Reviewer: Santhosh <[email protected]>
Gerrit-Reviewer: jenkins-bot

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to