home *** CD-ROM | disk | FTP | other *** search
/ Inter.Net 55-2 / Inter.Net 55-2.iso / Mandrake / mdkinst / usr / bin / perl-install / lang.pm < prev    next >
Encoding:
Perl POD Document  |  2000-01-12  |  9.5 KB  |  337 lines

  1. package lang;
  2.  
  3.  
  4.  
  5.  
  6.  
  7.  
  8.  
  9. use common qw(:common :file :system);
  10. use commands;
  11. use log;
  12.  
  13.  
  14.  
  15.  
  16.  
  17.  
  18.  
  19. my %languages = (
  20.   'en'  => [ 'English (US)',        undef,          'en', 'en_US:en' ],
  21. 'en_GB' => [ 'English (UK)',        'iso-8859-1', 'en', 'en_GB:en' ],
  22.   'af'  => [ 'Afrikaans',        'iso-8859-1', 'af', 'af:en_ZA' ],
  23.  
  24.   'bg'  => [ 'Bulgarian',        'cp1251',     'bg', 'bg' ],
  25.   'br'  => [ 'Brezhoneg',        'iso-8859-1', 'br', 'br:fr_FR:fr' ],
  26.   'ca'  => [ 'Catalan',            'iso-8859-1', 'ca', 'ca:es_ES:es:fr_FR:fr' ],
  27.   'cs'  => [ 'Czech',            'iso-8859-2', 'cs', 'cs' ],
  28.   'cy'  => [ 'Cymraeg (Welsh)',        'iso-8859-14','cy', 'cy:en_GB:en' ],
  29.   'da'  => [ 'Danish',            'iso-8859-1', 'da', 'da' ],        
  30. 'de_AT' => [ 'German (Austria)',    'iso-8859-1', 'de', 'de_AT:de' ],
  31. 'de_DE' => [ 'German (Germany)',    'iso-8859-1', 'de', 'de_DE:de' ],
  32.   'el'  => [ 'Greek',                   'iso-8859-7', 'el', 'el' ],
  33.   'eo'  => [ 'Esperanto',        'iso-8859-3', 'eo', 'eo' ],
  34. 'es_AR' => [ 'Spanish (Argentina)',    'iso-8859-1', 'es', 'es_AR:es_UY:es:es_ES' ],
  35. 'es_ES' => [ 'Spanish (Spain, modern sorting)',    'iso-8859-1', 'es', 'es' ],
  36. 'es@tradicional' => [ 'Spanish (Spain, traditional sorting)', 'iso-8859-1', 'es', 'es' ],
  37. 'es_MX' => [ 'Spanish (Mexico)',    'iso-8859-1', 'es', 'es_MX:es:es_ES' ],
  38.   'et'  => [ 'Estonian',        'iso-8859-15','et', 'et' ],
  39.   'eu'  => [ 'Euskara (Basque)',    'iso-8859-1', 'eu', 'eu:es_ES:fr_FR:es:fr' ],
  40.  
  41.   'fi'  => [ 'Suomi (Finnish)',        'iso-8859-1', 'fi', 'fi' ],
  42. 'fr_CA' => [ 'French (Canada)',        'iso-8859-1', 'fr', 'fr_CA:fr' ],
  43. 'fr_FR' => [ 'French (France)',        'iso-8859-1', 'fr', 'fr_FR:fr' ],
  44.  
  45.   'ga'  => [ 'Gaeilge (Irish)',        'iso-8859-14','ga', 'ga:en_IE:en' ],
  46.  
  47.   'gl'  => [ 'Galician',        'iso-8859-1', 'gl', 'gl:es_ES:pt_PT:pt_BR:es:pt' ],
  48.  
  49.  
  50.   'hr'  => [ 'Croatian',        'iso-8859-2', 'hr', 'hr' ],
  51.   'hu'  => [ 'Hungarian',         'iso-8859-2', 'hu', 'hu' ],
  52.   'hy'  => [ 'Armenian',                'armscii-8',  'hy', 'hy' ],
  53.  
  54.  
  55.   'id'  => [ 'Indonesian',        'iso-8859-1', 'id', 'id:in_ID' ],
  56.   'is'  => [ 'Icelandic',         'iso-8859-1', 'is', 'is' ],
  57.   'it'  => [ 'Italian',           'iso-8859-1', 'it', 'it_IT:it' ],
  58.   'ja'  => [ 'Japanese',        'jisx0208',   'ja', 'ja_JP.ujis:ja' ],
  59.   'ka'  => [ 'Georgian',                'georgian-academy', 'ka', 'ka' ],
  60.  
  61.   'ko'  => [ 'Korean',                  'ksc5601',    'ko', 'ko' ],
  62.  
  63.   'lt'  => [ 'Lithuanian',        'iso-8859-13','lt', 'lt' ],
  64.  
  65.  
  66.  
  67.  
  68.   'nl'  => [ 'Dutch (Netherlands)',    'iso-8859-1', 'nl', 'nl_NL:nl' ],
  69.   'no'  => [ 'Norwegian (Bokmaal)',    'iso-8859-1', 'no', 'no:no@nynorsk' ],
  70. 'no@nynorsk' => [ 'Norwegian (Nynorsk)','iso-8859-1', 'no', 'no@nynorsk:no' ],
  71.  
  72.   'pl'  => [ 'Polish',            'iso-8859-2', 'pl', 'pl' ],
  73. 'pt_BR' => [ 'Portuguese (Brazil)',    'iso-8859-1', 'pt_BR', 'pt_BR:pt_PT:pt' ],
  74. 'pt_PT' => [ 'Portuguese (Portugal)',    'iso-8859-1', 'pt', 'pt_PT:pt:pt_BR' ],
  75.   'ro'  => [ 'Romanian',          'iso-8859-2', 'ro', 'ro' ],
  76.   'ru'  => [ 'Russian',           'koi8-r',     'ru', 'ru' ],
  77.   'sk'  => [ 'Slovak',            'iso-8859-2', 'sk', 'sk' ],
  78.   'sl'  => [ 'Slovenian',        'iso-8859-2', 'sl', 'sl' ],
  79.   'sp'  => [ 'Serbian (Cyrillic)',    'iso-8859-5', 'sp', 'sp:sr' ],
  80.   'sr'  => [ 'Serbian (Latin)',        'iso-8859-2', 'sr', 'sr' ],
  81.   'sv'  => [ 'Swedish',            'iso-8859-1', 'sv', 'sv' ],
  82.   'th'  => [ 'Thai',                    'tis620',     'th', 'th' ],
  83.   'tr'  => [ 'Turkish',             'iso-8859-9', 'tr', 'tr' ],
  84.   'uk'  => [ 'Ukrainian',         'koi8-u',     'uk', 'uk' ],
  85.   'vi'  => [ 'Vietnamese (TCVN)',       'tcvn',       'vi',
  86.                     'vi_VN.tcvn:vi_VN.tcvn-5712:vi' ],
  87. 'vi_VN.viscii' => [ 'Vietnamese (VISCII)','viscii',   'vi',
  88.                         'vi_VN.viscii:vi_VN.tcvn-viscii1.1-1:vi' ],
  89.   'wa'  => [ 'Walon',             'iso-8859-1', 'wa', 'wa:fr_BE:fr' ],
  90. 'zh_TW.Big5' => [ 'Chinese (Big5)',     'Big5', 'zh_TW.Big5', 'zh_TW.Big5:zh_TW.big5:zh' ],
  91. 'zh_CN' => [ 'Chinese (GuoBiao)',    'gb2312', 'zh_CN', 'zh_CN:zh_CN.GB2312:zh_CN.gb2312:zh' ],
  92. );
  93.  
  94. my %xim = (
  95.   'zh_TW.Big5' => { 
  96.     ENC => 'big5',
  97.     XIM => 'xcin',
  98.     XMODIFIERS => '"@im=xcin"',
  99.   },
  100.   'zh_CN' => {
  101.     ENC => 'gb',
  102.     XIM => 'xcin-zh_CN',
  103.     XMODIFIERS => '"@im=xcin-zh_CN"',
  104.   },
  105.   'ko' => {
  106.     ENC => 'kr',
  107.     XIM => 'Ami',
  108.     XMODIFIERS => '"@im=Ami"',
  109.   },
  110.   'ja' => {
  111.     ENC => 'eucj',
  112.     XIM => 'kinput2',
  113.     XMODIFIERS => '"@im=kinput2"',
  114.   }
  115. );
  116.  
  117. sub std2 { "-mdk-helvetica-medium-r-normal-*-*-$_[1]-*-*-*-*-$_[0]" }
  118. sub std_ { std2($_[0], 100), std2($_[0], 100) }
  119. sub std  { std2($_[0], 100), std2($_[0],  80) }
  120.  
  121.  
  122.  
  123. my %charsets = (
  124.   "armscii-8"  => [ "arm8",        "armscii8.uni",    "trivial.trans", 
  125.     std_("armscii-8") ],
  126.  
  127.   "Big5"       => [ undef,        undef,        undef,
  128.     "-*-*-*-*-*-*-*-*-*-*-*-*-big5-0" ],
  129.   "gb2312"     => [ undef,        undef,        undef,
  130.         "-*-*-*-*-*-*-*-*-*-*-*-*-gb2312.1980-0" ],
  131.   "georgian-academy" => [ "t_geors",    "geors.uni",    "trivial.trans",
  132.     "-*-*-*-*-*-*-*-*-*-*-*-*-georgian-academy" ],
  133.   "georgian-ps" => [ "t_geors",        "geors.uni",    "geors_to_geops.trans",
  134.     "-*-*-*-*-*-*-*-*-*-*-*-*-georgian-academy" ],
  135.   "iso-8859-1" => [ "lat0-sun16",    undef,        "iso15",
  136.     std("iso8859-1") ],
  137.   "iso-8859-2" => [ "lat2-sun16",    undef,        "iso02",
  138.     std("iso8859-2") ],
  139.   "iso-8859-3" => [ "iso03.f16",    undef,        "iso03",
  140.     std_("iso8859-3") ],
  141.   "iso-8859-4" => [ "lat4u-16",        undef,        "iso04",
  142.     std_("iso8859-4") ],
  143.   "iso-8859-5" => [ "iso05.f16",    "iso05",    "trivial.trans",
  144.     std("iso8859-5") ],
  145.  
  146.  
  147.   "iso-8859-6" => [ "iso06.f16",    "iso06",    "trivial.trans",
  148.     std_("iso8859-6") ],
  149.   "iso-8859-7" => [ "iso07.f16",    "iso07",    "trivial.trans",
  150.     std_("iso8859-7") ],
  151.  
  152.  
  153.   "iso-8859-8" => [ "iso08.f16",    "iso08",    "trivial.trans",
  154.     std_("iso8859-8") ],
  155.   "iso-8859-9" => [ "iso09.f16",    "iso09",    "trivial.trans",
  156.     std("iso8859-9") ],
  157.   "iso-8859-13" => [ "tlat7",        "iso01",    "trivial.trans",
  158.     std_("iso8859-13") ],
  159.   "iso-8859-14" => [ "tlat8",        "iso01",    "trivial.trans",
  160.     std_("iso8859-14") ],
  161.   "iso-8859-15" => [ "lat0-sun16",    undef,        "iso15",
  162.     std("iso8859-15") ],
  163.  
  164.   "jisx0208"   => [ undef,        undef,        "trivial.trans",
  165.     "-*-*-*-*-*-*-*-*-*-*-*-*-jisx*.*-0" ],
  166.   "koi8-r"     => [ "koi8-8x16",    "koi8-r",    "trivial.trans",
  167.     std("koi8-r") ],
  168.   "koi8-u"     => [ "koi8u_8x16",    "koi8-r",    "trivial.trans",
  169.     std("koi8-u") ],
  170.   "cp1251"     => [ "iso05.f16",    "iso05",    "iso05_to_cp1251.trans",
  171.     std_("microsoft-cp1251") ],
  172.  
  173.   "ksc5601"    => [ undef,        undef,        undef,
  174.     "-*-*-*-*-*-*-*-*-*-*-*-*-ksc5601.1987-*" ],
  175.  
  176.   "tis620"     => [ undef,        undef,        "trivial.trans",
  177.     std2("tis620.2533-1",120) ],
  178.   "tcvn"       => [ "tcvn8x16",        "tcvn",        "trivial.trans",
  179.     std2("tcvn-5712", 130), std2("tcvn-5712", 100) ],
  180.   "viscii"     => [ "viscii10-8x16",    "viscii.uni",    "viscii1.0_to_viscii1.1.trans",
  181.     "-*-*-*-*-*-*-*-*-*-*-*-*-viscii1.1-1" ],
  182.  
  183.  
  184.   "isiri-3342" => [ undef,        undef,        "trivial.trans",
  185.     "-*-*-*-*-*-*-*-*-*-*-*-*-isiri-3342" ],
  186. );
  187.  
  188.  
  189.  
  190.  
  191.  
  192. sub list { map { $_->[0] } values %languages }
  193. sub lang2text { $languages{$_[0]} && $languages{$_[0]}[0] }
  194. sub text2lang {
  195.     my ($t) = @_;
  196.     while (my ($k, $v) = each %languages) {
  197.     lc($v->[0]) eq lc($t) and return $k;
  198.     }
  199.     die "unknown language $t";
  200. }
  201.  
  202. sub set {
  203.     my ($lang, $prefix) = @_;
  204.  
  205.     if ($lang) {
  206.     $ENV{LC_ALL}    = $lang;
  207.     $ENV{LANG}      = $languages{$lang}[2];
  208.     $ENV{LANGUAGE}  = $languages{$lang}[3];
  209.     $ENV{LINGUAS}   = $languages{$lang}[3];
  210.  
  211.     local $_ = $languages{$lang}[1];
  212.     s/iso-8859-1$/iso-8859-15/;
  213.     s/iso-/iso/;
  214.     s/koi8-.*/koi8/;
  215.     s/cp1251/mscp1251/;
  216.     
  217.     commands::install_cpio("/usr/share/locale", $languages{$lang}[2], "misc", $_);
  218.     } else {
  219.     # stick with the default (English) */
  220.     delete $ENV{LANG};
  221.     delete $ENV{LC_ALL};
  222.     delete $ENV{LINGUAS};
  223.     }
  224. }
  225.  
  226. sub write {
  227.     my ($prefix) = @_;
  228.     my $lang = $ENV{LC_ALL};
  229.  
  230.     $lang or return;
  231.  
  232.     my $h = { LC_ALL => $lang };
  233.     if (my $l = $languages{$lang}) {
  234.     add2hash $h, { LANG => $l->[2], LANGUAGE => $l->[2], LINGUAS => $l->[3] };
  235.  
  236.     my $c = $charsets{$l->[1] || ''};
  237.     if ($c && $c->[0] && $c->[1]) {        
  238.         add2hash $h, { SYSFONT => $c->[0], UNIMAP => $c->[1], SYSFONTACM => $c->[2] };
  239.  
  240.         my $p = "$prefix/usr/lib/kbd";
  241.         eval {
  242.         commands::cp("-f",
  243.              "$p/consolefonts/$c->[0].psf.gz",
  244.              glob_("$p/consoletrans/$c->[1]*"),
  245.              glob_("$p/consoletrans/$c->[2]*"),
  246.              "$prefix/etc/sysconfig/console");
  247.         };
  248.         $@ and log::l("missing console $c->[0], $c->[1], $c->[2]");
  249.     }
  250.     add2hash $h, $xim{$lang};
  251.     }
  252.     setVarsInSh("$prefix/etc/sysconfig/i18n", $h);
  253. }
  254.  
  255. sub load_po($) {
  256.     my ($lang) = @_;
  257.     my ($s, $from, $to, $state, $fuzzy);
  258.  
  259.     $s .= "package po::I18N;\n";
  260.     $s .= "no strict;\n";
  261.     $s .= "\%{'$lang'} = (";
  262.  
  263.     my $f; -e ($f = "$_/po/$lang.po") and last foreach @INC;
  264.     unless (-e $f) {
  265.     -e ($f = "$_") and last foreach @INC;
  266.     $f = commands::install_cpio("$f/po", "$lang.po");
  267.     }
  268.     local *F;
  269.     unless (-e $f) {
  270.     -e ($f = "$_/po/$lang.po.bz2") and last foreach @INC;
  271.     if (-e $f) {
  272.         open F, "bzip2 -dc $f 2>/dev/null |";
  273.     } else {
  274.         -e ($f = "$_/po.cz2") and last foreach @INC;
  275.         $f =~ s/\.cz2//;
  276.         log::l("trying to load $lang.po from $f");
  277.         open F, "extract_archive $f '' $lang.po 2>/dev/null |";
  278.     }
  279.     } else {
  280.     open F, $f; 
  281.     }
  282.     foreach (<F>) {
  283.     /^msgstr/ and $state = 1;
  284.     /^msgid/  && !$fuzzy and $state = 2;
  285.  
  286.     if (/^(#|$)/ && $state != 3) {
  287.         $state = 3;
  288.         if (my @l = $to =~ /%(\d+)\$/g) {
  289.         $to =~ s/%(\d+)\$/%/g;
  290.         $to = qq([ "$to", ) . join(",", map { $_ - 1 } @l) . " ],";
  291.         } else {
  292.         $to = qq("$to");
  293.         }
  294.         $s .= qq("$from" => $to,\n) if $from;
  295.         $from = $to = '';
  296.     }
  297.     $to .= (/"(.*)"/)[0] if $state == 1;
  298.     $from .= (/"(.*)"/)[0] if $state == 2;
  299.  
  300.     $fuzzy = /^#, fuzzy/;
  301.     }
  302.     $s .= ");";
  303.     no strict "vars";
  304.     eval $s;
  305.     !$@;
  306. }
  307.  
  308.  
  309.  
  310.  
  311.  
  312.  
  313.  
  314.  
  315.  
  316.  
  317.  
  318.  
  319.  
  320.  
  321.  
  322.  
  323.  
  324.  
  325. sub get_x_fontset {
  326.     my ($lang) = @_;
  327.  
  328.     my $l = $languages{$lang}  or return;
  329.     my $c = $charsets{$l->[1]} or return;
  330.     @$c[3..4];
  331. }
  332.  
  333.  
  334.  
  335.  
  336. 1;
  337.