WordPress.org

Make WordPress Core

Opened 9 years ago

Closed 7 years ago

#1540 closed defect (bug) (fixed)

Date format returned by wp_get_archives is not localizable

Reported by: stephenju Owned by: skippy
Milestone: 2.0.6 Priority: lowest
Severity: normal Version: 1.5.1.2
Component: Template Keywords: bg|needs-patch bg|2nd-opinion has-patch
Focuses: Cc:

Description

When using wp_get_archives('type=monthly'), the date string format in the links is hard coded as "month year" not localizable.

Attachments (2)

wp_archive-l10n.patch (913 bytes) - added by drssay 8 years ago.
20xbranchfix.patch (949 bytes) - added by Viper007Bond 7 years ago.
Missing _'s

Download all attachments as: .zip

Change History (13)

comment:1 skippy9 years ago

  • Keywords bg|needs-patch bg|2nd-opinion added
  • Milestone set to 1.6
  • Owner changed from anonymous to skippy
  • Status changed from new to assigned

lines 306 and 309 of wp-includes/template-functions-general.php:

$text = sprintf('%s %d', $month[zeroise($arcresult->month,2)], $arcresult->year);

I don't see a clean way to use the blog's preferred date format; maybe someone else will.

comment:2 nbachiyski9 years ago

We could easily fetch also the unix timestamp of a post in that month from the database and then form the string using the date_i18n function with an internationalized date format:

$text = date_i18n(_('F Y'), $arcresult->post_date);

However, in this situation we could run into some problems. The string marked for internaliozation is 'F Y' (which means: monthname year). For example I want to translate it as '\a\r\c\h\i\v\e \f\o\r\: Y F', but somewhere in Wordpress the same combination 'F Y' is used and it is again internationalized. If the second occurence of 'F Y' is in other context (far apart from archives) then our translation will be totally inadequate.

Actually, using the same string in many contexts is far more general gettext issue and maybe is its greatest flaw...

comment:3 matt8 years ago

  • Milestone changed from 1.6 to 2.1
  • Priority changed from normal to lowest

comment:4 stephenju8 years ago

May I suggest that an additional month date format option to be added in the admin? This will avoid the ambiguity and allow user full control over the format.

Also, I would argue this is a high priority bug since it's the default format of the archive listing and every blog in a language with different date/time format will show it WRONG.

comment:5 drssay8 years ago

Is there any solution of this?
This ticket must fixed quickly for non latin1 user(for example China & Japan & Korean)
I Think below solution is very good solution.

$text = date_i18n(_('F Y'), $arcresult->post_date);

comment:6 drssay8 years ago

second option

$text = sprintf(_('%1$s %2$d'), $month[zeroise($arcresult->month,2)], $arcresult->year);

I think that best solution using smallest edit.

patch attached.

drssay8 years ago

comment:7 rgovostes8 years ago

  • Keywords has-patch added

comment:8 ryan7 years ago

  • Milestone changed from 2.1 to 2.0.6

comment:9 ryan7 years ago

  • Resolution set to fixed
  • Status changed from assigned to closed

(In [4545]) gettext date format strings in wp_get_archives. fixes #1540

comment:10 tai7 years ago

  • Resolution fixed deleted
  • Status changed from closed to reopened

Please put one more underbar like

(__('%1$s %2$d')

, otherwise it doesn't work.

Viper007Bond7 years ago

Missing _'s

comment:11 markjaquith7 years ago

  • Resolution set to fixed
  • Status changed from reopened to closed

(In [4641]) _() => () typo fix. props tai. fixes #1540

Note: See TracTickets for help on using tickets.