[tldoc] Sorting order

Mojca Miklavec mojca.miklavec.lists at gmail.com
Fri Jun 17 16:49:36 CEST 2011


On Wed, Jun 15, 2011 at 03:03, Norbert Preining <preining at logic.at> wrote:
> On Di, 14 Jun 2011, Karl Berry wrote:
>> What Norbert did (at my suggestion, don't blame him :) was simply to use
>> Perl sort/cmp on the translated strings (instead of the English
>> strings).
>>
>> We are well aware that the collation order will therefore be incorrect.
>
> According to perl docs of sort:
>               When "use locale" is in effect, "sort LIST" sorts LIST
>               according to the current collation locale.  See perllocale.
> I am not sure, but maybe we can simply add
>        use locale;
> in the installer? I have no idea what else might be effected, though ;-)

This was the only example that I was able to come up with (but the
library wasn't installed by default which is probably a problem; and
the module doesn't provide Serbian collate rules for example):

use encoding 'utf8';
use Unicode::Collate::Locale;

$Collator = Unicode::Collate::Locale->new(locale => "sl");
my @sorttest = qw(cd ab ča št de tu si);

@sorted = $Collator->sort(@sorttest);
foreach my $a ( @sorted ) {
    print "$a\n";
}

The following without any exotic libraries didn't work:

use encoding 'utf8';
use locale;
use POSIX qw(locale_h);

use warnings;
use strict;

setlocale(LC_CTYPE, "sl_SI.UTF-8");
my @sorttest = qw(cd ab ča št de tu si);
@sorttest = sort(@sorttest);

foreach my $a ( @sorttest ) {
    print "$a\n";
}

print "\n";

print +(sort grep /\w/, map { chr } 0..255), "\n";



More information about the tldoc mailing list