<!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>[13774] sites/trunk/wordpress.org/public_html/wp-content/plugins/wporg-gp-customizations/inc/cli: Translation.</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 { white-space: pre-line; 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/13774">13774</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/13774","name":"Review Commit"}}</script></dd>
<dt style="float: left; width: 6em; font-weight: bold">Author</dt> <dd>amieiro</dd>
<dt style="float: left; width: 6em; font-weight: bold">Date</dt> <dd>2024-06-04 14:53:48 +0000 (Tue, 04 Jun 2024)</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'>Translation. Add the option to show statistics from the start date we want.</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#sitestrunkwordpressorgpublic_htmlwpcontentpluginswporggpcustomizationsinccliclassstatsprintphp">sites/trunk/wordpress.org/public_html/wp-content/plugins/wporg-gp-customizations/inc/cli/class-stats-print.php</a></li>
<li><a href="#sitestrunkwordpressorgpublic_htmlwpcontentpluginswporggpcustomizationsinccliclassstatsphp">sites/trunk/wordpress.org/public_html/wp-content/plugins/wporg-gp-customizations/inc/cli/class-stats.php</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="sitestrunkwordpressorgpublic_htmlwpcontentpluginswporggpcustomizationsinccliclassstatsprintphp"></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/wporg-gp-customizations/inc/cli/class-stats-print.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/wporg-gp-customizations/inc/cli/class-stats-print.php    2024-06-04 05:21:55 UTC (rev 13773)
+++ sites/trunk/wordpress.org/public_html/wp-content/plugins/wporg-gp-customizations/inc/cli/class-stats-print.php      2024-06-04 14:53:48 UTC (rev 13774)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -2,13 +2,45 @@
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px"> namespace WordPressdotorg\GlotPress\Customizations\CLI;
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+use DateTime;
</ins><span class="cx" style="display: block; padding: 0 10px"> use WP_CLI;
</span><span class="cx" style="display: block; padding: 0 10px"> use WP_CLI_Command;
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px"> class Stats_Print extends WP_CLI_Command  {
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+        /**
+        * Prints statistics starting from a specified date.
+        *
+        * ## OPTIONS
+        *
+        * [--start_date=<start_date>]
+        * : The start date for the statistics in 'Y-m-d' format.
+        *   If not provided, defaults to one week before the current date.
+        *
+        * ## EXAMPLES
+        *
+        *     # Print statistics starting from one week before the current date.
+        *     wp wporg-translate show-stats --url=translate.wordpress.org
+        *
+        *     # Print statistics starting from 2023-10-25.
+        *     wp wporg-translate show-stats --start_date=2023-10-25 --url=translate.wordpress.org
+        *
+        * @param array $args       Positional arguments.
+        * @param array $assoc_args Associative arguments.
+        */
</ins><span class="cx" style="display: block; padding: 0 10px">         public function __invoke( $args, $assoc_args ) {
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                if ( !isset( $assoc_args['start_date'] ) ) {
+                       $start_date = date( 'Y-m-d', strtotime( '-1 week' ) );
+               } else {
+                       $start_date     = $assoc_args['start_date'];
+                       $start_datetime = DateTime::createFromFormat( 'Y-m-d', $start_date ) ;
+                       $is_valid_date  = $start_datetime && $start_datetime->format( 'Y-m-d' ) === $start_date;
+                       if ( ! $is_valid_date ) {
+                               WP_CLI::error( 'The --start_date parameter must be in the format Y-m-d. E.g.: 2023-10-24' );
+                               return;
+                       }
+               }
</ins><span class="cx" style="display: block; padding: 0 10px">                 $stats = new Stats();
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                $stats( true );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+         $stats( true, $start_date );
</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">\ No newline at end of file
</span></span></pre></div>
<a id="sitestrunkwordpressorgpublic_htmlwpcontentpluginswporggpcustomizationsinccliclassstatsphp"></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/wporg-gp-customizations/inc/cli/class-stats.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/wporg-gp-customizations/inc/cli/class-stats.php  2024-06-04 05:21:55 UTC (rev 13773)
+++ sites/trunk/wordpress.org/public_html/wp-content/plugins/wporg-gp-customizations/inc/cli/class-stats.php    2024-06-04 14:53:48 UTC (rev 13774)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -13,12 +13,8 @@
</span><span class="cx" style="display: block; padding: 0 10px"> require WP_PLUGIN_DIR . '/wp-i18n-teams/wp-i18n-teams.php';
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px"> use DateTime;
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-use Exception;
-use GP;
</del><span class="cx" style="display: block; padding: 0 10px"> use GP_Locale;
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-use GP_Locales;
</del><span class="cx" style="display: block; padding: 0 10px"> use WP_CLI;
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-use WP_CLI_Command;
</del><span class="cx" style="display: block; padding: 0 10px"> use WP_Query;
</span><span class="cx" style="display: block; padding: 0 10px"> use WordPressdotorg\GlotPress\Routes\Plugin;
</span><span class="cx" style="display: block; padding: 0 10px"> use function WordPressdotorg\Locales\get_locales;
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -162,11 +158,12 @@
</span><span class="cx" style="display: block; padding: 0 10px">        /**
</span><span class="cx" style="display: block; padding: 0 10px">         * Prints the Polyglots stats or stores them on a page.
</span><span class="cx" style="display: block; padding: 0 10px">         *
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-         * @param bool $echo_the_values Whether it should print the info in the CLI or stores it on a page.
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+  * @param bool        $echo_the_values Whether it should print the info in the CLI or stores it on a page.
+        * @param string|null $old_date        The date to compare the stats with. Format: 'Y-m-d'.
</ins><span class="cx" style="display: block; padding: 0 10px">          *
</span><span class="cx" style="display: block; padding: 0 10px">         * @return void
</span><span class="cx" style="display: block; padding: 0 10px">         */
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-        public function __invoke( bool $echo_the_values = false ) {
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ public function __invoke( bool $echo_the_values = false, string $old_date = null ): void {
</ins><span class="cx" style="display: block; padding: 0 10px">                 global $wpdb;
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">                // This value is only set in the production site (translate.wordpress.org).
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -189,8 +186,11 @@
</span><span class="cx" style="display: block; padding: 0 10px">                $this->print_contributors_per_locale();
</span><span class="cx" style="display: block; padding: 0 10px">                $this->print_managers_stats();
</span><span class="cx" style="display: block; padding: 0 10px">                $this->print_most_active_translators();
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                $this->store_stats();
-               $this->print_stats_comparison( gmdate( 'Y-m-d' ) );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+         // Don't store the stats if we execute the command in the CLI, to avoid storing the same stats twice.
+               if ( ! $echo_the_values ) {
+                       $this->store_stats();
+               }
+               $this->print_stats_comparison( gmdate( 'Y-m-d' ), $old_date );
</ins><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">                $this->update_page();
</span><span class="cx" style="display: block; padding: 0 10px">        }
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -359,7 +359,7 @@
</span><span class="cx" style="display: block; padding: 0 10px">         * Print stats compared week on week.
</span><span class="cx" style="display: block; padding: 0 10px">         *
</span><span class="cx" style="display: block; padding: 0 10px">         * @param string $current_date The date for which we display the stats.
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-         * @param string $old_date The date to compare the stats with.
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+  * @param string $old_date     The date to compare the stats with.
</ins><span class="cx" style="display: block; padding: 0 10px">          *
</span><span class="cx" style="display: block; padding: 0 10px">         * @return void
</span><span class="cx" style="display: block; padding: 0 10px">         */
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -374,10 +374,19 @@
</span><span class="cx" style="display: block; padding: 0 10px">                if ( ! $current_date_data || ! $old_date_data ) {
</span><span class="cx" style="display: block; padding: 0 10px">                        return;
</span><span class="cx" style="display: block; padding: 0 10px">                }
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+
+               $current_datetime = DateTime::createFromFormat( 'Y-m-d', $current_date );
+               $old_datetime     = DateTime::createFromFormat( 'Y-m-d', $old_date );
+               if ( ! $current_datetime || ! $old_datetime ) {
+                       return;
+               }
+               $interval        = $current_datetime->diff( $old_datetime );
+               $days_difference = $interval->days;
+
</ins><span class="cx" style="display: block; padding: 0 10px">                 if ( ! $this->echo_the_values ) {
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                        $this->stats_comparison = $this->create_gutenberg_heading( 'Summary for weekly stats' );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                 $this->stats_comparison = $this->create_gutenberg_heading( "Summary for the last $days_difference days" );
</ins><span class="cx" style="display: block; padding: 0 10px">                 } else {
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                        $this->print_wpcli_heading( 'Summary for weekly stats' );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                 $this->print_wpcli_heading( "Summary for the last $days_difference days" );
</ins><span class="cx" style="display: block; padding: 0 10px">                 }
</span><span class="cx" style="display: block; padding: 0 10px">                $stats_diff = new \stdClass();
</span><span class="cx" style="display: block; padding: 0 10px">                foreach ( $current_date_data as $key => $value ) {
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -394,10 +403,10 @@
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">                $code .= 'Requests: There are ' . $current_date_data->requests_unresolved . ' unresolved editor requests out of ' . $current_date_data->requests_total . ' (' . $this->prefix_num( $stats_diff->requests_unresolved ) . ') total and ' . $current_date_data->locale_requests_unresolved . ' unresolved locale requests out of ' . $current_date_data->locale_requests_total . ' (' . $this->prefix_num( $stats_diff->locale_requests_unresolved ) . ') total.' . PHP_EOL . PHP_EOL;
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                $code .= 'Translators: There are ' . $current_date_data->translators_gtes . ' (' . $this->prefix_num( $stats_diff->translators_gtes ) . ') GTEs, ' . $current_date_data->translators_ptes . ' (' . $this->prefix_num( $stats_diff->translators_ptes ) . ') PTEs and ' . $current_date_data->translators_contributors . ' (' . $this->prefix_num( $stats_diff->translators_contributors ) . ') translation contributors.' . PHP_EOL;
-               $code .= '(A wordpress.org account could have multiple roles over different locale)' . PHP_EOL . PHP_EOL;
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+         $code .= 'Translators: There are ' . number_format_i18n( $current_date_data->translators_gtes ) . ' (' . $this->prefix_num( $stats_diff->translators_gtes ) . ') GTEs, ' . number_format_i18n( $current_date_data->translators_ptes ) . ' (' . $this->prefix_num( $stats_diff->translators_ptes ) . ') PTEs and ' . number_format_i18n( $current_date_data->translators_contributors ) . ' (' . $this->prefix_num( $stats_diff->translators_contributors ) . ') translation contributors.' . PHP_EOL;
+               $code .= '(A wordpress.org account could have multiple roles over different locale).' . PHP_EOL . PHP_EOL;
</ins><span class="cx" style="display: block; padding: 0 10px"> 
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                $code .= 'Site language: ' . $current_date_data->wp_translated_sites_pct . '% (' . $this->prefix_num( round( $stats_diff->wp_translated_sites_pct, 3 ) ) . '%) of WordPress sites are running a translated WordPress site. ' . PHP_EOL;
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+         $code .= 'Site language: ' . $current_date_data->wp_translated_sites_pct . '% (' . $this->prefix_num( round( $stats_diff->wp_translated_sites_pct, 3 ), 3 ) . '%) of WordPress sites are running a translated WordPress site. ' . PHP_EOL;
</ins><span class="cx" style="display: block; padding: 0 10px">                 if ( ! $this->echo_the_values ) {
</span><span class="cx" style="display: block; padding: 0 10px">                        $this->stats_comparison .= $this->create_gutenberg_code( $code );
</span><span class="cx" style="display: block; padding: 0 10px">                } else {
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -420,15 +429,16 @@
</span><span class="cx" style="display: block; padding: 0 10px">        /**
</span><span class="cx" style="display: block; padding: 0 10px">         * Prefix numbers greater than zero with plus sign and plus_minus sign if number is zero.
</span><span class="cx" style="display: block; padding: 0 10px">         *
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-         * @param int $num Number to be prefixed.
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+  * @param float $number          Number to be prefixed.
+        * @param int   $number_decimals Number of decimals to be displayed.
</ins><span class="cx" style="display: block; padding: 0 10px">          *
</span><span class="cx" style="display: block; padding: 0 10px">         * @return string Prefixed number
</span><span class="cx" style="display: block; padding: 0 10px">         */
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-        private function prefix_num( $num ) {
-               if ( 0 === $num ) {
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ private function prefix_num( $number, $number_decimals = 0 ) {
+               if ( 0 === $number ) {
</ins><span class="cx" style="display: block; padding: 0 10px">                         return '±0';
</span><span class="cx" style="display: block; padding: 0 10px">                }
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                return $num > 0 ? sprintf( '+%d', $num ) : $num;
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+         return $number > 0 ? sprintf( '+%s', number_format_i18n( $number, $number_decimals ) ) : number_format_i18n( $number, $number_decimals );
</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></pre>
</div>
</div>

</body>
</html>