Make WordPress Core

Opened 6 years ago

Closed 3 years ago

#41539 closed defect (bug) (wontfix)

Dates not localized in admin-ajax when logged in

Reported by: philjms's profile philjms Owned by:
Milestone: Priority: normal
Severity: normal Version: 4.7.4
Component: I18N Keywords: close
Focuses: Cc:


I have a localized theme set to Spanish language. Everything works fine.

I change my user profile language to English.

Now, when logged in, the method called by admin-ajax returns the dates in English, not Spanish. Everything else remains in Spanish.

When not logged in, or when my user profile language is set to Spanish, the method called by admin-ajax returns the dates in Spanish, as expected.

I'm assuming that admin-ajax is defaulting to the user language instead of the theme language. This is a problem if you are trying to develop themes in languages other than your own.

It is also a problem because there is no obvious way to fix this. I've tried many ways to localize the dates manually in the method called by admin-ajax, but nothing works. I've even added a load_textdomain() call before the dates, but that doesn't localize them either.

Change History (2)

#1 @swissspidy
6 years ago

  • Keywords close added

Hey there,

As the name and file location implies, admin-ajax.php runs within admin context, where everything is displayed in the user's locale.

If you want to use strings in a different locale, use switch_to_locale(). See for some explanation and examples.

#2 @hellofromTonya
3 years ago

  • Milestone Awaiting Review deleted
  • Resolution set to wontfix
  • Status changed from new to closed

Closing this ticket as it appears not to be a bug but rather the way it works, see @ swissspidy note above, and the age of the ticket since marked as a close candidate.

Note: See TracTickets for help on using tickets.