[wp-trac] [WordPress Trac] #57945: Locale bug in short-circuited WP REST API request via rest_pre_dispatch?
WordPress Trac
noreply at wordpress.org
Mon Mar 20 00:13:09 UTC 2023
#57945: Locale bug in short-circuited WP REST API request via rest_pre_dispatch?
-------------------------------------+------------------------------
Reporter: joeyojoeyo12 | Owner: (none)
Type: defect (bug) | Status: new
Priority: normal | Milestone: Awaiting Review
Component: REST API | Version: 6.1.1
Severity: normal | Resolution:
Keywords: reporter-feedback close | Focuses:
-------------------------------------+------------------------------
Comment (by joeyojoeyo12):
My current workaround is this right before returning a {{{WP_Error}}}
instance holding a {{{__('localized message','my-plugin')}}} as its error
message, within a callback hooked to {{{rest_pre_dispatch}}}, for the
error message to get displayed properly:
{{{
$current_locale = get_locale(); // retrieved from the client as explained
above, so correct
$mo = new MO();
if ($mo->import_from_file(WP_CONTENT_DIR . "/languages/plugins/my-
plugin-$current_locale.mo")) {
$translations[$current_locale] = $mo->entries;
}
echo $translations[$current_locale]['localized message']->translations[0];
}}}
But this seems like a horrible hack to me..?
[https://stackoverflow.com/questions/31778466/get-translations-for-a
-string-in-wordpress]
--
Ticket URL: <https://core.trac.wordpress.org/ticket/57945#comment:3>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list