<!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>[3497] sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory: Plugin Directory: Initial commit for a readme POT generator/importer.</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/3497">3497</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/3497","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>2016-06-20 10:59:52 +0000 (Mon, 20 Jun 2016)</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'>Plugin Directory: Initial commit for a readme POT generator/importer.

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

<h3>Modified Paths</h3>
<ul>
<li><a href="#sitestrunkwordpressorgpublic_htmlwpcontentpluginsplugindirectorycliclasssvnwatcherphp">sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/cli/class-svn-watcher.php</a></li>
</ul>

<h3>Added Paths</h3>
<ul>
<li><a href="#sitestrunkwordpressorgpublic_htmlwpcontentpluginsplugindirectorybinimportplugintoglotpressphp">sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/bin/import-plugin-to-glotpress.php</a></li>
<li>sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/cli/i18n/</li>
<li><a href="#sitestrunkwordpressorgpublic_htmlwpcontentpluginsplugindirectoryclii18nclassreadmeimportphp">sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/cli/i18n/class-readme-import.php</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="sitestrunkwordpressorgpublic_htmlwpcontentpluginsplugindirectorybinimportplugintoglotpressphp"></a>
<div class="addfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Added: sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/bin/import-plugin-to-glotpress.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/bin/import-plugin-to-glotpress.php                              (rev 0)
+++ sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/bin/import-plugin-to-glotpress.php        2016-06-20 10:59:52 UTC (rev 3497)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -0,0 +1,68 @@
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+<?php
+namespace WordPressdotorg\Plugin_Directory;
+
+// This script should only be called in a CLI environment.
+if ( 'cli' != php_sapi_name() ) {
+       die();
+}
+
+$opts = getopt( '', array( 'url:', 'abspath:', 'plugin:', 'tag:', 'type:' ) );
+
+// Guess the default parameters:
+if ( empty( $opts ) && $argc == 2 ) {
+       $opts['plugin'] = $argv[1];
+       $argv[1] = '--plugin ' . $argv[1];
+}
+if ( empty( $opts['url'] ) ) {
+       $opts['url'] = 'https://wordpress.org/plugins/';
+}
+if ( empty( $opts['abspath'] ) && false !== strpos( __DIR__, 'wp-content' ) ) {
+       $opts['abspath'] = substr( __DIR__, 0, strpos( __DIR__, 'wp-content' ) );
+}
+
+foreach ( array( 'url', 'abspath', 'plugin' ) as $opt ) {
+       if ( empty( $opts[ $opt ] ) ) {
+               fwrite( STDERR, "Missing Parameter: $opt\n" );
+               fwrite( STDERR, "Usage: php {$argv[0]} --plugin hello-dolly --abspath /home/example/public_html --url https://wordpress.org/plugins/\n" );
+               fwrite( STDERR, "--url and --abspath will be guessed if possible.\n" );
+               die();
+       }
+}
+
+// Bootstrap WordPress
+$_SERVER['HTTP_HOST']   = parse_url( $opts['url'], PHP_URL_HOST );
+$_SERVER['REQUEST_URI'] = parse_url( $opts['url'], PHP_URL_PATH );
+
+include rtrim( $opts['abspath'], '/' ) . '/wp-load.php';
+
+if ( ! class_exists( '\WordPressdotorg\Plugin_Directory\Plugin_Directory' ) ) {
+       fwrite( STDERR, "Error! This site doesn't have the Plugin Directory plugin enabled.\n" );
+       if ( defined( 'WPORG_PLUGIN_DIRECTORY_BLOGID' ) ) {
+               fwrite( STDERR, "Run the following command instead:\n" );
+               fwrite( STDERR, "\tphp " . implode( ' ', $argv ) . " --url " . get_site_url( WPORG_PLUGIN_DIRECTORY_BLOGID, '/' ) . "\n" );
+       }
+       die();
+}
+
+$plugin_slug = $opts['plugin'];
+$tag         = $opts['tag'];
+$type        = $opts['type'];
+$start_time  = microtime( 1 );
+
+echo "Processing I18N Import for $plugin_slug... ";
+try {
+       if ( 'readme' === $type ) {
+               $importer = new CLI\I18N\Readme_Import( $plugin_slug );
+               $importer->import_from_tag( $tag );
+       } elseif ( 'code' === $type ) {
+               $importer = new CLI\I18N\Code_Import( $plugin_slug );
+               $importer->import_from_tag( $tag );
+       }
+
+       echo "OK. Took " . round( microtime(1) - $start_time, 2 )  . "s\n";
+} catch( \Exception $e ) {
+       echo "Failed. Took " . round( microtime(1) - $start_time, 2 )  . "s\n";
+
+       fwrite( STDERR, "[{$plugin_slug}] Plugin I18N Import Failed: " . $e->getMessage() . "\n" );
+       exit(1);
+}
</ins></span></pre></div>
<a id="sitestrunkwordpressorgpublic_htmlwpcontentpluginsplugindirectorycliclasssvnwatcherphp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/cli/class-svn-watcher.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/cli/class-svn-watcher.php       2016-06-20 10:03:29 UTC (rev 3496)
+++ sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/cli/class-svn-watcher.php 2016-06-20 10:59:52 UTC (rev 3497)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -11,8 +11,9 @@
</span><span class="cx" style="display: block; padding: 0 10px">  */
</span><span class="cx" style="display: block; padding: 0 10px"> class SVN_Watcher {
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-        const SVN_URL = 'https://plugins.svn.wordpress.org/';
-       const PHP     = '/usr/local/bin/php';
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ const SVN_URL      = 'https://plugins.svn.wordpress.org/';
+       const PHP          = '/usr/local/bin/php';
+       const PROCESS_I18N = false;
</ins><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">        public function __construct() {
</span><span class="cx" style="display: block; padding: 0 10px">                $this->watch();
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -58,12 +59,30 @@
</span><span class="cx" style="display: block; padding: 0 10px">                        echo "\$$cmd\n";
</span><span class="cx" style="display: block; padding: 0 10px">                        echo shell_exec( $cmd ) . "\n";
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                        if ( $this->process_i18n_for_plugin( $plugin_slug) && $plugin_data['readme_touched'] ) {
-// TODO                                echo "import GlotPress readme\n";
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                 if ( self::PROCESS_I18N ) {
+                               $plugin     = Plugin_Directory::get_plugin_post( $plugin_slug );
+                               $stable_tag = $plugin->stable_tag;
+
+                               $i18n_processes = [];
+                               if ( in_array( 'trunk', $plugin_data['tags_touched'] ) ) {
+                                       if ( $plugin_data['code_touched'] ) {
+                                               $i18n_processes[] = 'trunk|code';
+                                       }
+                                       if ( $plugin_data['readme_touched'] ) {
+                                               $i18n_processes[] = 'trunk|readme';
+                                       }
+                               }
+                               if ( in_array( $stable_tag, $plugin_data['tags_touched'] ) ) {
+                                       if ( $plugin_data['code_touched'] ) {
+                                               $i18n_processes[] = "{$stable_tag}|code";
+                                       }
+                                       if ( $plugin_data['readme_touched'] ) {
+                                               $i18n_processes[] = "{$stable_tag}|readme";
+                                       }
+                               }
+
+                               $this->process_i18n_for_plugin( $plugin_slug, $i18n_processes );
</ins><span class="cx" style="display: block; padding: 0 10px">                         }
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                        if ( $this->process_i18n_for_plugin( $plugin_slug) && $plugin_data['code_touched'] ) {
-// TODO                                echo "import GlotPress code\n";
-                       }
</del><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">                        $this->update_option( $svn_rev_option_name, $plugin_data['revision'] );
</span><span class="cx" style="display: block; padding: 0 10px">                }
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -73,10 +92,24 @@
</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><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-         * Determine Whether i18n processing is enabled for a plugin.
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+  * Processes i18n import tasks.
+        *
+        * @param string $plugin_slug
+        * @param array $i18n_processes
</ins><span class="cx" style="display: block; padding: 0 10px">          */
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-        protected function process_i18n_for_plugin( $plugin_slug ) {
-               return false;
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ protected function process_i18n_for_plugin( $plugin_slug, $i18n_processes ) {
+               foreach ( $i18n_processes as $process ) {
+                       list( $tag, $type ) = explode( '|', $process );
+
+                       $esc_plugin_slug = escapeshellarg( $plugin_slug );
+                       $esc_tag         = escapeshellarg( $tag );
+                       $esc_type        = escapeshellarg( $type );
+
+                       $cmd = self::PHP . ' ' . dirname( __DIR__ ) . "/bin/import-plugin-to-glotpress.php --plugin {$esc_plugin_slug} --tag {$esc_tag} --type {$esc_type}";
+
+                       echo "\n\$$cmd\n";
+                       echo shell_exec( $cmd ) . "\n";
+               }
</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">        /**
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -204,4 +237,4 @@
</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><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-}
</del><span class="cx" style="display: block; padding: 0 10px">\ No newline at end of file
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+}
</ins></span></pre></div>
<a id="sitestrunkwordpressorgpublic_htmlwpcontentpluginsplugindirectoryclii18nclassreadmeimportphp"></a>
<div class="addfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Added: sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/cli/i18n/class-readme-import.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/cli/i18n/class-readme-import.php                                (rev 0)
+++ sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/cli/i18n/class-readme-import.php  2016-06-20 10:59:52 UTC (rev 3497)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -0,0 +1,198 @@
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+<?php
+namespace WordPressdotorg\Plugin_Directory\CLI\I18N;
+
+use WordPressdotorg\Plugin_Directory\Plugin_I18n;
+use WordPressdotorg\Plugin_Directory\Tools\SVN;
+use WordPressdotorg\Plugin_Directory\Readme\Parser;
+use WordPressdotorg\Plugin_Directory\Tools\Filesystem;
+use Exception;
+
+/**
+ * Class to handle plugin readme imports GlotPress.
+ *
+ * @package WordPressdotorg\Plugin_Directory\CLI\I18N
+ */
+class Readme_Import {
+       const PLUGIN_SVN_BASE = 'https://plugins.svn.wordpress.org';
+
+       /**
+        * Slug of the plugin.
+        *
+        * @var string
+        */
+       private $plugin;
+
+       /**
+        * Constructor.
+        *
+        * @param string $plugin The plugin slug.
+        */
+       public function __construct( $plugin ) {
+               $this->plugin = $plugin;
+       }
+
+       /**
+        * Imports the readme of a specific tag to GlotPress.
+        *
+        * @param string $tag SVN tag of the readme.
+        *
+        * @throws Exception
+        */
+       public function import_from_tag( $tag ) {
+               global $wpdb;
+
+               $files = SVN::ls( self::PLUGIN_SVN_BASE . "/{$this->plugin}/{$tag}" );
+               if ( ! $files ) {
+                       throw new Exception( "Plugin has no files in {$tag}." );
+               }
+
+               $readme_files = preg_grep( '!^readme.(txt|md)$!i', $files );
+               if ( ! $readme_files ) {
+                       throw new Exception( 'Plugin has no readme file.' );
+               }
+
+               $readme_file = reset( $readme_files );
+               foreach ( $readme_files as $f ) {
+                       if ( '.txt' == strtolower( substr( $f, - 4 ) ) ) {
+                               $readme_file = $f;
+                               break;
+                       }
+               }
+
+               $readme_file = self::PLUGIN_SVN_BASE . "/{$this->plugin}/{$tag}/{$readme_file}";
+               $readme      = new Parser( $readme_file );
+
+               if ( ! class_exists( '\PO' ) ) {
+                       require_once ABSPATH . '/wp-includes/pomo/po.php';
+               }
+
+               $pot = new \PO;
+               $pot->set_header( 'MIME-Version', '1.0' );
+               $pot->set_header( 'Content-Type', 'text/plain; charset=UTF-8' );
+               $pot->set_header( 'Content-Transfer-Encoding', '8bit' );
+
+               $str_priorities = [];
+
+               if ( $readme->name ) {
+                       $pot->add_entry( new \Translation_Entry( [
+                               'singular'           => $readme->name,
+                               'extracted_comments' => 'Plugin name.',
+                       ] ) );
+
+                       $str_priorities[ $readme->name ] = 1;
+               }
+
+               if ( $readme->short_description ) {
+                       $pot->add_entry( new \Translation_Entry( [
+                               'singular'           => $readme->short_description,
+                               'extracted_comments' => 'Short description.',
+                       ] ) );
+
+                       $str_priorities[ $readme->name ] = 1;
+               }
+
+               if ( $readme->screenshots ) {
+                       foreach ( $readme->screenshots as $screenshot ) {
+                               $pot->add_entry( new \Translation_Entry( [
+                                       'singular'           => $screenshot,
+                                       'extracted_comments' => 'Screenshot description.',
+                               ] ) );
+                       }
+               }
+
+               $section_strings = [];
+
+               foreach ( $readme->sections as $section_key => $section_text ) {
+                       if ( 'changelog' !== $section_key ) { // No need to scan non-translatable version headers in changelog.
+                               if ( preg_match_all( '|<h[3-4]+[^>]*>(.+)</h[3-4]+>|', $section_text, $matches ) ) {
+                                       if ( ! empty( $matches[1] ) ) {
+                                               foreach ( $matches[1] as $text ) {
+                                                       $section_strings = $this->handle_translator_comment( $section_strings, $text, "{$section_key} header" );
+                                               }
+                                       }
+                               }
+                       }
+
+                       if ( preg_match_all( '|<li>([\s\S]*?)</li>|', $section_text, $matches ) ) {
+                               if ( ! empty( $matches[1] ) ) {
+                                       foreach ( $matches[1] as $text ) {
+                                               $section_strings = $this->handle_translator_comment( $section_strings, $text, "{$section_key} list item" );
+                                               if ( 'changelog' === $section_key ) {
+                                                       $str_priorities[ $text ] = -1;
+                                               }
+                                       }
+                               }
+                       }
+
+                       if ( preg_match_all( '|<p>([\s\S]*?)</p>|', $section_text, $matches ) ) {
+                               if ( ! empty( $matches[1] ) ) {
+                                       foreach ( $matches[1] as $text ) {
+                                               $section_strings = $this->handle_translator_comment( $section_strings, trim( $text ), "{$section_key} paragraph" );
+                                               if ( 'changelog' === $section_key ) {
+                                                       $str_priorities[ $text ] = - 1;
+                                               }
+                                       }
+                               }
+                       }
+               }
+
+               foreach ( $section_strings as $text => $comments ) {
+                       $pot->add_entry( new \Translation_Entry( [
+                               'singular'           => $text,
+                               'extracted_comments' => 'Found in ' . implode( $comments, ', ' ) . '.',
+                       ] ) );
+               }
+
+               $tmp_directory = Filesystem::temp_directory( $this->plugin . '-readme-' . $tag );
+               $pot_file = "{$tmp_directory}/{$this->plugin}-readme.pot";
+
+               $exported = $pot->export_to_file( $pot_file );
+               if ( ! $exported ) {
+                       throw new Exception( 'POT file not extracted.' );
+               }
+
+               // @todo: Create/update GP projects.
+
+               $branch = ( 'trunk' === $tag ) ? 'dev' : 'stable';
+               $cmd = WPORGTRANSLATE_WPCLI . ' glotpress import-originals ' . escapeshellarg( "wp-plugins/{$this->plugin}/{$branch}-readme" ) . ' ' . escapeshellarg( $pot_file );
+
+               echo "\n\$$cmd\n";
+               echo shell_exec( $cmd ) . "\n";
+
+               // @todo: Fix this.
+               $gp_branch_id = Plugin_I18n::instance()->get_gp_branch_id( $this->plugin, "{$branch}-readme" );
+               if ( $gp_branch_id ) {
+                       foreach ( $str_priorities as $str => $prio ) {
+                               if ( 1 !== $prio && -1 !== $prio ) {
+                                       $prio = 0;
+                               }
+
+                               $wpdb->query( $wpdb->prepare(
+                                       'UPDATE ' . GLOTPRESS_TABLE_PREFIX . 'originals SET priority = %d WHERE project_id = %d AND status = %s AND singular = %s',
+                                       $prio, $gp_branch_id, '+active', $str
+                               ) );
+                       }
+               }
+       }
+
+       /**
+        * Handles GlotPress "extracted comments" for translators to get context for each string translations.
+        *
+        * @param array $array Empty or existing arrays of string and comments
+        * @param string $key Unique key
+        * @param string $val Comment value
+        *
+        * @return array
+        */
+       function handle_translator_comment( $array, $key, $val ) {
+               $val = trim( preg_replace( '/[^a-z0-9]/i', ' ', $val ) ); // cleanup key names for display.
+
+               if ( empty( $array[ $key ] ) ) {
+                       $array[ $key ] = array( $val );
+               } elseif ( ! in_array( $val, $array[ $key ] ) ) {
+                       $array[ $key ][] = $val;
+               }
+
+               return $array;
+       }
+}
</ins></span></pre>
</div>
</div>

</body>
</html>