[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: Language and locale setting in /root/dbootstrap_setting (patch)



I'm working on fixes for base-config, and in the process I thought it
is smart to change dbootstrap to be able to us the lang->msgcat
content the same way as the LANGUAGE environment is handled by libc,
ie as a colon separated list of langauges to try.  It is very relevant
for Norwegian, where Bokmål and Nynorsk is very similar, and very
similar to Danish and Swedish, and it would be better to use any of
these instead of English.

The following patch changes how the msgcat string is used.  It is
relative to the current anonymous CVS version:

Index: langs/norwegian.src
===================================================================
RCS file: /cvs/debian-boot/boot-floppies/utilities/dbootstrap/langs/norwegian.src,v
retrieving revision 1.1
diff -u -3 -p -u -r1.1 norwegian.src
--- langs/norwegian.src	2001/10/17 03:30:12	1.1
+++ langs/norwegian.src	2002/02/24 15:48:43
@@ -3,10 +3,10 @@
     <hint>no - Du har valgt norsk.  Trykk Enter for å fortsette</hint>
     <list>
         <name>Velg språkvariant</name>
-        <item arch="i386" locale="no_NO.ISO-8859-1" acm="iso01" font="LatArCyrHeb-16" keymap="i386/qwerty/no-latin1" msgcat="nb">
+        <item arch="i386" locale="no_NO.ISO-8859-1" acm="iso01" font="LatArCyrHeb-16" keymap="i386/qwerty/no-latin1" msgcat="nb_NO:nb:no_NO:no:nn_NO:nn:dk:sv">
             <name>Bokmål</name>
         </item>
-        <item arch="i386" locale="nn_NO.ISO-8859-1" acm="iso01" font="LatArCyrHeb-16" keymap="i386/qwerty/no-latin1" msgcat="nn">
+        <item arch="i386" locale="nn_NO.ISO-8859-1" acm="iso01" font="LatArCyrHeb-16" keymap="i386/qwerty/no-latin1" msgcat="nn_NO:nn:nb_NO:nb:no_NO:no:dk:sv">
             <name>Nynorsk</name>
         </item>
     </list>
Index: boxes.c
===================================================================
RCS file: /cvs/debian-boot/boot-floppies/utilities/dbootstrap/boxes.c,v
retrieving revision 1.61
diff -u -3 -p -u -r1.61 boxes.c
--- boxes.c	2002/02/07 04:00:25	1.61
+++ boxes.c	2002/02/24 15:48:42
@@ -1171,10 +1173,23 @@ boxChooseLanguageVariant (const struct l
 	    struct language_item *li = list[i].list->items[0].p;
 	    if (list[i].list->items[0].d != 1)
 		continue;
-	    sprintf(prtbuf, "/etc/messages.%s", li->msgcat);
-	    if (access(prtbuf, R_OK))
-		continue;
-
+	    /* If any of the languages listed in the colon separated
+	       list of language codes is available, accept it */
+	    {
+		int accessable = 0;
+		char *languagelist = strdup(li->msgcat);
+		char *language = NULL;
+		for ( language = strtok(languagelist, ":");
+		      language && *language; language = strtok(NULL, ":") )
+		{
+		    sprintf(prtbuf, "/etc/messages.%s", language);
+		    if (0 == access(prtbuf, R_OK))
+			++accessable;
+		}
+		free(languagelist);
+		if (! accessable)
+		    continue;
+	    }
             wpadit (tempo, list[i].hint, width);
             newtListboxAddEntry (lang_list, tempo, list + i);
         }
Index: main.c
===================================================================
RCS file: /cvs/debian-boot/boot-floppies/utilities/dbootstrap/main.c,v
retrieving revision 1.141
diff -u -3 -p -u -r1.141 main.c
--- main.c	2002/02/03 20:57:40	1.141
+++ main.c	2002/02/24 15:48:43
@@ -708,6 +708,65 @@ static void check_proc (void) {
     	exit(1);
     }
 }
+/*
+ * Try to load all the languages specified by the colon separated
+ * priority list of langauge codes.  Fall back to messages.en,
+ * messages.trm and the TRMBACKUP catalog if none of the languages in
+ * the list works.
+ *
+ * Return true (1) if successfull and false (0) if unable to load any
+ * of the languages.
+ */
+int load_msgcat(char *list) {
+  char *msgcat = (char *)malloc (PATH_MAX);
+  char *languagelist = strdup(list);
+  char *language = NULL;
+  for ( language = strtok(languagelist, ":");
+	language && *language;
+	language = strtok(NULL, ":") )
+  {
+    snprintf (msgcat, PATH_MAX, "/etc/messages.%s", language);
+    msgcat[PATH_MAX - 1] = '\0';
+    DEBUGMSG ("i18n mode, trying to load message catalog %s", msgcat);
+    if ( LOAD_TRMFILE (msgcat) == 0) /* Succeded ? */
+    {
+      free(languagelist);
+      free (msgcat);
+      return 0;
+    }
+  }	
+  free(languagelist);
+  languagelist = NULL;
+
+  free (msgcat);
+  msgcat = NULL;
+
+  /* Try to load english, and the backup catalogs as well*/
+  if ( LOAD_TRMFILE("/etc/messages.en") != 0 ||
+       LOAD_TRMFILE("/etc/messages.trm") != 0 ||
+       LOAD_TRMFILE(TRMBACKUP) != 0 )
+  {
+    char message[255];
+
+    snprintf (message, sizeof (message),
+	      "An error occured while loading localized application messages from '%s'. English messages will be used instead.",
+	      lang->msgcat);
+    message[254] = '\0'; /* Just in case */
+	      
+    problemBoxEn (message, "Problem");
+    return 0;
+  }
+  return 1;
+}
+
+void reboot_missing_messages(void) {
+  problemBoxEn ("An error occurred while loading application messages",
+		"Problem");
+  reboot(RB_AUTOBOOT);
+  /* when not root and debugging */
+  boxFinished();
+  exit(1); 
+}
 
 int main (void) {
     char *term;
@@ -793,31 +852,11 @@ int main (void) {
 	  do {
 	    lang = boxChooseLanguageVariant (langs);
 	  } while (lang == NULL);
-	  snprintf (msgcat, PATH_MAX, "/etc/messages.%s", lang->msgcat);
-	  msgcat[PATH_MAX - 1] = '\0';
-	  DEBUGMSG ("loading message catalog %s", msgcat);
-	  
-	  if (LOAD_TRMFILE (msgcat) == 0)         /* Failed to load localized strings? */
-	  {
-	    if (LOAD_TRMFILE (TRMBACKUP) == 0)  /* Failed to load English strings as well? */
-            {
-	      problemBoxEn ("An error occured while loading application messages.", "Problem");
-	      
-	      reboot (RB_AUTOBOOT);
-	      
-	      /* when not root and debugging */
-	      boxFinished();
-	      exit(1); 
-	    }
-	    else
-	    {
-	      char message[255];
 
-	      snprintf (message, sizeof (message), "An error occured while loading localized application messages from '%s'. English messages will be used instead.", msgcat);
-	      message[254] = '\0'; /* Just in case */
-	      
-	      problemBoxEn (message, "Problem");
-	    }
+	  /* Get colon separated priority list of language codes
+	     (message catalogs) to use. */
+	  if ( load_msgcat(lang->msgcat) == 0 ) {    /* Failed to load localized strings? */
+	    reboot_missing_messages();
 	  }
 	} else {
 	  /* Try to force the language to English */
@@ -829,21 +868,10 @@ int main (void) {
 	  }
 	  lang = langs->list->items[0].p;
 
-	  snprintf (msgcat, PATH_MAX, "/etc/messages.%s", lang->msgcat);
-	  msgcat[PATH_MAX - 1] = '\0';
-	  DEBUGMSG ("i18n mode, loading message catalog %s", msgcat);
-
 	  /* The English messages might be /etc/messages.en, or
 	     /etc/messages.trm in a single locale system */
-	  if (LOAD_TRMFILE (msgcat) == 0
-	      && LOAD_TRMFILE ("/etc/messages.trm") == 0)
-	  {
-	    problemBoxEn ("An error occurred while loading application messages", "Problem");
-	    reboot(RB_AUTOBOOT);
-	    /* when not root and debugging */
-	    boxFinished();
-	    exit(1); 
-	  }
+	  if ( load_msgcat(lang->msgcat) == 0)
+	    reboot_missing_messages();
 	}
 
         free (msgcat);
@@ -851,17 +879,8 @@ int main (void) {
 #else
     /* We can use problemBox only AFTER boxInit */
     /* So it's important that no (NO!!!) function before this call (LOAD_TRMFILE) uses gettext function */
-    if (LOAD_TRMFILE(TRMFILE) == 0 && LOAD_TRMFILE(TRMBACKUP) == 0) {
-	char message[255];
-	snprintf(message, sizeof(message), 
-		 "An error occured while loading application messages from '%s'.", TRMFILE);
-    message[254] = '\0'; /* Just in case */
-	problemBoxEn (message, "Problem");
-	reboot(RB_AUTOBOOT);
-	/* when not root and debugging */
-	boxFinished();
-	exit(1); 
-    }
+    if ( load_msgcat("") == 0 )   /* Only loading default. */
+      reboot_missing_messages();
 #endif
 
 #if #cpu (m68k)
Index: net-fetch.c
===================================================================
RCS file: /cvs/debian-boot/boot-floppies/utilities/dbootstrap/net-fetch.c,v
retrieving revision 1.55
diff -u -3 -p -u -r1.55 net-fetch.c
--- net-fetch.c	2002/02/19 18:57:51	1.55
+++ net-fetch.c	2002/02/24 15:48:43
@@ -371,15 +371,26 @@ nf_initialize(void)
   nf_state.method = strdup("http");
   nf_state.server.hostname = strdup("http.us.debian.org");
 #ifdef USE_LANGUAGE_CHOOSER
+  if (NULL != lang && NULL != lang->msgcat)
   {
      int i = 0;
      while(mirror_country_map[i] != NULL) {
-        if(strcmp(lang->msgcat,mirror_country_map[i]) == 0) {
-           sprintf(nf_state.server.hostname, "ftp.%s.debian.org", mirror_country_map[i+1]);
-           goto hostname_set;
-        }
-        else
-           i+=2;
+        char *languagelist = strdup(lang->msgcat);
+	char *language = NULL;
+	int match = 0;
+	for ( language = strtok(languagelist, ":");
+	      language && *language;
+	      language = strtok(NULL, ":") ) {
+	   if(strcmp(language,mirror_country_map[i]) == 0)
+	      match = 1;
+	}
+	free(languagelist);
+	if (match) {
+	   sprintf(nf_state.server.hostname, "ftp.%s.debian.org", mirror_country_map[i+1]);
+	   goto hostname_set;
+	}
+	else
+	   i+=2;
      }
   }
 hostname_set:
Index: release_notes.c
===================================================================
RCS file: /cvs/debian-boot/boot-floppies/utilities/dbootstrap/release_notes.c,v
retrieving revision 1.8
diff -u -3 -p -u -r1.8 release_notes.c
--- release_notes.c	2001/12/03 02:39:21	1.8
+++ release_notes.c	2002/02/24 15:48:43
@@ -8,70 +8,103 @@
 #include "lang.h"
 
 #ifdef _TESTING_
-#  define RELEASE_FILE	"../../scripts/rootdisk/messages/C/release_notes"
+#  define RELEASE_FILE	"../../scripts/rootdisk/messages/%s%s/release_notes"
 #else
-#  define RELEASE_FILE	"/release_notes"
+#  define RELEASE_FILE	"/release_notes%s%s"
 #endif
 
 int
-release_notes (const char *suffix)
+release_notes (const char *msgcat)
 {
     struct stat s;
     int fd;
-#ifdef USE_LANGUAGE_CHOOSER
     char *fname = (char *)malloc (PATH_MAX);
 
-    if (suffix != NULL)
-        snprintf (fname, PATH_MAX, "%s.%s", RELEASE_FILE, suffix);
-    else
-        strcpy (fname, RELEASE_FILE);
+    char *languagelist;
+    char *suffix;
+    int found_file = 0;
 
-    if ((NAME_ISREG (fname, &s) && (fd=open (fname, O_RDONLY)) >= 0)
-	|| (NAME_ISREG(RELEASE_FILE, &s) && (fd=open (RELEASE_FILE, O_RDONLY)) >= 0))
+    if (msgcat == NULL) {
+#ifdef _TESTING_
+        msgcat = "C";
 #else
-    if (NAME_ISREG(RELEASE_FILE, &s) && (fd=open(RELEASE_FILE, O_RDONLY)) >= 0)
-#endif
+    msgcat = "";
+#endif /* _TESTING_ */
+    }
+    languagelist = strdup(msgcat);
+
+    for ( suffix = strtok(languagelist, ":"); suffix;
+	  suffix = strtok(NULL, ":") )
     {
-        char *buf = (char *)malloc (s.st_size+1);
-        size_t num;
+#ifdef _TESTING_
+        const char *separator = "";
+#else
+	const char *separator = ".";
+#endif /* _TESTING_ */
 
-		num = read (fd, buf, s.st_size);
-		close(fd);
-		buf[s.st_size] = '\0';
-
-		wideMessageBox (buf, _("Release Notes"));
-
-        free (buf);
-    } else {
-#ifdef USE_LANGUAGE_CHOOSER
-        ERRMSG("cannot find release notes file %s", 
-               fname);
-        free (fname);
-        return -1;
+        if (!suffix && ! *suffix)
+	{
+	  separator = "";
+#ifdef _TESTING_
+	  suffix = "C";
 #else
-        ERRMSG("cannot find release notes file %s", 
-               RELEASE_FILE);
+	  suffix = "";
+#endif /* _TESTING_ */
+	}
+
+	snprintf (fname, PATH_MAX, RELEASE_FILE, separator, suffix);
+
+	// wideMessageBox(fname, _("Release Notes"));
+
+	if ((NAME_ISREG (fname, &s) && (fd=open (fname, O_RDONLY)) >= 0)
+	    || (NAME_ISREG(RELEASE_FILE, &s)
+		&& (fd=open (RELEASE_FILE, O_RDONLY)) >= 0))
+	{
+	    char *buf = (char *)malloc (s.st_size+1);
+	    size_t num;
+
+	    num = read (fd, buf, s.st_size);
+	    close(fd);
+	    buf[s.st_size] = '\0';
+
+	    wideMessageBox (buf, _("Release Notes"));
+
+	    free (buf);
+	    ++found_file;
+	    break;
+	}
+    }
+
+    if ( ! found_file) {
+        free(languagelist);
+        free (fname);
+
+	ERRMSG("cannot find release notes file %s", fname);
         return -1;
-#endif
     }
 
-#ifdef USE_LANGUAGE_CHOOSER
+    free(languagelist);
     free (fname);
-#endif
 
     return (0);
 }
 
 #ifdef _TESTING_
 /* To test, compile using: make release_notes_test */
-void main(void){
+int main(int argc, char *argv[]){
+    char *msgcat = NULL;
+
     LOAD_TRMFILE("test.trm");
     get_kver();
     boxInit();
-    
-    release_notes (NULL);
+
+    if (2 == argc)
+      msgcat = argv[1];
+
+    release_notes (msgcat);
 
     boxFinished();
+    return 0;
 }
 #endif
 
Index: util.c
===================================================================
RCS file: /cvs/debian-boot/boot-floppies/utilities/dbootstrap/util.c,v
retrieving revision 1.70
diff -u -3 -p -u -r1.70 util.c
--- util.c      2002/02/21 15:23:25     1.70
+++ util.c      2002/02/24 16:09:32
@@ -670,8 +670,14 @@ check_pending_config(void)
     write_userconfig("CDROM", "true");

 #ifdef USE_LANGUAGE_CHOOSER
-  if ( lang != NULL )
-    write_userconfig("LANG_INST", lang->locale);
+  if ( lang != NULL ) {
+    /* The locale should be generated by base-config if needed, and ignored
+       if it can't be used. */
+    write_userconfig("LANG", lang->locale);
+
+    /* Specify which translations to use when displaying messages */
+    write_userconfig("LANGUAGE", lang->msgcat);
+  }
 #endif

 #if #cpu(powerpc)



Reply to: