[wp-trac] [WordPress Trac] #16530: Implement locale based sorting

WordPress Trac wp-trac at lists.automattic.com
Fri Feb 11 06:43:49 UTC 2011


#16530: Implement locale based sorting
-------------------------+-----------------------------
 Reporter:  cyberskull   |      Owner:
     Type:  enhancement  |     Status:  new
 Priority:  normal       |  Milestone:  Awaiting Review
Component:  I18N         |    Version:  3.1
 Severity:  normal       |   Keywords:
-------------------------+-----------------------------
 While looking at my tags list I noticed that they are not sorted to the
 English locale, but rather to the ordinal value of the characters.

 For example, this is how WordPress currently sorts things:

 * A Book on Software
 * all those things that bug me
 * an apple a day keeps bill gates away
 * books, books and more books!
 * history and stuff
 * lies, damned lies and statistics
 * the history of stuff
 * this tag is totally made up
 * those guys
 * under the bridge
 * zaroo bugs found

 A natural English local sort would be:

 * all those things that bug me
 * an apple a day keeps bill gates away
 * A Book on Software
 * books, books and more books!
 * history and stuff
 * the history of stuff
 * lies, damned lies and statistics
 * this tag is totally made up
 * those guys
 * under the bridge
 * zaroo bugs found

 For English, this can be done with the reasonably simple regex:
 {{{/^((a|the)\s+)?(.+)/i}}} and using the value of {{{$3}}} for the
 comparison.

 I was thinking that a function like either locale_sort(…) or wp_sort(…)
 that would take the same arguments as the built in sort function. When
 invoked, it would get the locale from either the blog or the logged in
 user and if there is a custom sort for that local to then apply it before
 the strings are compared.

 Here is a pseudocode approach:
 {{{
 function local_sort(…)
 {
         local function $locale_format = $locale_sorts{locale()};
         #Gets the appropriate formatter function from a hash of functions
 based
         #on the locale() or returns null/undef.

         if($locale_format)
         {
                 $a = $locale_format($a); #format a
                 $b = $locale_format($b); #format b
         }

         return sort($a, $b);
 }
 }}}

 In the case of English, the function would look something like this:

 {{{
 en_locale_sort_format($string)
 {
         $string =~ /^((a|the)\s+)?(.+)/i;
         return $3;
 }
 }}}

-- 
Ticket URL: <http://core.trac.wordpress.org/ticket/16530>
WordPress Trac <http://core.trac.wordpress.org/>
WordPress blogging software


More information about the wp-trac mailing list