WordPress.org

Ready to get started?Download WordPress

Forums

How to change the human-time-diff post-date language? (3 posts)

  1. okaprasumba
    Member
    Posted 1 year ago #

    i use human-time-diff postdate for my website and it will change my post date into for example : 1 day ago. i want to translate the 'day' into my language (indonesian), i already change my wp to indonesian language but it didnt change the post date. i tried to open the locale.php but i cant find it there too. where i can change the language?

  2. David Choi
    Member
    Posted 1 year ago #

    That function is located in

    wp-includes/formatting.php

    around line 2101, and looks like it's hard coded into the code as you can see after %s

    function human_time_diff( $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 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 >= DAY_IN_SECONDS ) {
                    $days = round( $diff / DAY_IN_SECONDS );
                    if ( $days <= 1 ) {
                            $days = 1;
                    }
                    $since = sprintf( _n( '%s day', '%s days', $days ), $days );
            }
            return $since;
    }

    So you have to manually edit this file.

  3. Henry
    Member
    Posted 9 months ago #

    you could copy the function to your theme's functions.php file, rename it and then change the language. That's what i did.

Topic Closed

This topic has been closed to new replies.

About this Topic