Santhosh has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/218821

Change subject: Congratulate translator on 10th, 100th translation milestones
......................................................................

Congratulate translator on 10th, 100th translation milestones

Uses echo notifications

Bug: T99071
Change-Id: I2b51986bba6904ac43f630f602fba7a27cda75a8
---
M ContentTranslation.hooks.php
M api/ApiContentTranslationPublish.php
M i18n/en.json
M i18n/qqq.json
M includes/Notification.php
5 files changed, 75 insertions(+), 7 deletions(-)


  git pull 
ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/ContentTranslation 
refs/changes/21/218821/1

diff --git a/ContentTranslation.hooks.php b/ContentTranslation.hooks.php
index 3dc12f7..1dff85f 100644
--- a/ContentTranslation.hooks.php
+++ b/ContentTranslation.hooks.php
@@ -253,6 +253,24 @@
                        'icon' => 'cx',
                );
 
+               $notifications['cx-tenth-translation'] = array(
+                       'category' => 'cx',
+                       'group' => 'positive',
+                       'formatter-class' => 'EchoBasicFormatter',
+                       'title-message' => 'cx-notification-tenth-translation',
+                       'email-subject-message' => 
'cx-notification-tenth-translation-email-subject',
+                       'icon' => 'cx',
+               );
+
+               $notifications['cx-hundredth-translation'] = array(
+                       'category' => 'cx',
+                       'group' => 'positive',
+                       'formatter-class' => 'EchoBasicFormatter',
+                       'title-message' => 
'cx-notification-hundredth-translation',
+                       'email-subject-message' => 
'cx-notification-hundredth-translation-email-subject',
+                       'icon' => 'cx',
+               );
+
                $icons['cx'] = array(
                        'path' => 
'ContentTranslation/images/cx-notification-green.svg',
                );
@@ -268,6 +286,8 @@
        public static function onEchoGetDefaultNotifiedUsers( $event, &$users ) 
{
                switch ( $event->getType() ) {
                        case 'cx-first-translation':
+                       case 'cx-tenth-translation':
+                       case 'cx-hundredth-translation':
                                $extra = $event->getExtra();
                                if ( !isset( $extra['recipient'] ) ) {
                                        break;
diff --git a/api/ApiContentTranslationPublish.php 
b/api/ApiContentTranslationPublish.php
index 740ddc6..85f8c55 100755
--- a/api/ApiContentTranslationPublish.php
+++ b/api/ApiContentTranslationPublish.php
@@ -215,11 +215,7 @@
                        }
                        $this->saveTranslationHistory( $params );
                        // Notify user about milestones
-                       $translator = new ContentTranslation\Translator( $user 
);
-                       if ( $translator->getTranslationsCount() === 1 ) {
-                               
ContentTranslation\Notification::firstTranslation( $user );
-                       }
-                       // TODO: Add other milestones
+                       $this->notifyTranslator();
                } else {
                        $result = array(
                                'result' => 'error',
@@ -230,6 +226,26 @@
                $this->getResult()->addValue( null, $this->getModuleName(), 
$result );
        }
 
+       /**
+        * Notify user about milestones.
+        */
+       public function notifyTranslator() {
+               $user = $this->getUser();
+               $translator = new ContentTranslation\Translator( $user );
+               $translationCount = $translator->getTranslationsCount();
+               switch ( $translationCount ) {
+                       case 1 :
+                               
ContentTranslation\Notification::firstTranslation( $user );
+                               break;
+                       case 10 :
+                               
ContentTranslation\Notification::tenthTranslation( $user );
+                               break;
+                       case 100 :
+                               
ContentTranslation\Notification::hundredthTranslation( $user );
+                               break;
+               }
+       }
+
        public function saveAsDraft() {
                $params = $this->extractRequestParams();
                $this->saveTranslationHistory( $params );
diff --git a/i18n/en.json b/i18n/en.json
index 04fa1d8..6a90ba0 100644
--- a/i18n/en.json
+++ b/i18n/en.json
@@ -201,5 +201,9 @@
        "echo-category-title-cx": "Translations",
        "echo-pref-tooltip-cx": "Notify me about my translations created using 
Content Translation tool",
        "cx-notification-first-translation": "Congratulations for your first 
translation! Find more pages to translate at [[Special:MyContributions|your 
contributions page]].",
-       "cx-notification-first-translation-email-subject": "Congratulations for 
your first translation"
+       "cx-notification-first-translation-email-subject": "Congratulations for 
your first translation",
+       "cx-notification-tenth-translation": "Congratulations for your tenth 
translation! You are becoming an expert translator. Keep the good work!",
+       "cx-notification-tenth-translation-email-subject": "Congratulations for 
your tenth translation",
+       "cx-notification-hundredth-translation": "You just made 100 
translations! That is a remarkable achievement. Share the word with other 
editors",
+       "cx-notification-hundredth-translation-email-subject": "Congratulations 
for your one hundredth translation"
 }
diff --git a/i18n/qqq.json b/i18n/qqq.json
index bed6375..e6a281c 100644
--- a/i18n/qqq.json
+++ b/i18n/qqq.json
@@ -206,5 +206,9 @@
        "echo-category-title-cx": "Title of CX Echo notifications. Shown in 
[[Special:Preferences]] page to configure 
notifications\n{{Identical|Translation}}",
        "echo-pref-tooltip-cx": "A tooltip text about CX notifcations.Shown in 
[[Special:Preferences]] page to configure notifications",
        "cx-notification-first-translation": "Echo notification congratulating 
the user for first published translation. Don't translate the 
Special:MyContrubitions link.",
-       "cx-notification-first-translation-email-subject": "Email subject to 
congratulate the user for first published translation."
+       "cx-notification-first-translation-email-subject": "Email subject to 
congratulate the user for first published translation.",
+       "cx-notification-tenth-translation": "Echo notification congratulating 
the user for tenth published translation.",
+       "cx-notification-tenth-translation-email-subject":  "Email subject to 
congratulate the user for tenth published translation.",
+       "cx-notification-hundredth-translation": "Echo notification 
congratulating the user for hundred published translation.",
+       "cx-notification-hundredth-translation-email-subject":  "Email subject 
to congratulate the user for hundred published translation."
 }
diff --git a/includes/Notification.php b/includes/Notification.php
index a36eaf8..2ba05bb 100644
--- a/includes/Notification.php
+++ b/includes/Notification.php
@@ -18,4 +18,28 @@
                        )
                ) );
        }
+
+       /**
+        * Notify the user on tenth published translation.
+        */
+       public static function tenthTranslation( \User $recipient ) {
+               \EchoEvent::create( array(
+                       'type' => 'cx-tenth-translation',
+                       'extra' => array(
+                               'recipient' => $recipient->getId(),
+                       )
+               ) );
+       }
+
+       /**
+        * Notify the user on tenth published translation.
+        */
+       public static function hundredthTranslation( \User $recipient ) {
+               \EchoEvent::create( array(
+                       'type' => 'cx-hundredth-translation',
+                       'extra' => array(
+                               'recipient' => $recipient->getId(),
+                       )
+               ) );
+       }
 }

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: I2b51986bba6904ac43f630f602fba7a27cda75a8
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/ContentTranslation
Gerrit-Branch: master
Gerrit-Owner: Santhosh <santhosh.thottin...@gmail.com>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to