Plugin Directory

Changeset 3139318


Ignore:
Timestamp:
08/21/2024 10:48:35 PM (15 months ago)
Author:
mdawaffe
Message:

I18n improvements

  • Use the post type label translations
  • Don't concatenate multiple translated strings
  • Use numbered placeholders
  • Add context and comments where necessary

Props yoavf

File:
1 edited

Legend:

Unmodified
Added
Removed
  • email-post-changes/trunk/class.email-post-changes.php

    r3139317 r3139318  
    136136        $the_author = get_the_author_meta( 'display_name', get_current_user_id() ); // The revision
    137137        $the_title = get_the_title( $this->right_post->ID ); // New title (may be same as old title)
    138         $the_date = gmdate( 'j F, Y \a\t G:i \U\T\C', strtotime( $this->right_post->post_modified_gmt . '+0000' ) ); // Modified time
     138        $the_date = gmdate( _x( 'j F, Y \a\t G:i \U\T\C', 'time format for when a post was modified' ), strtotime( $this->right_post->post_modified_gmt . '+0000' ) ); // Modified time
    139139        $the_permalink = esc_url( get_permalink( $this->right_post->ID ) );
    140140        $the_edit_link = esc_url( get_edit_post_link( $this->right_post->ID ) );
     
    172172
    173173            $left_title = __( 'Revision' );
    174             $right_title = sprintf( __( 'Current %s' ), $post_type = ucfirst( $this->right_post->post_type ) );
    175 
    176             $head_sprintf = __( '%s made the following changes to the %s %s on %s' );
    177 
     174            $post_type = get_post_type_object( $this->right_post->post_type );
     175            $post_type_label = $post_type->labels->singular_name;
     176
     177            /* i18n for a post type can be tricky, let's have presets for the default post types */
     178            if ( $this->right_post->post_type == 'post' ) {
     179                $right_title = __( 'Current post' );
     180            } else if ( $this->right_post->post_type == 'page' ) {
     181                $right_title = __( 'Current page' );
     182            } else {
     183                $right_title = sprintf( _x( 'Current %s', 'post type' ), $post_type_label );
     184            }
     185
     186            /* translators: 1=username, 2=post type, 3=post title, 4=edit link, 4=post type, 5=date */
     187            $head_sprintf = __( '%1$s made the following changes to the “%2$s” %3$s %4$s on %5$s' );
    178188
    179189            // HTML
    180             $html_diff_head  = '<h2>' . sprintf( __( '%s changed' ), $post_type ) . "</h2>\n";
     190            $html_diff_head  = '<h2>' . sprintf( __( '%s changed' ), $post_type_label ) . "</h2>\n";
    181191            $html_diff_head .= '<p>' . sprintf( $head_sprintf,
    182192                esc_html( $the_author ),
    183                 sprintf( _x( '&#8220;%s&#8221; [%s]', '1 = link, 2 = "edit"' ),
    184193                    "<a href='$the_permalink'>" . esc_html( $the_title ) . '</a>',
    185                     "<a href='$the_edit_link'>" . __( 'edit' ) . '</a>'
    186                 ),
    187                 $this->right_post->post_type,
     194                "<a href='$the_edit_link'>" . __( '[edit]' ) . '</a>',
     195                $post_type_label,
    188196                $the_date
    189197            ) . "</p>\n\n";
    190198
    191199            $html_diff_head .= "<table style='width: 100%; border-collapse: collapse; border: none;'><tr>\n";
    192             $html_diff_head .= "<td style='width: 50%; padding: 0; margin: 0;'>" . esc_html( $left_title ) . ' @ ' . esc_html( $this->left_post->post_date_gmt ) . "</td>\n";
    193             $html_diff_head .= "<td style='width: 50%; padding: 0; margin: 0;'>" . esc_html( $right_title ) . ' @ ' . esc_html( $this->right_post->post_modified_gmt ) . "</td>\n";
     200            $html_diff_head .= "<td style='width: 50%; padding: 0; margin: 0;'>" . esc_html( sprintf( _x( '%1$s @ %2$s', 'post title @ date and time'), $left_title, $this->left_post->post_date_gmt ) ) . "</td>\n";
     201            $html_diff_head .= "<td style='width: 50%; padding: 0; margin: 0;'>" . esc_html( sprintf( _x( '%1$s @ %2$s', 'post title @ date and time'), $right_title, $this->right_post->post_date_gmt ) ) . "</td>\n";
    194202            $html_diff_head .= "</tr></table>\n\n";
    195203
     
    222230
    223231            // TEXT
    224             $text_diff  = sprintf( $head_sprintf, $the_author, '"' . $the_title . '"', $this->right_post->post_type, $the_date ) . "\n";
    225             $text_diff .= "URL:  $the_permalink\n";
    226             $text_diff .= "Edit: $the_edit_link\n\n";
     232            $text_diff  = sprintf( $head_sprintf, $the_author, $the_title, '', $post_type_label, $the_date ) . "\n";
     233            $text_diff .= sprintf( __( "URL: %s" ),  $the_permalink) . "\n";
     234            $text_diff .= sprintf( __( "Edit: %s" ), $the_edit_link ) . "\n";
    227235
    228236            foreach ( $text_diffs as $field_title => $diff ) {
     
    238246            wp_mail(
    239247                $email,
    240                 sprintf( __( '[%s] %s changed: %s' ), $blogname, $post_type, $title ),
     248                /* translators: 1=blogname, 2=post type, 3=post title */
     249                sprintf( __( '[%1$s] %2$s changed: %3$s' ), $blogname, $post_type_label, $title ),
    241250                $html_diff
    242251            );
Note: See TracChangeset for help on using the changeset viewer.