home *** CD-ROM | disk | FTP | other *** search
/ Chip 2000 May / Chip_2000-05_cd2.bin / suse / inst-sys / lib / YaST2 / clients / inst_language.ycp < prev    next >
Encoding:
Text File  |  2000-03-30  |  6.7 KB  |  238 lines

  1. /**
  2.  *
  3.  * $Id: inst_language.ycp,v 1.17.4.4 2000/03/22 16:43:01 kkaempf Exp $
  4.  *
  5.  * Module:        inst_language.ycp      
  6.  *
  7.  * Author:        Klaus   KΣmpf
  8.  *            Michael Hager
  9.  *            Stefan  Hundhammer    
  10.  *
  11.  * Purpose:        Let the user choose the language.
  12.  *
  13.  * user_settings:
  14.  *
  15.  * rw: "language"   the language for the installation and
  16.  *                  for target machine
  17.  * 
  18.  * "rw" read/write
  19.  * "wr" write only
  20.  *
  21.  * Reads:
  22.  * language.ycp:    a map with all supported languages
  23.  * 
  24.  */
  25. {
  26.   map lang2yast1 =
  27.       $[
  28.     "en_GB"        : "english",
  29.     "en_US"        : "english",
  30.     "en"         : "english",
  31.     "de_DE"        : "german",
  32.     "de_CH"        : "german",
  33.     "de"          : "german",
  34.     "br_FR"        : "french",
  35.     "fr_FR"        : "french",
  36.     "fr_CH"        : "french",
  37.     "it_IT"        : "italian",
  38.     "es_ES"        : "spanish",
  39.     "nl_NL"        : "dutch",
  40.     "pt_PT"        : "portuguese",
  41.     "pt_BR"        : "brazilian",
  42.     "hu_HU"        : "hungarian",
  43.     "pl_PL"        : "polish",
  44.     "el_GR"        : "greek",
  45.     "ru"         : "russian",
  46.     "ru_RU"         : "russian",
  47.     "ru_RU.KOI8-R"    : "russian",
  48.     "cs_CZ"        : "czech"
  49.       ];
  50.  
  51.   define SetConsoleFont(map consolefonts, string language) ``{
  52.     list | void  consolefont = lookup(consolefonts, language);
  53.     if (consolefont== nil && size(language) > 2)
  54.       consolefont = lookup(consolefonts, substring(language, 0, 2));
  55.     if (consolefont != nil)
  56.     {
  57.       string console_font   = select(consolefont, 0);
  58.       string unicode_map    = select(consolefont, 1);
  59.       string screen_map        = select(consolefont, 2);
  60.       string console_magic  = select(consolefont, 3);
  61.  
  62.       user_settings = add(user_settings, "console_font", console_font);
  63.       user_settings = add(user_settings, "console_unicodemap", unicode_map);
  64.       user_settings = add(user_settings, "console_screenmap",  screen_map);
  65.       user_settings = add(user_settings, "console_magic",  console_magic);
  66.       
  67.       UI(`SetConsoleFont (console_magic, console_font, screen_map, unicode_map));
  68.     }
  69.   };
  70.  
  71.   // Build the contents of the dialog.
  72.  
  73.   /* ----------------------------------------------------------------------
  74.    * Language
  75.    * ----------------------------------------------------------------------*/
  76.   map languages = ReadY2("language.ycp");
  77.  
  78.   // build up language selection box
  79.   //   with the default selection according to user_settings
  80.  
  81.   string language = UI(`GetLanguage());
  82.   if (language == "") language = "en";
  83.   language = lookup(user_settings, "language", language);
  84.  
  85.   // If we don't have that language, try omitting the country part,
  86.   // leaving just the language part ("de_DE" -> "de")
  87.  
  88.   if ( lookup(languages, language) == nil && size(language) > 2 )
  89.     language=substring(language, 0, 2);
  90.  
  91.   UI(`SetLanguage(language));
  92.  
  93.   /*
  94.    * Set default console font
  95.    */
  96.  
  97.   map consolefonts = ReadY2("consolefonts.ycp");
  98.   SetConsoleFont(consolefonts, language);
  99.   
  100.   term languagesel = 
  101.       `SelectionBox(`id(`language), `opt(`notify), "",
  102.             maplist(`lang_code, `lang_name, languages, 
  103.                 `` `item(`id(lang_code), lang_name, language == lang_code)));
  104.  
  105.  
  106.   /* ----------------------------------------------------------------------
  107.    * Build dialog
  108.    * ----------------------------------------------------------------------*/
  109.  
  110.   term contents = `VBox(
  111.             `Heading ( _(
  112. "Welcome to YaST2 - the SuSE Linux
  113. installation / system administration program."
  114. ) ),
  115.             `VWeight( 5, `VStretch() ),
  116.             `VWeight( 80, `HBox(
  117.                          `HWeight( 25, `HStretch() ),
  118.                          `HWeight( 50,
  119.                                `VBox (
  120.                                   `Left( `Label ( _( "Select your language:" ) ) ),
  121.                                   languagesel
  122.                                   )
  123.                                ),
  124.                          `HWeight( 25, `HStretch() )
  125.                          )
  126.                    ),
  127.             `VWeight( 10, `VStretch() ),
  128.             
  129.             // This button quits the installation in the first dialog
  130.             // where the user has a chance to click at anything.
  131.             // The ID `cancel will be handled automatically by the UI -
  132.             // no further action necessary.
  133.             `PushButton( `id(`cancel), _("&Quit YaST2") ),
  134.             `VWeight( 5, `VStretch() )
  135.             );
  136.  
  137.   // Show a Wizardwindow with  that contents. Don't use the Id `next,
  138.   // `back, and `help
  139.  
  140.   // helptext for language,keyboard,timezone screen
  141.   string help_text = UI(_("\
  142. <p>
  143. Choose the <b>language</b> to be used during installation and later in
  144. the installed system.
  145. </p>" ) );
  146.  
  147.   help_text = help_text + UI(_("\
  148. <p>
  149. Select <b>next</b> to continue with the next dialog. If you wish to
  150. change your selections in a later dialog, you can use the <b>back</b>
  151. and <b>next</b> buttons to switch back and forth between the
  152. installation dialogs.
  153. </p>" ) );
  154.  
  155.   help_text = help_text + UI(_("\
  156. <p>
  157. <b><i>Nothing will happen</i></b> to your computer until you confirm
  158. all your selections in the last installation dialog.
  159. </p>
  160.  
  161. <p>
  162. Select <b>Quit YaST2</b> to abort the installation now.
  163. </p>
  164. <br>
  165. ") );
  166.   
  167.   // Screen title for the first interactive dialog
  168.   any dlg = UI(`SetWizardContents( "", contents,
  169.                    help_text,
  170.                    Args(0), Args(1)));
  171.  
  172.   any ret = nil;
  173.   
  174.   repeat
  175.   {
  176.       ret= UI(`UserInput());
  177.  
  178.       if (ret == `next || ret == `language || ret == `back)
  179.       {
  180.       language = UI(`QueryWidget(`id(`language), `CurrentItem));
  181.       user_settings = add(user_settings, "language", language);
  182.       
  183.       if ( ret != `back )
  184.       {
  185.           UI(`SetLanguage(language));
  186.           SetConsoleFont(consolefonts, language);
  187.  
  188.           string yast1_language = lookup (lang2yast1, language, language);
  189.           user_settings = add (user_settings, "yast1_language", yast1_language);
  190.  
  191.           // replace Language and Locale in /etc/install.inf
  192.           // remove Keytable from /etc/install.inf
  193.  
  194.           Shell ("grep -v ^Language /etc/install.inf | grep -v ^Keytable | grep -v ^Locale > /tmp/install.inf");
  195.           WriteString ("/tmp/yast2.inf",
  196.         "Language: "+yast1_language+"\n"
  197.         + "Locale: "+language+"\n");
  198.           Shell ("cat /tmp/yast2.inf /tmp/install.inf > /etc/install.inf");
  199.  
  200.           _debug("Lang: ", language);
  201.  
  202.           if (ret == `language) return (`again);
  203.       }
  204.  
  205.       if ( ret == `next )
  206.       {
  207.           integer  mem_total_with_swap = 0;
  208.           map|void mem_map = SCR(`Read(.proc.meminfo));
  209.  
  210.           _debug ( "MemMap",  mem_map );
  211.           
  212.           if ( mem_map != nil )
  213.           {
  214.           // default 256 MB if the amount can not be read
  215.           mem_total_with_swap =   lookup(lookup( mem_map, "mem" ), "total", 256 * 1024 * 1024 )
  216.                                        + lookup(lookup( mem_map, "swap"), "total", 0);
  217.  
  218.           _debug( "Total Mem:", mem_total_with_swap );
  219.           
  220.           if (  mem_total_with_swap  < (48 * 1024 * 1024) )
  221.           {
  222.              UI(`DisplayMessage(_("YaST2 needs at least 48 MB of memory to run.\n
  223. Please use the text based YaST1 for the
  224. installation of SuSE Linux on your PC.
  225. A detailed description of the installation
  226. procedure can be found in the manual." ) ) );
  227.               
  228.                return `again;
  229.           }
  230.           }
  231.       }
  232.       
  233.       }
  234.   } until (ret == `next || ret == `back || ret == `cancel);
  235.  
  236.   return ret;
  237. }
  238.