summaryrefslogtreecommitdiffstats
path: root/perl-install/lang.pm
blob: 708a6b5da5cfe65c22fef9a1028264dd60da7d3d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
package lang;

use diagnostics;
use strict;

use common qw(:file);
use commands;
use cpio;
use log;

my %languages = (
  "en" => [ "English",   undef,		undef,		"en_US" ],
  "fr" => [ "French",    "lat0-sun16",	"iso15",	"fr_FR" ],
  "de" => [ "German",    "lat0-sun16",	"iso15",	"de_DE" ],
  "hu" => [ "Hungarian", "lat2-sun16",  "iso02",	"hu_HU" ],
  "is" => [ "Icelandic", "lat0-sun16",	"iso15",	"is_IS" ],
  "it" => [ "Italian",   "lat0-sun16",	"iso15",	"it_IT" ],
  "no" => [ "Norwegian", "lat0-sun16",	"iso15",	"no_NO" ],
  "ro" => [ "Romanian",  "lat2-sun16",	"iso02",	"ro_RO" ],
  "sk" => [ "Slovak",    "lat2-sun16",	"iso02",	"sk_SK" ],
  "ru" => [ "Russian",   "Cyr_a8x16", 	"koi2alt",	"ru_SU" ],
"uk_UA"=> [ "Ukrainian", "RUSCII_8x16",	"koi2alt",	"uk_UA" ],
);

1;

sub set {
    my $lang = shift;

    if ($lang) {
	$ENV{LANG} = $ENV{LINGUAS} = $lang;
	$ENV{LC_ALL} = $languages{$lang}->[3];
	my $f = $languages{$lang}->[1]; $f and load_font($f);
    } else {
	# stick with the default (English) */
	delete $ENV{LANG};
	delete $ENV{LC_ALL};
	delete $ENV{LINGUAS};
    }
}

sub write {
    my ($prefix) = @_;
    my $lang = $ENV{LANG};

    $::testing || !$lang and return 0;
    local *F;
    open F, "> $prefix/etc/sysconfig/i18n";

    my $f = sub { $_[1] and print F "$_[0]=$_[1]\n"; };
    &$f("LANG", $lang);
    &$f("LINGUAS", $lang);
    if (my $l = $languages{$lang}) {
	&$f("LC_ALL", $l->{lc_all});
	&$f("SYSFONT", $l->{font});
	&$f("SYSFONTACM", $l->{map});

	my $p = "$prefix/usr/lib/kbd";
	commands::cp("-f", 
		     "$p/consolefonts/$l->{font}.psf.gz", 
		     glob_("$p/consoletrans/$l->{map}*"), 
		     "$prefix/etc/sysconfig/console");
    }
    1;
}

sub load_font {
    my ($fontFile) = @_;
    cpio::installCpioFile("/etc/fonts.cgz", $fontFile, "/tmp/font", 1) or die "error extracting $fontFile from /etc/fonts.cfz";
    c::loadFont('/tmp/font') or log::l("error in loadFont: one of PIO_FONT PIO_UNIMAPCLR PIO_UNIMAP PIO_UNISCRNMAP failed: $!");
    print STDERR "\033(K";
}