0

I want to translate the post meta data (date) in chines language for example, September 13, 2017, should be translated as 2017年9月13. But my code gives it in English. Do you see any error? Please help.

Thank you in advance.

  $time_string = '<time class="entry-date published" datetime="%1$s">%2$s</time>';
        if (get_the_time('U') !== get_the_modified_time('U')) {
            $time_string .= '<time class="updated" datetime="%3$s">%4$s</time>';
        }

        $time_string = sprintf($time_string,
            esc_attr(get_the_date('c')),
            esc_html(get_the_date()),
            esc_attr(get_the_modified_date('c')),
            esc_html(get_the_modified_date())
        );
        printf(__('<span class="posted-on"><a href="%1$s" title="%2$s" rel="bookmark"><i class="fa fa-clock-o"></i> %3$s</a></span>', 'colormag'), 
            esc_url(get_permalink()), esc_attr(get_the_time()), $time_string
        );
| improve this question | | | | |
  • The Codex says to use date_i18n. – Michael Oct 7 '18 at 8:47
  • inside the printf i used __() to localize. But still the same – Shamima Saleem Oct 7 '18 at 13:45
  • How do I use date_i18n ? – Shamima Saleem Oct 7 '18 at 13:57
  • Example is from the Codex: <?php echo date_i18n( get_option( 'date_format' ), strtotime( '11/15-1976' ) ); ?> – user141080 Oct 7 '18 at 14:30
  • May you give an example with printf please – Shamima Saleem Oct 7 '18 at 14:36
0

You don't need to change any code.

get_the_date without an argument will use the date_format option in your WordPress settings. The option F j, Y will substitute F as "September", but if you have a translation of "September" it will be used.

Comments have suggested the use of date_i18n. This is used automatically when you call get_the_date(). Translations of the days and months are in WordPress core and will be used if installed. e.g. The Chinese translation of "September" is here,

However, if you want to print "2017年9月13" I think you will have to set a custom format in your WordPress settings as:

Y年m月d

Under Settings > General > Date Format, select "Custom" and enter that into the field. I've tested that and it formats the Chinese characters just fine.

| improve this answer | | | | |
  • Hi Tim, Thank you very much! Yes date_i18n and i10n are already installed in wordpress as you said. I fixed it from setting after two days. Thank you again! :) – Shamima Saleem Oct 12 '18 at 2:16
  • OK good. Please accept my answer if it's correct. – Tim Oct 12 '18 at 7:36
  • Your answer is correct, How do I accept?I newly joined the Forum, I already voted up, a message fleshed " Your vote is counted but will not appear as your reputation is less. " – Shamima Saleem Oct 12 '18 at 9:56
  • Click the grey tick on the left of the answer, below the up/down arrows – Tim Oct 12 '18 at 12:15

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.