[wp-meta] [Making WordPress.org] #1850: Language suggestor on the beta plugin repository is incorrect

Making WordPress.org noreply at wordpress.org
Thu Feb 16 00:58:58 UTC 2017


#1850: Language suggestor on the beta plugin repository is incorrect
------------------------------+------------------------------------
 Reporter:  Clorith           |       Owner:
     Type:  defect            |      Status:  new
 Priority:  normal            |   Milestone:  Plugin Directory v3.0
Component:  Plugin Directory  |  Resolution:
 Keywords:  has-patch commit  |
------------------------------+------------------------------------
Changes (by SergeyBiryukov):

 * keywords:   => has-patch commit
 * milestone:   => Plugin Directory v3.0


Comment:

 Traced the issue to two bugs in `Locale_Banner` class:
 1. In [source:sites/trunk/wordpress.org/public_html/wp-content/plugins
 /plugin-directory/api/routes/class-locale-banner.php?rev=4223&marks=71#L65
 Locale_Banner::locale_banner()], `$suggest_locales` is an array
 intersection between locales based on the HTTP `Accept-Language` header
 and all available locales. However, due to `$locales_from_header` being
 the second argument, the order of preference is defined by the list of all
 locales (which appears to be randomly returned from DB) instead of the
 locales provided by `Accept-Language` header. As a result, the primary
 language is determined incorrectly (in my case, Russian should be the
 first, but only comes second).
 2. In [source:sites/trunk/wordpress.org/public_html/wp-content/plugins
 /plugin-directory/api/routes/class-locale-
 banner.php?rev=4223&marks=265,266#L238 Locale_Banner::map_locale()], if an
 exact match is not found (e.g. when trying to map `cs_CS` to `cs_CZ`), an
 attempt is made to omit the region and only compare the language part.
 However, what it actually does is return the first non-empty locale from
 the list of all available locales, which happens to be `bg_BG`.

 [attachment:meta-1850.patch] addresses both issues. Here's some debug info
 before the patch:
 {{{
 $http_locales: Array ( [0] => en-US [1] => en [2] => ru [3] => cs )
 $lang: ru, $region: RU
 $mapped: ru_RU
 $lang: cs, $region: CS
 $mapped: bg_BG
 $translated_locales: Array ( [0] => bg_BG [1] => uk [2] => fr_FR [3] =>
 tr_TR [4] => de_DE [5] => ru_RU [6] => cs_CZ )
 $locales_from_header: Array ( [0] => ru_RU [1] => bg_BG )
 array_intersect: Array ( [0] => bg_BG [5] => ru_RU )
 $suggest_locales: Array ( [0] => bg_BG [1] => ru_RU )
 $suggest_named_locales: Array ( [bg_BG] => Bulgarian [ru_RU] => Russian )
 }}}
 and after:
 {{{
 $http_locales: Array ( [0] => en-US [1] => en [2] => ru [3] => cs )
 $lang: ru, $region: RU
 $mapped: ru_RU
 $lang: cs, $region: CS
 $mapped: cs_CZ
 $translated_locales: Array ( [0] => bg_BG [1] => uk [2] => fr_FR [3] =>
 tr_TR [4] => de_DE [5] => ru_RU [6] => cs_CZ )
 $locales_from_header: Array ( [0] => ru_RU [1] => cs_CZ )
 array_intersect: Array ( [0] => ru_RU [1] => cs_CZ )
 $suggest_locales: Array ( [0] => ru_RU [1] => cs_CZ )
 $suggest_named_locales: Array ( [ru_RU] => Russian [cs_CZ] => Czech )
 }}}

--
Ticket URL: <https://meta.trac.wordpress.org/ticket/1850#comment:5>
Making WordPress.org <https://meta.trac.wordpress.org/>
Making WordPress.org


More information about the wp-meta mailing list