SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Enthusiast
    Join Date
    Oct 2004
    Location
    IL
    Posts
    39
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Different languages sorting problem

    I have the following code that creates a list of countries (with links):

    Code:
       <?php foreach ($viewdata['country_list'] as $row){ ?>
            <a href="<?php echo BASEURLPATH?>/country/<?php echo $row->ct_fn?>"><?php _e($row->ct_name,'country');?></a><br />
        <?php } ?>
    The problem is that the data in the DB is in english so for english the sorting is ok. But for other languages (i have translation with .mo files edited by poedit) the translations apear but with an english alphabetical order (and not the order of this language).

    <?php _e($row->ct_name,'country');?> in the code is the country tanslated name and the list should be sorted by it.

    I got an advice that the point is to create a temporary array, with the new strings and resort it:

    Code:
    <?php 
    foreach($viewdata['country_list'] as $row) {
    $newList[$row->ct_fn] = _e($row->ct_name, 'country');
    }
    natsort($newList);
    
    foreach ($newList as $row){ 
    ?>
        <a href="<?php echo BASEURLPATH?>/country/<?php echo $row['ct_fn']; ?>"><?php echo $row['ct_name']; ?></a><br />
    <?php } ?>
    But this code didn't work (it just "spit" the country names without the link structure,as text and not link, and the order is not as it should be - it has the old, english alphabetical order)..

    Please help. Thanks

  2. #2
    SitePoint Evangelist
    Join Date
    Jun 2006
    Location
    Wigan, Lancashire. UK
    Posts
    523
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    If you're trying to sort language texts, then you use sort with the SORT_LOCALE_STRING flag, have used setlocale() to select your language setting.
    ---
    Development Projects:
    PHPExcel
    PHPPowerPoint

  3. #3
    SitePoint Enthusiast
    Join Date
    Oct 2004
    Location
    IL
    Posts
    39
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I don't quite get it (i'm not good at php)..

    What i'm trying to do is sort the countries alphabetically. The names in the DB are in english, ie:

    Albania
    France
    USA
    Zambia

    The site has translations and for different languages it will display the country name translation.

    The problem is that other languages (for example arabic, hebrew, chinese, jap) should have different sorting..

    What it does now is display the list with the translated country names, but with english sorting (because the values in the DB are in english).


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •