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

Re: [d-i]: Localization and cdebconf



* Joey Hess 

| Tollef Fog Heen wrote:
| > I have begun looking into i18n with cdebconf.  First, it didn't parse
| > Description-$LANG lines, I have fixed this now (patches are coming
| > later).
| 
| Looking forward to that.

Index: tools/cdebconf/src/template.c
===================================================================
RCS file: /cvs/debian-boot/debian-installer/tools/cdebconf/src/template.c,v
retrieving revision 1.6
diff -u -r1.6 template.c
--- tools/cdebconf/src/template.c       2001/01/07 05:05:12     1.6
+++ tools/cdebconf/src/template.c       2001/11/19 18:36:38
@@ -135,15 +137,78 @@
                                        
                                t->extended_description = strdup(extdesc);
                        }
+               }
+               else if (strstr(p, "Description-") == p && t != 0)
+               {
+                       struct language_description *langdesc = malloc(sizeof(struct
 language_description));
+                       struct language_description *lng_tmp = 0;
+                       memset(langdesc,0,sizeof(struct language_description));
+                       /* We assume that the language codes are
+                          always 2 characters long, */
 
+                       langdesc->language = malloc(3);
+                       langdesc->language[0] = *(p+12);
+                       langdesc->language[1] = *(p+13);
+                       langdesc->language[2] = 0;
+                       langdesc->description = strdup(p+16);
+                       extdesc[0] = 0;
+                       while (fgets(buf, sizeof(buf), fp))
+                       {
+                               if (buf[0] != ' ') break;
+                               strvacat(extdesc, sizeof(extdesc), buf+1, 0);
+                       }
+                       if (*extdesc != 0)
+                       {
+                               /* remove extraneous linebreaks */
+                               /* remove internal linebreaks unless the next
+                                * line starts with a space; also change
+                                * lines that contain a . only to an empty
+                                * line
+                                */
+                               for (bufp = extdesc; *bufp != 0; bufp++)
+                                       if (*bufp == '\n')
+                                       {
+                                               if (*(bufp+1) == '.' &&
+                                                   *(bufp+2) == '\n')
+                                           {
+                                                   *(bufp+1) = ' ';
+                                                   bufp+=2;
+                                           }
+                                               else if (*(bufp+1) != ' ')
+                                                       *bufp = ' ';
+                                       }
+                               
+                               langdesc->extended_description = strdup(extdesc);
+                       }
                        if (t != 0)
                        {
-                               t->next = tlist;
-                               tlist = t;
-                               t = 0;
+                               if (t->localized_descriptions == NULL) 
+                               {
+                                       t->localized_descriptions = langdesc;
+                               }
+                               else
+                               {
+                                       lng_tmp = t->localized_descriptions;
+                                       while (lng_tmp->next != NULL)
+                                               lng_tmp = lng_tmp->next;
+                                       lng_tmp->next = langdesc;
+                               }
                        }
                }
        }
+
+       if (t != 0)
+       {
+               t->next = tlist;
+               tlist = t;
+               t = 0;
+       }
+
        fclose(fp);
        return tlist;
 }
+/*
+Local variables:
+c-file-style: "linux"
+End:
+*/
Index: tools/cdebconf/src/template.h
===================================================================
RCS file: /cvs/debian-boot/debian-installer/tools/cdebconf/src/template.h,v
retrieving revision 1.1
diff -u -r1.1 template.h
--- tools/cdebconf/src/template.h       2000/10/23 01:38:11     1.1
+++ tools/cdebconf/src/template.h       2001/11/19 18:36:39
@@ -1,6 +1,14 @@
 #ifndef _TEMPLATE_H_
 #define _TEMPLATE_H_
 
+struct language_description 
+{
+       char *language;
+       char *description;
+       char *extended_description;
+       struct language_description *next;
+};
+
 struct template
 {
        unsigned int ref;
@@ -10,6 +18,7 @@
        char *choices;
        char *description;
        char *extended_description;
+       struct language_description *localized_descriptions;
        struct template *next;
 };
 
This just loads the data structure, and it seems to work, but I
haven't looked into getting it to select the proper structure when
displaying fields.

Any ideas on that?  I am considering adding a function to template.c
which is "switch_default_language", which will just copy the localized
descriptions into the normal description and extended description
fields.  This is because I don't want to put that logic into the
frontends, where it doesn't belong, IMHO.

| Well, I was sort of hoping that we could use whatever is developed to
| allow localization of package descriptions. But in leu of that, we can
| just use Description-ll fields, I suppose.

We'll probably need that as well, but the code shouldn't be too hard
to generalize, I think..

-- 

Tollef Fog Heen
Axiom #1: You Can't Win



Reply to: