<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>[6686] sites/trunk/global.wordpress.org/public_html/wp-content/mu-plugins/roles/rosetta-roles.php: Rosetta Roles: Send newly added translation editors an email notification.</title>
</head>
<body>

<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt;  }
#msg dl a { font-weight: bold}
#msg dl a:link    { color:#fc3; }
#msg dl a:active  { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg ul { text-indent: -1em; padding-left: 1em; }#logmsg ol { text-indent: -1.5em; padding-left: 1.5em; }
#logmsg > ul, #logmsg > ol { margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff  {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<dl class="meta" style="font-size: 105%">
<dt style="float: left; width: 6em; font-weight: bold">Revision</dt> <dd><a style="font-weight: bold" href="http://meta.trac.wordpress.org/changeset/6686">6686</a><script type="application/ld+json">{"@context":"http://schema.org","@type":"EmailMessage","description":"Review this Commit","action":{"@type":"ViewAction","url":"http://meta.trac.wordpress.org/changeset/6686","name":"Review Commit"}}</script></dd>
<dt style="float: left; width: 6em; font-weight: bold">Author</dt> <dd>ocean90</dd>
<dt style="float: left; width: 6em; font-weight: bold">Date</dt> <dd>2018-02-18 14:58:36 +0000 (Sun, 18 Feb 2018)</dd>
</dl>

<pre style='padding-left: 1em; margin: 2em 0; border-left: 2px solid #ccc; line-height: 1.25; font-size: 105%; font-family: sans-serif'>Rosetta Roles: Send newly added translation editors an email notification.

Fixes <a href="http://meta.trac.wordpress.org/ticket/1613">#1613</a>.</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#sitestrunkglobalwordpressorgpublic_htmlwpcontentmupluginsrolesrosettarolesphp">sites/trunk/global.wordpress.org/public_html/wp-content/mu-plugins/roles/rosetta-roles.php</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="sitestrunkglobalwordpressorgpublic_htmlwpcontentmupluginsrolesrosettarolesphp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: sites/trunk/global.wordpress.org/public_html/wp-content/mu-plugins/roles/rosetta-roles.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- sites/trunk/global.wordpress.org/public_html/wp-content/mu-plugins/roles/rosetta-roles.php        2018-02-18 14:54:16 UTC (rev 6685)
+++ sites/trunk/global.wordpress.org/public_html/wp-content/mu-plugins/roles/rosetta-roles.php  2018-02-18 14:58:36 UTC (rev 6686)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -72,9 +72,13 @@
</span><span class="cx" style="display: block; padding: 0 10px">                if ( ! is_main_site() ) {
</span><span class="cx" style="display: block; padding: 0 10px">                        add_action( 'admin_menu', array( $this, 'register_translation_editors_page' ) );
</span><span class="cx" style="display: block; padding: 0 10px">                        add_filter( 'set-screen-option', array( $this, 'save_custom_screen_options' ), 10, 3 );
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                        add_action( 'after_setup_theme', array( $this, 'register_resources_nav_menu' ) );
</ins><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">                        add_action( 'translation_editor_added', array( $this, 'update_wporg_profile_badge' ) );
</span><span class="cx" style="display: block; padding: 0 10px">                        add_action( 'translation_editor_removed', array( $this, 'update_wporg_profile_badge' ) );
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+
+                       add_action( 'translation_editor_added', array( $this, 'send_email_notification' ), 10, 2 );
+                       add_action( 'translation_editor_updated', array( $this, 'send_email_notification' ), 10, 2 );
</ins><span class="cx" style="display: block; padding: 0 10px">                 }
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">                add_action( 'wp_ajax_rosetta-get-projects', array( $this, 'ajax_rosetta_get_projects' ) );
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -83,6 +87,13 @@
</span><span class="cx" style="display: block; padding: 0 10px">        }
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">        /**
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+         * Registers a nav menu for storing resources for translation editors.
+        */
+       public function register_resources_nav_menu() {
+               register_nav_menu( 'rosetta_translation_editor_resources', __( 'Resources for translation editors', 'rosetta' ) );
+       }
+
+       /**
</ins><span class="cx" style="display: block; padding: 0 10px">          * Registers page for managing translation editors.
</span><span class="cx" style="display: block; padding: 0 10px">         */
</span><span class="cx" style="display: block; padding: 0 10px">        public function register_translation_editors_page() {
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -505,6 +516,172 @@
</span><span class="cx" style="display: block; padding: 0 10px">        }
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">        /**
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+         * Sends an email to the new translation editor.
+        *
+        * @param \WP_User $user           The user object of the translation editor.
+        * @param array    $projects_added List of project IDs.
+        */
+       public function send_email_notification( $user, $projects_added ) {
+               // Don't send an email if no new projects have been added.
+               if ( ! $projects_added ) {
+                       return;
+               }
+
+               $to      = $user->user_email;
+               $subject = __( 'You have been added to a WordPress project as a translation editor', 'rosetta' );
+
+               if ( [ '0' ] === $projects_added ) {
+                       // General Translation Editor.
+
+                       /* translators: Do not translate the placeholders USERNAME, LOCALENAME, LOCALEURL. */
+                       $message = __(
+                               'Howdy ###USERNAME###,
+
+We are happy to inform you that you have been successfully added as a General Translation Editor of WordPress for ###LOCALENAME###.
+
+As a General Translation Editor you have access to submit and approve translations for all projects available at ###LOCALEURL###.
+
+Alongside WordPress itself, it’s good to prioritize translating the projects that ship with it first – The default themes like Twenty Seventeen or Twenty Sixteen, and Akismet.
+
+Please get to know how the team works by reading the Translators Handbook – https://make.wordpress.org/polyglots/handbook/, a good place to start is the General Expectations page.
+
+As a General Translation Editor for the locale, we request that you fill out your WordPress.org profile (https://profiles.wordpress.org/profile/), register on Slack and provide a way for translation contributors to reach you.
+
+We also ask all WordPress General Translation Editors to subscribe for notifications for their locales, you can find the notification subscription settings in your profile settings (https://profiles.wordpress.org/profile/notifications/).
+
+The Polyglots team connects on Slack once per week at 11am UTC every Wednesday. We’d love to have you there if you can make it. Register from http://chat.wordpress.org.
+If you have any questions about the processes or need any help, reach the team on Slack or on https://make.wordpress.org/polyglots/.
+
+Welcome to the WordPress Polyglots team and happy translating!'
+                       );
+
+                       $message = str_replace(
+                               [
+                                       '###USERNAME###',
+                                       '###LOCALENAME###',
+                                       '###LOCALEURL###',
+                               ],
+                               [
+                                       $user->user_login,
+                                       '#' . $this->gp_locale->wp_locale . ' (' . $this->gp_locale->native_name . ')',
+                                       'https://translate.wordpress.org/locale/' . $this->gp_locale->slug,
+                               ],
+                               $message
+                       );
+               } else {
+                       // Project Translation Editor.
+
+                       /* translators: Do not translate the placeholders USERNAME, LOCALENAME, PROJECTLIST, RESOURCESLIST. */
+                       $message = __(
+                               'Howdy ###USERNAME###,
+
+We are happy to inform you that you have been successfully added as a Project Translation Editor for ###LOCALENAME### for the following projects:
+
+###PROJECTLIST###
+
+You have been added to these projects either by your own request, or by the request of the plugin author.
+
+Before translating, please get to know how the team works by reading the Translators Handbook – https://make.wordpress.org/polyglots/handbook/, a good place to start is the General Expectations page.
+
+Your local translation team can be found on https://make.wordpress.org/polyglots/teams/. Make sure you get familiar with the documentation about translating in your language that other contributors from your team have prepared.
+
+###RESOURCESLIST###
+
+The Polyglots team connects on Slack once per week at 11am UTC every Wednesday. We’d love to have you there if you can make it. Register from https://chat.wordpress.org/.
+If you have any questions about the processes or need any help, reach the team on Slack or on https://make.wordpress.org/polyglots/.
+
+Welcome to the WordPress Polyglots team and happy translating.'
+                       );
+
+                       $projects     = $this->get_translate_projects();
+                       $project_tree = $this->get_project_tree( $projects, 0, 1 );
+
+                       $project_list = [];
+
+                       foreach ( $projects_added as $project_id ) {
+                               if ( $projects[ $project_id ] ) {
+                                       $parent = $this->get_parent_project( $project_tree, $project_id );
+                                       if ( $parent->id != $project_id ) {
+                                               $name = sprintf(
+                                                       /* translators: 1: Parent project name, 2: Child project name */
+                                                       __( '%1$s &rarr; %2$s', 'rosetta' ),
+                                                       $parent->name,
+                                                       $projects[ $project_id ]->name
+                                               );
+                                       } else {
+                                               $name = $projects[ $project_id ]->name;
+                                       }
+
+                                       $name = sprintf(
+                                               '%s: %s',
+                                               $name,
+                                               esc_url( 'https://translate.wordpress.org/projects/' . $projects[ $project_id ]->path )
+                                       );
+
+                                       $project_list[] = html_entity_decode( $name, ENT_QUOTES, get_bloginfo( 'charset' ) );
+                               }
+                       }
+
+                       $resources_list = '';
+
+                       if ( has_nav_menu( 'rosetta_translation_editor_resources' ) ) {
+                               $resources_list = (string) wp_nav_menu( [
+                                       'fallback_cb'    => '__return_false',
+                                       'theme_location' => 'rosetta_translation_editor_resources',
+                                       'container'      => false,
+                                       'echo'           => false,
+                                       'depth'          => 1,
+                                       'items_wrap'     => '%3$s',
+                                       // Custom walker that returns plain text links.
+                                       'walker'         => new class() extends Walker_Nav_Menu {
+                                               public function start_lvl( &$output, $depth = 0, $args = array() ) {
+                                                       $output .= "\n";
+                                               }
+                                               public function end_lvl( &$output, $depth = 0, $args = array() ) {
+                                                       $output .= "\n";
+                                               }
+                                               public function start_el( &$output, $item, $depth = 0, $args = array(), $id = 0 ) {
+                                                       $href  = ! empty( $item->url ) ? $item->url : '';
+                                                       $title = apply_filters( 'the_title', $item->title, $item->ID );
+                                                       $title = apply_filters( 'nav_menu_item_title', $title, $item, $args, $depth );
+
+                                                       $item_output = $title;
+                                                       if ( $href ) {
+                                                               $item_output .= ': ' . esc_url( $href );
+                                                       }
+
+                                                       $output .= apply_filters( 'walker_nav_menu_start_el', $item_output, $item, $depth, $args );
+                                               }
+                                               public function end_el( &$output, $item, $depth = 0, $args = array() ) {
+                                                       $output .= "\n";
+                                               }
+                                       },
+                               ] );
+                       }
+
+                       $message = str_replace(
+                               [
+                                       '###USERNAME###',
+                                       '###LOCALENAME###',
+                                       '###PROJECTLIST###',
+                                       '###RESOURCESLIST###',
+                               ],
+                               [
+                                       $user->user_login,
+                                       '#' . $this->gp_locale->wp_locale . ' (' . $this->gp_locale->native_name . ')',
+                                       implode( "\n", $project_list ),
+                                       $resources_list,
+                               ],
+                               $message
+                       );
+               }
+
+               $headers = "From: \"WordPress Polyglots\" <donotreply@wordpress.org>\n" . 'Content-Type: text/plain; charset="' . get_option( 'blog_charset' ) . "\"\n";
+
+               wp_mail( $to, $subject, $message, $headers );
+       }
+
+       /**
</ins><span class="cx" style="display: block; padding: 0 10px">          * Retrieves the assigned projects of a user
</span><span class="cx" style="display: block; padding: 0 10px">         *
</span><span class="cx" style="display: block; padding: 0 10px">         * @param int $user_id User ID.
</span></span></pre>
</div>
</div>

</body>
</html>