#!/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=(.*)/;
    $country = $1 if /--kde_country=(.*)/;
}
if (defined $klang) {
    $klang or exit;
    my $lang = lang::kde_lang_country2lang($klang, $country);
    lang::write('', $lang, $>, 'dont_touch_kde_files') if $apply;

    #- help KDE defaulting to the right charset
    print lang::charset2kde_charset(lang::lang2charset($lang)), "\n";
} else {
    my ($lang) = lang::read('', $>);

    my $in = 'interactive'->vnew;
    if ($lang = any::selectLanguage($in, $lang)) {
	lang::write('', $lang, $>);
	if ($>) {
	    if (my $wm = any::running_window_manager()) {
		$in->ask_okcancel('', N("The change is done, but to be effective you must logout"), 1)
		  && any::ask_window_manager_to_logout($wm);
	    }
	}
    }
    $in->exit(0);
}