How to use Internationalized human_time_diff() function in Chinese?

Looking at https://codex.wordpress.org/Function_Reference/human_time_diff

I’m using an English version of WordPress.

In my theme template, I would like to define custom text of min, hour, day, week, month, year in Chinese using human_time_diff() when looping through posts.

According to the instruction in the Codex documentation:

<?php
    printf( _x( '%s ago', '%s = human-readable time difference',
    'your-text-domain' ), human_time_diff( get_the_time( 'U' ),
    current_time( 'timestamp' ) ) );
?>

I still don’t know how to make the implementation to do the swap using the code above. eg.

min -> 分鐘
hour -> 小時
dat -> 天
week -> 週
month -> 月
year -> 年

ago part should be straight forward.

Is there an example that can demonstrate how it works?

Also, do I need to worry about plurals in English?

Solutions Collecting From Web of "How to use Internationalized human_time_diff() function in Chinese?"

If you check out the source of human_time_diff:

if ( $diff < HOUR_IN_SECONDS ) {
    $mins = round( $diff / MINUTE_IN_SECONDS );
    if ( $mins <= 1 )
        $mins = 1;
    /* translators: min=minute */
    $since = sprintf( _n( '%s min', '%s mins', $mins ), $mins );
} elseif ( $diff < DAY_IN_SECONDS && $diff >= HOUR_IN_SECONDS ) {
    $hours = round( $diff / HOUR_IN_SECONDS );
    if ( $hours <= 1 )
        $hours = 1;
    $since = sprintf( _n( '%s hour', '%s hours', $hours ), $hours );
} elseif ( $diff < WEEK_IN_SECONDS && $diff >= DAY_IN_SECONDS ) {
    $days = round( $diff / DAY_IN_SECONDS );
    if ( $days <= 1 )
        $days = 1;
    $since = sprintf( _n( '%s day', '%s days', $days ), $days );
} elseif ( $diff < MONTH_IN_SECONDS && $diff >= WEEK_IN_SECONDS ) {
    $weeks = round( $diff / WEEK_IN_SECONDS );
    if ( $weeks <= 1 )
        $weeks = 1;
    $since = sprintf( _n( '%s week', '%s weeks', $weeks ), $weeks );
} elseif ( $diff < YEAR_IN_SECONDS && $diff >= MONTH_IN_SECONDS ) {
    $months = round( $diff / MONTH_IN_SECONDS );
    if ( $months <= 1 )
        $months = 1;
    $since = sprintf( _n( '%s month', '%s months', $months ), $months );
} elseif ( $diff >= YEAR_IN_SECONDS ) {
    $years = round( $diff / YEAR_IN_SECONDS );
    if ( $years <= 1 )
        $years = 1;
    $since = sprintf( _n( '%s year', '%s years', $years ), $years );
}

As you can see, just translate the %s min, %s mins etc. strings.

The full solution that works for me without modifying the WordPress core is to clone the human_time_diff() function and place it inside functions.php as a renamed human_time_diff_chinese(), then swap all occurrence of human_time_diff() function with this new human_time_diff_chinese() function.

function human_time_diff_chinese( $from, $to = '' ) {
  if ( empty( $to ) ) {
    $to = time();
  }

  $diff = (int) abs( $to - $from );

  if ( $diff < HOUR_IN_SECONDS ) {
    $mins = round( $diff / MINUTE_IN_SECONDS );
    if ( $mins <= 1 )
      $mins = 1;
    /* translators: min=minute */
    $since = sprintf( _n( '%s 分鐘', '%s 分鐘', $mins ), $mins );
  } elseif ( $diff < DAY_IN_SECONDS && $diff >= HOUR_IN_SECONDS ) {
    $hours = round( $diff / HOUR_IN_SECONDS );
    if ( $hours <= 1 )
      $hours = 1;
    $since = sprintf( _n( '%s 小時', '%s 小時', $hours ), $hours );
  } elseif ( $diff < WEEK_IN_SECONDS && $diff >= DAY_IN_SECONDS ) {
    $days = round( $diff / DAY_IN_SECONDS );
    if ( $days <= 1 )
      $days = 1;
    $since = sprintf( _n( '%s 天', '%s 天', $days ), $days );
  } elseif ( $diff < MONTH_IN_SECONDS && $diff >= WEEK_IN_SECONDS ) {
    $weeks = round( $diff / WEEK_IN_SECONDS );
    if ( $weeks <= 1 )
      $weeks = 1;
    $since = sprintf( _n( '%s 週', '%s 週', $weeks ), $weeks );
  } elseif ( $diff < YEAR_IN_SECONDS && $diff >= MONTH_IN_SECONDS ) {
    $months = round( $diff / MONTH_IN_SECONDS );
    if ( $months <= 1 )
      $months = 1;
    $since = sprintf( _n( '%s 個月', '%s 個月', $months ), $months );
  } elseif ( $diff >= YEAR_IN_SECONDS ) {
    $years = round( $diff / YEAR_IN_SECONDS );
    if ( $years <= 1 )
      $years = 1;
    $since = sprintf( _n( '%s 年', '%s 年', $years ), $years );
  }

  return apply_filters( 'human_time_diff_chinese', $since, $diff, $from, $to );
}