WordPress.org

Make WordPress Core

Opened 5 years ago

Closed 3 years ago

#29362 closed enhancement (maybelater)

More development for wp_dropdown_languages()

Reported by: alex-ye Owned by:
Milestone: Priority: normal
Severity: normal Version: 4.0
Component: I18N Keywords: has-patch needs-refresh
Focuses: Cc:

Description

wp_dropdown_languages() a new function in WordPress 4.0 .. It seems that it needs more development.. a better fallback to the $args array and more options and sure thing a WP filter!

Attachments (3)

l10n.patch (1.8 KB) - added by alex-ye 5 years ago.
29362.patch (709 bytes) - added by khromov 5 years ago.
Patch for inconsistent behaviour
29362.2.patch (899 bytes) - added by jubstuff 4 years ago.
Updated patch

Download all attachments as: .zip

Change History (17)

@alex-ye
5 years ago

#1 @alex-ye
5 years ago

I had done a start patch.. I hope it helps :)

#2 @ocean90
5 years ago

wp_dropdown_languages() is WIP, see #15677.

#3 @ocean90
5 years ago

  • Keywords needs-refresh added
  • Version set to 4.0

Patch needs a refresh. I don't think it needs more options, but I'm open for a filter.

#4 @ocean90
5 years ago

  • Keywords has-patch added

#5 follow-up: @khromov
5 years ago

I'd like to second a filter. I author the "English WordPress Admin"* plugin and the introduction of wp_dropdown_languages() has made it so that if you hook on the locale filter to change locale to "en_US", the dropdown will have English selected when the user visits options-general.php, so when the user saves the options, he will have changed his site language by mistake.

It may not actually be right to filter the locale when using wp_dropdown_languages() at all, due to aformentioned issues with the settings form.

#6 @gputignano
5 years ago

Who don't add value for en_US option?
<option value"en_US">en_US</option>

#7 @khromov
5 years ago

  • Keywords dev-feedback added; needs-refresh removed

The code has changed around qite a bit since the patch by @alex-ye, so I made another patch:

Changes

wp_dropdown_languages() is used twice, in option-general.php and in /network/settings.php

In network settings.php, the site locale is correctly fetched from the database. In option-general.php, we call get_locale() instead which doesn't check the database. That's why hooking on the locale filter has unintended consequences, which were outlined earlier here:

https://core.trac.wordpress.org/ticket/29362#comment:5

In the patch, I refactored option-general.php to grab the settings from the database just like the network settings. Feedback appreciated.

PS.
I didn't add a filter, this patch is just for fixing inconsistent behaviour.

@khromov
5 years ago

Patch for inconsistent behaviour

#8 @ocean90
5 years ago

  • Keywords needs-refresh added; dev-feedback removed

get_locale() is used by design in option-general.php because it includes the locale filter, $wp_local_package, WPLANG, and get_option( 'WPLANG' ).

#9 @khromov
5 years ago

@ocean90,

Can you explain a bit more about the thought behind this? Why should the locale filter change the "Site Language" dropdown form? Any plugin hooking on the locale filter would possibly change the value of the dropdown.

#10 in reply to: ↑ 5 @SergeyBiryukov
5 years ago

Replying to khromov:

I'd like to second a filter. I author the "English WordPress Admin"* plugin and the introduction of wp_dropdown_languages() has made it so that if you hook on the locale filter to change locale to "en_US", the dropdown will have English selected when the user visits options-general.php, so when the user saves the options, he will have changed his site language by mistake.

Related: #31318

#11 @64asc
5 years ago

The patch posted above by khormov is still functional to solve the issue as described here and in #31318

@jubstuff
4 years ago

Updated patch

#12 @jubstuff
4 years ago

I tested the patch by khormov and it's working.

I just updated it to reflect the current status of the codebase, because it didn't apply smoothly.

G

This ticket was mentioned in Slack in #core-i18n by swissspidy. View the logs.


3 years ago

#14 @swissspidy
3 years ago

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

So the discussion here about the same problem discussed in #31318, which is essentially a duplicate of #29783.

The idea itself to extend wp_dropdown_languages() is definitely valid on its own, but there doesn't seem to be a need for it at the moment.

Note: See TracTickets for help on using tickets.