Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I use the birdtips theme and it formats the post date as

$birdtips_posted = date(__('Y. F j.', 'birdtips'),  strtotime(get_the_time("Y-m-d")));

where Y. F j. is already rewritten to reflect my language. As far as I understand, __ is the translation function, but how can I tell Wordpress that I use Hungarian, and will it translate month names automatically, or I should give the names in a .po file?

share|improve this question
add comment

1 Answer 1

up vote 3 down vote accepted

Use date_i18n():

date_i18n( 'Y. F j.',  strtotime( get_the_time( "Y-m-d" ) ) );

From the function’s description:

Retrieve the date in localized format, based on timestamp.

If the locale specifies the locale month and weekday, then the locale will take over the format for the date. If it isn't, then the date format string will be used instead.

A timestamp is a UNIX timestamp, a single number, for example 1366784091.

share|improve this answer
    
I would suggest a slight amendment: date_i18n( get_option( 'date_format' ), strtotime( get_the_time( "Y-m-d" ) ) ); –  vancoder Apr 23 '13 at 21:07
1  
@vancoder This is correct when you don’t know the context. When you change code for a personal use case you don’t need the same format in all places. –  toscho Apr 23 '13 at 21:09
    
Thanks it worked. What does 'based on timestamp' mean? –  Gergely Apr 24 '13 at 6:13
    
@GergelyBuday I made an update to my answer. :) –  toscho Apr 24 '13 at 6:16
    
@toscho: well, I misunderstood the sentence, the date is based on the timestamp, but the localized format is based on the locale. –  Gergely Apr 24 '13 at 6:29
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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