翻译不返回已翻译的字符串

时间:2014-02-06 作者:Pieter Goosen

我有以下功能在我的子主题中显示我的评论表单

    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\');
所有可翻译字符串都将被刮取并显示在我的af\\u af.po文件中。问题是有些字符串不返回翻译后的文本,有些字符串返回。以下是一些返回翻译文本的字符串

 \'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>\',
这里是那些不想显示翻译文本的字符串

 \'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>\',
这是我从wordpress核心文件复制的代码。我错过什么了吗?有什么建议吗

1 个回复
最合适的回答,由SO网友:Pieter Goosen 整理而成

我累了,犯了很多错误,我看不出来。我完全忽略了我的sprintf字符串缺少域名这一事实。我直接从wordpress核心文件复制了代码,这些代码不包含任何域名。这就是解决方法:改变

\'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>\',

\'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>\',

结束

相关推荐

Plugin Localization

我刚刚为wp构建了我的第一个插件,即使它不是一个伟大的“代码诗意”;)它正常工作。这是一个使用GalleryView 3.0 jquery插件转换默认wp库的插件(http://spaceforaname.com/galleryview).我唯一不能做的就是本地化。此插件的本地化意味着转换管理界面,在这里可以配置jquery插件选项来更改结果库的外观。我试着关注网络上数百万的教程,在论坛上阅读了很多关于这个问题的帖子,并遵循了codex的指南。。。但仍然没有运气。这就是我所做的:每个文本行都位于gette