$conf, $runtime; function_exists('chdir') AND chdir(APP_PATH); $r = 'mysql' == $conf['cache']['type'] ? website_set('runtime', $runtime) : cache_set('runtime', $runtime); } function runtime_truncate() { global $conf; 'mysql' == $conf['cache']['type'] ? website_set('runtime', '') : cache_delete('runtime'); } register_shutdown_function('runtime_save'); ?>localization - Translations not returning translated strings|Programmer puzzle solving
最新消息:Welcome to the puzzle paradise for programmers! Here, a well-designed puzzle awaits you. From code logic puzzles to algorithmic challenges, each level is closely centered on the programmer's expertise and skills. Whether you're a novice programmer or an experienced tech guru, you'll find your own challenges on this site. In the process of solving puzzles, you can not only exercise your thinking skills, but also deepen your understanding and application of programming knowledge. Come to start this puzzle journey full of wisdom and challenges, with many programmers to compete with each other and show your programming wisdom! Translated with DeepL.com (free version)

localization - Translations not returning translated strings

matteradmin10PV0评论

I have the following function to display my comment form in my child theme

    function pietergoosen_comment_form_fields( $args = array(), $post_id = null ) {
    if ( null === $post_id )
        $post_id = get_the_ID();
    else
        $id = $post_id;

    $commenter = wp_get_current_commenter();
    $user = wp_get_current_user();
    $user_identity = $user->exists() ? $user->display_name : '';

    $args = wp_parse_args( $args );
    if ( ! isset( $args['format'] ) )
        $args['format'] = current_theme_supports( 'html5', 'comment-form' ) ? 'html5' : 'xhtml';

    $req      = get_option( 'require_name_email' );
    $aria_req = ( $req ? " aria-required='true'" : '' );
    $html5    = 'html5' === $args['format'];
    $fields   =  array(
        'author' => '<p class="comment-form-author">' . '<label for="author">' . __( 'Name', 'pietergoosen' ) . ( $req ? ' <span class="required">*</span>' : '' ) . '</label> ' .
                    '<input id="author" name="author" placeholder="'.__( '*Required* Enter a valid name and last name', 'pietergoosen' ).'" type="text" value="' . esc_attr( $commenter['comment_author'] ) . '" size="30"' . $aria_req . ' /></p>',

        'email'  => '<p class="comment-form-email"><label for="email">' . __( 'Email', 'pietergoosen' ) . ( $req ? ' <span class="required">*</span>' : '' ) . '</label> ' .
                    '<input id="email" name="email" placeholder="'.__( '*Required* Enter a valid email', 'pietergoosen' ).'" ' . ( $html5 ? 'type="email"' : 'type="text"' ) . ' value="' . esc_attr(  $commenter['comment_author_email'] ) . '" size="30"' . $aria_req . ' /></p>',

        'referer' =>'<p class="comment-form-referer"><label for="referer">' . __( 'Where did you here about this website?', 'pietergoosen' ) . '</label>' .
                    '<input id="referer" name="referer" placeholder="'.__( 'Facebook, Twitter, Friends, Google, etc &hellip;', 'pietergoosen' ).'" type="text"  size="30" /></p>',
);

    $required_text = sprintf( ' ' . __( 'Required fiels are marked %s'), '<span class="required">*</span>' );

    $arg = array(
        'fields'               => apply_filters( 'comment_form_default_fields', $fields ),
        'comment_field'        => '<p class="comment-form-comment"><label for="comment">' . _x( 'Comment', 'Comments field name', 'pietergoosen' ) . '</label> <textarea id="comment" name="comment" placeholder="'.__( '*Required* Enter your comment here. Minimum 20 characters, please', 'pietergoosen' ).'" cols="45" rows="8" aria-required="true"></textarea></p>',
        'must_log_in'          => '<p class="must-log-in">' . sprintf( __( 'You must be <a href="%s">logged in</a> to post a comment.' ), wp_login_url( apply_filters( 'the_permalink', get_permalink( $post_id ) ) ) ) . '</p>',
        'logged_in_as'         => '<p class="logged-in-as">' . sprintf( __( 'Logged in as <a href="%1$s">%2$s</a>. <a href="%3$s" title="Log out of this account">Log out?</a>' ), get_edit_user_link(), $user_identity, wp_logout_url( apply_filters( 'the_permalink', get_permalink( $post_id ) ) ) ) . '</p>',
        'comment_notes_before' => '<p class="comment-notes">' . __( 'Your email address will not be published.' ) . ( $req ? $required_text : '' ) . '</p>',
        'comment_notes_after'  => '<p class="form-allowed-tags">' . sprintf( __( 'You may use these <abbr title="HyperText Markup Language">HTML</abbr> tags and attributes: %s' ), ' <code>' . allowed_tags() . '</code>' ) . '</p>',
        'id_form'              => 'commentform',
        'id_submit'            => 'submit',
        'title_reply'          => __( 'Leave a Reply', 'pietergoosen' ),
        'title_reply_to'       => __( 'Leave a Reply to %s', 'pietergoosen' ),
        'cancel_reply_link'    => __( 'Cancel reply', 'pietergoosen' ),
        'label_submit'         => __( 'Post Comment', 'pietergoosen' ),
        'format'               => 'xhtml',
        );
    return $arg;
}

add_filter('comment_form_defaults', 'pietergoosen_comment_form_fields');

All the translatable strings are scraped up and are displayed in my af_AF.po file. The problem is that some strings don't return the translated texts and some do. Here are some of the strings that return the translated text

 'author' => '<p class="comment-form-author">' . '<label for="author">' . __( 'Name', 'pietergoosen' ) . ( $req ? ' <span class="required">*</span>' : '' ) . '</label> ' .
                    '<input id="author" name="author" placeholder="'.__( '*Required* Enter a valid name and last name', 'pietergoosen' ).'" type="text" value="' . esc_attr( $commenter['comment_author'] ) . '" size="30"' . $aria_req . ' /></p>',

        'email'  => '<p class="comment-form-email"><label for="email">' . __( 'Email', 'pietergoosen' ) . ( $req ? ' <span class="required">*</span>' : '' ) . '</label> ' .
                    '<input id="email" name="email" placeholder="'.__( '*Required* Enter a valid email', 'pietergoosen' ).'" ' . ( $html5 ? 'type="email"' : 'type="text"' ) . ' value="' . esc_attr(  $commenter['comment_author_email'] ) . '" size="30"' . $aria_req . ' /></p>',

        'referer' =>'<p class="comment-form-referer"><label for="referer">' . __( 'Where did you here about this website?', 'pietergoosen' ) . '</label>' .
                    '<input id="referer" name="referer" placeholder="'.__( 'Facebook, Twitter, Friends, Google, etc &hellip;', 'pietergoosen' ).'" type="text"  size="30" /></p>',

and here are those strings that don't want to show the translated text

 'comment_field'        => '<p class="comment-form-comment"><label for="comment">' . _x( 'Comment', 'Comments field name', 'pietergoosen' ) . '</label> <textarea id="comment" name="comment" placeholder="'.__( '*Required* Enter your comment here. Minimum 20 characters, please', 'pietergoosen' ).'" cols="45" rows="8" aria-required="true"></textarea></p>',
        'must_log_in'          => '<p class="must-log-in">' . sprintf( __( 'You must be <a href="%s">logged in</a> to post a comment.' ), wp_login_url( apply_filters( 'the_permalink', get_permalink( $post_id ) ) ) ) . '</p>',
        'logged_in_as'         => '<p class="logged-in-as">' . sprintf( __( 'Logged in as <a href="%1$s">%2$s</a>. <a href="%3$s" title="Log out of this account">Log out?</a>' ), get_edit_user_link(), $user_identity, wp_logout_url( apply_filters( 'the_permalink', get_permalink( $post_id ) ) ) ) . '</p>',
        'comment_notes_before' => '<p class="comment-notes">' . __( 'Your email address will not be published.' ) . ( $req ? $required_text : '' ) . '</p>',
        'comment_notes_after'  => '<p class="form-allowed-tags">' . sprintf( __( 'You may use these <abbr title="HyperText Markup Language">HTML</abbr> tags and attributes: %s' ), ' <code>' . allowed_tags() . '</code>' ) . '</p>',

This is code I copied from wordpress core files. Am I missing something? Any suggestions

I have the following function to display my comment form in my child theme

    function pietergoosen_comment_form_fields( $args = array(), $post_id = null ) {
    if ( null === $post_id )
        $post_id = get_the_ID();
    else
        $id = $post_id;

    $commenter = wp_get_current_commenter();
    $user = wp_get_current_user();
    $user_identity = $user->exists() ? $user->display_name : '';

    $args = wp_parse_args( $args );
    if ( ! isset( $args['format'] ) )
        $args['format'] = current_theme_supports( 'html5', 'comment-form' ) ? 'html5' : 'xhtml';

    $req      = get_option( 'require_name_email' );
    $aria_req = ( $req ? " aria-required='true'" : '' );
    $html5    = 'html5' === $args['format'];
    $fields   =  array(
        'author' => '<p class="comment-form-author">' . '<label for="author">' . __( 'Name', 'pietergoosen' ) . ( $req ? ' <span class="required">*</span>' : '' ) . '</label> ' .
                    '<input id="author" name="author" placeholder="'.__( '*Required* Enter a valid name and last name', 'pietergoosen' ).'" type="text" value="' . esc_attr( $commenter['comment_author'] ) . '" size="30"' . $aria_req . ' /></p>',

        'email'  => '<p class="comment-form-email"><label for="email">' . __( 'Email', 'pietergoosen' ) . ( $req ? ' <span class="required">*</span>' : '' ) . '</label> ' .
                    '<input id="email" name="email" placeholder="'.__( '*Required* Enter a valid email', 'pietergoosen' ).'" ' . ( $html5 ? 'type="email"' : 'type="text"' ) . ' value="' . esc_attr(  $commenter['comment_author_email'] ) . '" size="30"' . $aria_req . ' /></p>',

        'referer' =>'<p class="comment-form-referer"><label for="referer">' . __( 'Where did you here about this website?', 'pietergoosen' ) . '</label>' .
                    '<input id="referer" name="referer" placeholder="'.__( 'Facebook, Twitter, Friends, Google, etc &hellip;', 'pietergoosen' ).'" type="text"  size="30" /></p>',
);

    $required_text = sprintf( ' ' . __( 'Required fiels are marked %s'), '<span class="required">*</span>' );

    $arg = array(
        'fields'               => apply_filters( 'comment_form_default_fields', $fields ),
        'comment_field'        => '<p class="comment-form-comment"><label for="comment">' . _x( 'Comment', 'Comments field name', 'pietergoosen' ) . '</label> <textarea id="comment" name="comment" placeholder="'.__( '*Required* Enter your comment here. Minimum 20 characters, please', 'pietergoosen' ).'" cols="45" rows="8" aria-required="true"></textarea></p>',
        'must_log_in'          => '<p class="must-log-in">' . sprintf( __( 'You must be <a href="%s">logged in</a> to post a comment.' ), wp_login_url( apply_filters( 'the_permalink', get_permalink( $post_id ) ) ) ) . '</p>',
        'logged_in_as'         => '<p class="logged-in-as">' . sprintf( __( 'Logged in as <a href="%1$s">%2$s</a>. <a href="%3$s" title="Log out of this account">Log out?</a>' ), get_edit_user_link(), $user_identity, wp_logout_url( apply_filters( 'the_permalink', get_permalink( $post_id ) ) ) ) . '</p>',
        'comment_notes_before' => '<p class="comment-notes">' . __( 'Your email address will not be published.' ) . ( $req ? $required_text : '' ) . '</p>',
        'comment_notes_after'  => '<p class="form-allowed-tags">' . sprintf( __( 'You may use these <abbr title="HyperText Markup Language">HTML</abbr> tags and attributes: %s' ), ' <code>' . allowed_tags() . '</code>' ) . '</p>',
        'id_form'              => 'commentform',
        'id_submit'            => 'submit',
        'title_reply'          => __( 'Leave a Reply', 'pietergoosen' ),
        'title_reply_to'       => __( 'Leave a Reply to %s', 'pietergoosen' ),
        'cancel_reply_link'    => __( 'Cancel reply', 'pietergoosen' ),
        'label_submit'         => __( 'Post Comment', 'pietergoosen' ),
        'format'               => 'xhtml',
        );
    return $arg;
}

add_filter('comment_form_defaults', 'pietergoosen_comment_form_fields');

All the translatable strings are scraped up and are displayed in my af_AF.po file. The problem is that some strings don't return the translated texts and some do. Here are some of the strings that return the translated text

 'author' => '<p class="comment-form-author">' . '<label for="author">' . __( 'Name', 'pietergoosen' ) . ( $req ? ' <span class="required">*</span>' : '' ) . '</label> ' .
                    '<input id="author" name="author" placeholder="'.__( '*Required* Enter a valid name and last name', 'pietergoosen' ).'" type="text" value="' . esc_attr( $commenter['comment_author'] ) . '" size="30"' . $aria_req . ' /></p>',

        'email'  => '<p class="comment-form-email"><label for="email">' . __( 'Email', 'pietergoosen' ) . ( $req ? ' <span class="required">*</span>' : '' ) . '</label> ' .
                    '<input id="email" name="email" placeholder="'.__( '*Required* Enter a valid email', 'pietergoosen' ).'" ' . ( $html5 ? 'type="email"' : 'type="text"' ) . ' value="' . esc_attr(  $commenter['comment_author_email'] ) . '" size="30"' . $aria_req . ' /></p>',

        'referer' =>'<p class="comment-form-referer"><label for="referer">' . __( 'Where did you here about this website?', 'pietergoosen' ) . '</label>' .
                    '<input id="referer" name="referer" placeholder="'.__( 'Facebook, Twitter, Friends, Google, etc &hellip;', 'pietergoosen' ).'" type="text"  size="30" /></p>',

and here are those strings that don't want to show the translated text

 'comment_field'        => '<p class="comment-form-comment"><label for="comment">' . _x( 'Comment', 'Comments field name', 'pietergoosen' ) . '</label> <textarea id="comment" name="comment" placeholder="'.__( '*Required* Enter your comment here. Minimum 20 characters, please', 'pietergoosen' ).'" cols="45" rows="8" aria-required="true"></textarea></p>',
        'must_log_in'          => '<p class="must-log-in">' . sprintf( __( 'You must be <a href="%s">logged in</a> to post a comment.' ), wp_login_url( apply_filters( 'the_permalink', get_permalink( $post_id ) ) ) ) . '</p>',
        'logged_in_as'         => '<p class="logged-in-as">' . sprintf( __( 'Logged in as <a href="%1$s">%2$s</a>. <a href="%3$s" title="Log out of this account">Log out?</a>' ), get_edit_user_link(), $user_identity, wp_logout_url( apply_filters( 'the_permalink', get_permalink( $post_id ) ) ) ) . '</p>',
        'comment_notes_before' => '<p class="comment-notes">' . __( 'Your email address will not be published.' ) . ( $req ? $required_text : '' ) . '</p>',
        'comment_notes_after'  => '<p class="form-allowed-tags">' . sprintf( __( 'You may use these <abbr title="HyperText Markup Language">HTML</abbr> tags and attributes: %s' ), ' <code>' . allowed_tags() . '</code>' ) . '</p>',

This is code I copied from wordpress core files. Am I missing something? Any suggestions

Share Improve this question edited Feb 8, 2014 at 18:46 Pieter Goosen asked Feb 6, 2014 at 17:18 Pieter GoosenPieter Goosen 55.5k23 gold badges117 silver badges211 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 1

Getting tired so mistakes creep in that I don't see. I totally missed the fact that my sprintf strings are missing the domain name. I copied the code directly from the wordpress core files, and these code don't include any domain name. So this is the fix: Change

'must_log_in'          => '<p class="must-log-in">' . sprintf( __( 'You must be <a href="%s">logged in</a> to post a comment.' ), wp_login_url( apply_filters( 'the_permalink', get_permalink( $post_id ) ) ) ) . '</p>',

to

'must_log_in'          => '<p class="must-log-in">' . sprintf( __( 'You must be <a href="%s">logged in</a> to post a comment.', 'pietergoosen' ), wp_login_url( apply_filters( 'the_permalink', get_permalink( $post_id ) ) ) ) . '</p>',
Post a comment

comment list (0)

  1. No comments so far