WordPress.org

Make WordPress Core

Opened 11 months ago

Last modified 11 months ago

#41539 new defect (bug)

Dates not localized in admin-ajax when logged in

Reported by: philjms Owned by:
Milestone: Awaiting Review Priority: normal
Severity: normal Version: 4.7.4
Component: I18N Keywords: close
Focuses: Cc:

Description

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 (1)

#1 @swissspidy
11 months 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 https://make.wordpress.org/core/2016/11/07/user-admin-languages-and-locale-switching-in-4-7/ for some explanation and examples.

Note: See TracTickets for help on using tickets.