WordPress.org

Make WordPress Core

#42241 closed defect (bug) (fixed)

MediaElement should use the correct locale string

Reported by: johnbillion Owned by: westonruter
Milestone: 4.9 Priority: normal
Severity: normal Version: 4.9
Component: Media Keywords: has-patch commit
Focuses: javascript Cc:

Description

The mejsL10n.language property is populated by get_bloginfo( 'language' ). This is incorrect as this data is intended to populate the lang attribute on the html element. get_locale() should be used instead.

Ref: https://core.trac.wordpress.org/browser/trunk/src/wp-includes/script-loader.php?rev=41839&marks=357#L354

See #42071

Attachments (5)

42241.0.diff (986 bytes) - added by westonruter 23 months ago.
42241.1.diff (1.0 KB) - added by westonruter 23 months ago.
mejs-language-not-spanish.png (26.5 KB) - added by westonruter 23 months ago.
42241.2.diff (1.3 KB) - added by westonruter 23 months ago.
Only accept country code in zh-cn
42241.3.diff (1.9 KB) - added by westonruter 23 months ago.
Add mejsL10n global as inline script before the mediaelement-core script instead of after the mediaelement script.

Download all attachments as: .zip

Change History (16)

#1 @rafa8626
23 months ago

  • Keywords has-patch needs-testing added; needs-patch removed

@johnbillion The patch has been submitted in this ticket; please test and let us know if it works for you. Thanks @westonruter

#2 @westonruter
23 months ago

What if the user's language is different from the site's language? Should not the language be determined more dynamically? Should it not be get_user_locale() when in the admin? If the user has selected language A but the site has language B, then they should get MediaElement.js with language A in the Customizer controls but in the customizer preview it should get language B, right?

#3 @ocean90
23 months ago

+1 for get_user_locale().

#4 @westonruter
23 months ago

42241.1.diff uses get_user_locale() when is_admin().

This patch also replaces the locale underscore with a hyphen, so es_MX gets replaced with es-MX. However, I don't really see this working as expected. I changed my locale to Mexican Spanish but then the player still had a “Play” tooltip: mejs-language-not-spanish.png.

It seems like ME.js isn't loading the locale.

#5 @rafa8626
23 months ago

If the translation are not matching the structure described in script-loader.php any changes would be reflected.

@westonruter
23 months ago

Only accept country code in zh-cn

@westonruter
23 months ago

Add mejsL10n global as inline script before the mediaelement-core script instead of after the mediaelement script.

#6 @westonruter
23 months ago

@rafa8626 In order for me to see “Reproducir” when I hover over the play button instead of “Play” I needed to do 42241.3.diff. I found that the mejsL10n global was getting output too late, after mediaelement-and-player.js already ran, and so the data from that variable was not accounted for.

I'm not sure if what I'm doing for mejsL10n.language is right.

#7 @rafa8626
23 months ago

@westonruter I think your approach is right. It's one of those things I didn't consider changing before because of my lack of knowledge in terms of WP processes scripts and variables in that file. My apologies I didn't catch this before.

#8 @westonruter
23 months ago

@rafa8626 What is the purpose of the language passed in to mejsL10n if we're already passing in all of the strings? Is my handling of the language/country code right or even necessary?

#9 @rafa8626
23 months ago

@westonruter It is necessary since the player is relying on that value to be passed to set the translation object correctly and perform the translation in the controls

#10 @westonruter
23 months ago

  • Keywords commit added; needs-testing removed
  • Owner set to westonruter
  • Status changed from new to accepted

#11 @westonruter
23 months ago

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

In 41889:

Media: Use user locale as ME.js language in admin and add mejsL10n inline script before mediaelement-core so WP-exported translation strings are used.

See #39686.
Fixes #42241.

Note: See TracTickets for help on using tickets.