translation - How to translate timestamp?

admin2025-06-02  4

This script comes with the theme I purchased that output "Published 3 days ago on Feb 21, 2019" on the article. However I couldn't get the "%s ago" translated, which includes variables of minute(s), hour(s), day(s), etc. What is the best way to translate just these variables?

<?php esc_html_e( 'Published', 'enews' ); ?>
<?php printf(esc_html__( '%s ago', 'enews' ), human_time_diff( get_the_time( 'U' ), current_time( 'timestamp' ) ) );?> 
<?php esc_html_e( 'on', 'enews' ); ?><time itemprop="datePublished" datetime="<?php the_time('Y-m-d'); ?>">
<?php the_time(get_option('date_format')); ?></time>

This script comes with the theme I purchased that output "Published 3 days ago on Feb 21, 2019" on the article. However I couldn't get the "%s ago" translated, which includes variables of minute(s), hour(s), day(s), etc. What is the best way to translate just these variables?

<?php esc_html_e( 'Published', 'enews' ); ?>
<?php printf(esc_html__( '%s ago', 'enews' ), human_time_diff( get_the_time( 'U' ), current_time( 'timestamp' ) ) );?> 
<?php esc_html_e( 'on', 'enews' ); ?><time itemprop="datePublished" datetime="<?php the_time('Y-m-d'); ?>">
<?php the_time(get_option('date_format')); ?></time>
Share Improve this question edited Feb 21, 2019 at 3:01 Buramiko asked Feb 21, 2019 at 2:55 BuramikoBuramiko 112 bronze badges 2
  • Which part is not translated? The "ago" word, or the human time diff part? – Krzysiek Dróżdż Commented Feb 21, 2019 at 6:35
  • There is a example in codex which you can use - codex.wordpress/Function_Reference/human_time_diff – anton Commented Feb 22, 2019 at 19:02
Add a comment  | 

1 Answer 1

Reset to default 0

The "%s" will be replaced by strings translated in the WordPress Core "default" text domain. e.g. "%s mins", "%s hours", etc..

Find these in your core translation files and translate them too.

转载请注明原文地址:http://conceptsofalgorithm.com/Algorithm/1748869789a314400.html

最新回复(0)