#!/usr/bin/perl

use lib qw(/usr/lib/libDrakX);

use standalone;     #- warning, standalone must be loaded very first, for 'explanations'

use interactive;
use common;
use lang;
use any;

my ($klang, $country, $apply);

foreach (@ARGV) {
    $apply = /--apply/;
    $klang = $1 if /--kde_lang=(.*)/;
    $kcountry = uc($1) if /--kde_country=(.*)/;
}
if (defined $klang) {
    $klang or exit;
    my $lang = member($klang, lang::list_langs()) ? $klang : 'en_US';
    my $country = member($kcountry, lang::list_countries()) ? $kcountry : 'US';
    my $locale = lang::read('', $>);
    $klang and $locale->{lang} = $lang;
    $kcountry and $locale->{country} = $country;
    lang::write('', $locale, $>, 'dont_touch_kde_files') if $apply;

    #- help KDE defaulting to the right charset
    print lang::charset2kde_charset(lang::l2charset($lang)), "\n";
} else {
    my $locale = lang::read('', $>);
    my $in = 'interactive'->vnew;
  select_language:
    $locale->{lang} = any::selectLanguage($in, $locale->{lang}) or goto the_end;
    any::selectCountry($in, $locale) or goto select_language;
    lang::write('', $locale, $>);
    if ($>) {
	if (my $wm = any::running_window_manager()) {
	    $in->ask_okcancel('', N("The change is done, but to be effective you must logout"), 1)
	      and any::ask_window_manager_to_logout($wm);
	}
    }
the_end:
    $in->exit(0);
}