如何翻译主题中的COMMENTS_NUMBER函数文本?

时间:2016-07-04 作者:jetyet47

如果我只是重复常规文本,我会这样做:

<?php _e(\'This post is closed to new comments.\',\'my-theme\') ?>
但是我该如何翻译文本comments_number(); 这样“评论”文本就可以翻译了?像这样:

<?php comments_number( \'Comments (0)\', \'Comments (1)\', \'Comments (%)\' ); ?>

2 个回复
SO网友:Max Yudin

您必须使用__() 功能:

comments_number( __(\'Comments (0)\'), __(\'Comments (1)\'), __(\'Comments (%)\') );
如果要使用自定义textdomain, e、 g。\'test\':

comments_number( __(\'Comments (0)\', \'test\'), __(\'Comments (1)\', \'test\'), __(\'Comments (%)\', \'test\') );
有关更多信息,请参阅:

SO网友:user1049961

这个comments_number 函数正在调用get_comments_number_text 功能:https://developer.wordpress.org/reference/functions/get_comments_number_text/

在该函数中有要翻译的字符串

function get_comments_number_text( $zero = false, $one = false, $more = false ) {
    $number = get_comments_number();

    if ( $number > 1 ) {
        if ( false === $more ) {
            /* translators: %s: number of comments */
            $output = sprintf( _n( \'%s Comment\', \'%s Comments\', $number ), number_format_i18n( $number ) );
        } else {
            // % Comments
            $output = str_replace( \'%\', number_format_i18n( $number ), $more );
        }
    } elseif ( $number == 0 ) {
        $output = ( false === $zero ) ? __( \'No Comments\' ) : $zero;
    } else { // must be one
        $output = ( false === $one ) ? __( \'1 Comment\' ) : $one;
    }
    /**
     * Filter the comments count for display.
     *
     * @since 1.5.0
     *
     * @see _n()
     *
     * @param string $output A translatable string formatted based on whether the count
     *                       is equal to 0, 1, or 1+.
     * @param int    $number The number of post comments.
     */
    return apply_filters( \'comments_number\', $output, $number );
}

相关推荐

month name translation

我使用birdtips主题,它将发布日期格式化为$birdtips_posted = date(__(\'Y. F j.\', \'birdtips\'), strtotime(get_the_time(\"Y-m-d\"))); 其中Y.F.j.已经被改写以反映我的语言。据我所知,\\uuuu是翻译功能,但我如何告诉Wordpress我使用匈牙利语,它会自动翻译月份名称,或者我应该在中给出名称。采购订单文件?