Have an idea?

Visit Sawtooth Software Feedback to share your ideas on how we can improve our products.

Sorting items in a list according to locale

Many studies these days are translated into multiple languages and survey authors want to arrange their lists according to the new language
like sorting a list according to the translated language.

Here is some code that I did for some one that will take the items from a parent list and add them in ascending order occording to a specified language collation locale.  
For this to work you will need to make sure that you are using at least perl 5.10.  
Please note there are two places in the following code that you will need to substitute your list name and desired language abbreviation.
Begin Unverified Perl
use POSIX qw(locale_h);
my $old_locale = setlocale(LC_CTYPE, '{insert_lang_code_here}');

my $ParentList = '{parent_list_name}';
my $strItems = LISTLABELSARRAY($ParentList);
my @ListItems = @{eval $strItems};
my $value = 1;
@ListItems = map { { 'label' => $_, 'value' => $value++ } } @ListItems;
@ListItems = sort { $a->{'label'} cmp $b->{'label'} } @ListItems;

for (my $i = 0; $i < @ListItems; $i++)
{
    ADD($ParentList, $ListItems[$i]->{'value'});
}
setlocale(LC_CTYPE, $old_locale);
End Unverified



On the line that reads
setlocale(LC_CTYPE, '{insert_lang_code_here}');

where it says {insert_lang_code_here} use the language codes defined here
http://www.loc.gov/standards/iso639-2/php/code_list.php in the ISO 639-1 Code column or ISO 639-2 Code column

So if I wanted to sort my items ascendingly in the french language because my parent list was in french, I would change the line to read
setlocale(LC_CTYPE, "fr");

If the parent list language was traditional chinese, then I would change the line to read
setlocale(LC_CTYPE, "zh");
asked Feb 14, 2013 by Mike Lodder Gold (23,410 points)

Your answer

Please only use this to answer the original question. Otherwise please use comments.
Your name to display (optional):
Privacy: Your email address will only be used for sending these notifications.
Anti-spam verification:

To avoid this verification in future, please log in or register.
...