REST API: Render response in user locale with ?_locale=user.

Introduces new `determine_locale()` function for deciding the proper locale to use for a response. Default value is `get_user_locale()` in the admin, and `get_locale()` on the frontend. Because REST API requests are considered frontend requests, `?_locale=user` can be used to render the response in the user's locale.

Also updates `wp-login.php?wp_lang` implementation to benefit from this abstraction.

Merges [43776] from the 5.0 branch to trunk.

Props flixos90, mnelson4, swissspidy, TimothyBlynJacobs.
Fixes #44758.


git-svn-id: https://develop.svn.wordpress.org/trunk@44134 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Jeremy Felt
2018-12-14 01:31:27 +00:00
parent 981678ba36
commit f7b3c32a57
5 changed files with 57 additions and 36 deletions

View File

@@ -954,7 +954,7 @@ function wp_default_scripts( &$scripts ) {
'var mejsL10n = %s;',
wp_json_encode(
array(
'language' => strtolower( strtok( is_admin() ? get_user_locale() : get_locale(), '_-' ) ),
'language' => strtolower( strtok( determine_locale(), '_-' ) ),
'strings' => array(
'mejs.install-flash' => __( 'You are using a browser that does not have Flash player enabled or installed. Please turn on your Flash player plugin or download the latest version from https://get.adobe.com/flashplayer/' ),
'mejs.fullscreen-off' => __( 'Turn off Fullscreen' ),