Changeset 3039 for trunk/lib/MT/I18N.pm

Show
Ignore:
Timestamp:
09/08/08 08:16:00 (15 months ago)
Author:
fumiakiy
Message:

Moved languages_list method from MT::App::CMS to MT::I18N so it can be used from other apps like Wizard.

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • trunk/lib/MT/I18N.pm

    r1235 r3039  
    7272} 
    7373 
     74sub languages_list { 
     75    my ( $app, $curr ) = @_; 
     76 
     77    $app ||= MT->instance; 
     78    my $langs = $app->supported_languages; 
     79    my @data; 
     80    $curr ||= $app->config('DefaultLanguage'); 
     81    $curr = 'en-us' if ( lc($curr) eq 'en_us' ); 
     82    my $curr_lang = $app->current_language; 
     83    for my $tag ( keys %$langs ) { 
     84        ( my $name = $langs->{$tag} ) =~ s/\w+ English/English/; 
     85        $app->set_language($tag); 
     86        my $row = { l_tag => $tag, l_name => $app->translate($name) }; 
     87        $row->{l_selected} = 1 if $curr eq $tag; 
     88        push @data, $row; 
     89    } 
     90    $app->set_language($curr_lang); 
     91    [ sort { $a->{l_name} cmp $b->{l_name} } @data ]; 
     92} 
     93 
    74941; 
    7595__END__ 
     
    130150package for the current language. 
    131151 
     152=head2 languages_list($app, $current) 
     153 
     154Returns a reference to an array of hashes which contains necessary 
     155data to render a dropdown list of languages that MT supports. 
     156Dropdown lists appear on User Profile, System Settings, and the 
     157start page of the wizard, among others. 
     158 
    132159=head1 LICENSE 
    133160