我认为您需要了解您使用的代码是如何工作的。输出字符串的代码为:
<?php printf( __( \'%s ago\', \'wp-job-manager\' ), human_time_diff( get_post_time( \'U\' ), current_time( \'timestamp\' ) ) ); ?>
在上述代码中,
__( \'%s ago\', \'wp-job-manager\' )
由wp job manager语言文件和
%s
替换为的输出
human_time_diff()
函数,格式为“1天”、“2个月”等。输出
human_time_diff()
已被WordPress语言文件翻译,此外,还可以过滤输出。因此,您有两个选项:1)修改
human_time_diff()
函数使用
human_time_diff
过滤器或2)覆盖核心ussing的翻译
gettext
滤器
1-Using human_time_diff
filter. 示例:
add_filter( \'human_time_diff\', function($since, $diff, $from, $to) {
//Here you can build your own human time diff strings
//For example
if ( empty( $to ) ) {
$to = time();
}
$diff = (int) abs( $to - $from );
if ( $diff < HOUR_IN_SECONDS ) {
$since = "WOW, a lot of time ago!!!!";
}
return $since;
}, 10, 4 );
2
Override the translations 使用
gettext
滤器例如:
add_filter( \'gettext\', function($translated, $original, $domain) {
if ( $original == "%s hour" ) {
//fill $translated string with whatever you want
$translated = "Some other string you want instead of original translattion";
}
return $translated;
}, 10, 3 );