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

Re: translations...



On Mon, Aug 12, 2002 at 11:08:11AM -0500, Adam Heath wrote:
> Show us the code.

Here you are. ;)


I know you don't like this patch because I already submitted it, I also know
you want to split the database before integrating such stuff. What I now
need to know in order to go further is how you plan to splitt it. I mean,
how many databases, with which package field in each, and so on.

That was the most important point to you, IIRC. But a lot of problems remain
until we can come with a good design.

For example, it was not clear if we use gettext for that or not.
Here are the pro and contra I can remember of.
Pro gettext: already done and widly used. 
Contra gettext: It's tricky to actually get the translations installed on
  user machine before the package are installed, which is naturally needed
  so that user can *choose* packages.
Contra putting translation as new fields in packages: 
  - dpkg have a fixed number of fields. That is to say that you have to
    modify dpkg itself each time you want add a new language. (or change a
    bit the way fields are internally managed)
  - Putting original version and translated version at the same place
    prevent the translators of keeping track of modifications. The same
    problem arose for debconf templates, and you may want to check 
    file:///usr/share/doc/debconf-doc/tutorial.html#AEN87
  - control files won't be ASCII anymore. We should go for UTF if we want to
    be safe.    							 
  - We have to reimplement the wheel in translation fuzzying when the
    original change, just like debconf does (just check the debconf-getlang
    source code). But that's not a really big deal.

Now that woody is out, and that the last flameware is old enough, I would be
more than happy if we could speak about that, and go at least a small step
further.

Here is a possible roadmap:
- Allow for several databases in dpkg (in a somehow generic way, since,
  IIRC, you want to do that for other non-vital fields, too)
- Allow for variable fields (ie 'Description-*') in dpkg, and put them in
  another database
- Change package building tools, so that these fields are actually put in
  the right place.
  I think that having the translation stored separatly in the source
    package, and integrate them only at build time is a must here.
  It might be nice to have a server like the Michael one, and having a tool
    to fetch new translation and put them in place, too (if developper ask
    for it, of course).
- Use the Description-* fields in place of the Description one, based on the
  locale

What do you think of all this ? Does it sound like a realistic roadmap ? Can
I try to do it, or is it screwed up ?

Bye, Mt.

-- 
Autrefois, c'était l'excellence qui faisait la notoriété.
Maintenant, c'est la notoriété qui fait l'excellence.
          --- Alain Finkielkraut
Index: dselect/pkginfo.cc
===================================================================
RCS file: /cvs/dpkg/dpkg/dselect/pkginfo.cc,v
retrieving revision 1.6
diff -u -r1.6 pkginfo.cc
--- dselect/pkginfo.cc	2001/07/16 13:40:22	1.6
+++ dselect/pkginfo.cc	2001/08/28 14:25:49
@@ -106,7 +106,7 @@
     whatinfovb(_("description of "));
     whatinfovb(table[cursorline]->pkg->name);
 
-    const char *m= table[cursorline]->pkg->available.description;
+    const char *m= GETTEXT_DESC(table[cursorline]->pkg->available.description);
     if (!m || !*m) m= _("no description available.");
     const char *p= strchr(m,'\n');
     int l= p ? (int)(p-m) : strlen(m);
@@ -132,6 +132,7 @@
     whatinfovb(_("installed control info for "));
     whatinfovb(table[cursorline]->pkg->name);
     varbuf vb;
+    varbufdol10n(&vb);
     varbufrecord(&vb,table[cursorline]->pkg,&table[cursorline]->pkg->installed);
     vb.terminate();
     if (debug)
@@ -148,6 +149,7 @@
     whatinfovb(_("available version of control info for "));
     whatinfovb(table[cursorline]->pkg->name);
     varbuf vb;
+    varbufdol10n(&vb);
     varbufrecord(&vb,table[cursorline]->pkg,&table[cursorline]->pkg->available);
     vb.terminate();
     if (debug)
Index: dselect/pkglist.cc
===================================================================
RCS file: /cvs/dpkg/dpkg/dselect/pkglist.cc,v
retrieving revision 1.13
diff -u -r1.13 pkglist.cc
--- dselect/pkglist.cc	2001/07/16 15:29:03	1.13
+++ dselect/pkglist.cc	2001/08/28 14:25:49
@@ -533,7 +533,7 @@
     return 1;
 
   if (searchdescr) {
-    const char* descr = table[index]->pkg->available.description;
+    const char* descr = GETTEXT_DESC(table[index]->pkg->available.description);
     if (!descr || !*descr) return 0;
 
     if (regexec(&searchfsm, descr, 0, NULL, 0)==0)
Index: dselect/pkgtop.cc
===================================================================
RCS file: /cvs/dpkg/dpkg/dselect/pkgtop.cc,v
retrieving revision 1.12
diff -u -r1.12 pkgtop.cc
--- dselect/pkgtop.cc	2001/07/16 13:40:22	1.12
+++ dselect/pkgtop.cc	2001/08/28 14:25:50
@@ -219,7 +219,7 @@
     }
 
     i= description_width;
-    p= info->description ? info->description : "";
+    p= (info->description ? GETTEXT_DESC(info->description) : "");
     while (i>0 && *p && *p != '\n') { waddnstr(listpad,p,1); i--; p++; }
       
   } else {
Index: include/dpkg-db.h
===================================================================
RCS file: /cvs/dpkg/dpkg/include/dpkg-db.h,v
retrieving revision 1.21
diff -u -r1.21 dpkg-db.h
--- include/dpkg-db.h	2001/04/23 08:59:02	1.21
+++ include/dpkg-db.h	2001/08/28 14:25:50
@@ -236,6 +236,7 @@
 int varbufprintf(struct varbuf *v, const char *fmt, ...) PRINTFFORMAT(2,3);
 int varbufvprintf(struct varbuf *v, const char *fmt, va_list va);
 void varbufinit(struct varbuf *v);
+void varbufdol10n(struct varbuf *v);
 void varbufreset(struct varbuf *v);
 void varbufextend(struct varbuf *v);
 void varbuffree(struct varbuf *v);
@@ -258,6 +259,7 @@
  */
 struct varbuf {
   size_t used, size;
+  int l10n; /* true if we should translate this varbuf */
   char *buf;
 
 #ifdef __cplusplus
Index: include/dpkg.h.in
===================================================================
RCS file: /cvs/dpkg/dpkg/include/dpkg.h.in,v
retrieving revision 1.28
diff -u -r1.28 dpkg.h.in
--- include/dpkg.h.in	2001/06/08 22:51:26	1.28
+++ include/dpkg.h.in	2001/08/28 14:25:51
@@ -149,6 +149,7 @@
 # include <libintl.h>
 # define _(Text) gettext (Text)
 # define N_(Text) Text
+# define GETTEXT_DESC(Text) dgettext("dpkg-desc",Text)
 #else
 # undef bindtextdomain
 # define bindtextdomain(Domain, Directory) /* empty */
@@ -157,6 +158,7 @@
 # define _(Text) Text
 # define N_(Text) Text
 # define gettext(Text) Text
+# define GETTEXT_DESC(Text) Text
 #endif
 
 extern const char thisname[]; /* defined separately in each program */
Index: include/parsedump.h
===================================================================
RCS file: /cvs/dpkg/dpkg/include/parsedump.h,v
retrieving revision 1.1
diff -u -r1.1 parsedump.h
--- include/parsedump.h	2001/07/27 01:55:52	1.1
+++ include/parsedump.h	2001/08/28 14:25:51
@@ -53,7 +53,7 @@
                             const struct pkginfoperfile*, const struct fieldinfo*);
 fwritefunction w_name, w_charfield, w_priority, w_section, w_status, w_configversion;
 fwritefunction w_version, w_null, w_booleandefno, w_dependency, w_conffiles;
-fwritefunction w_filecharf;
+fwritefunction w_filecharf, w_i18n_charfield;
 
 struct fieldinfo {
   const char *name;
Index: lib/dbmodify.c
===================================================================
RCS file: /cvs/dpkg/dpkg/lib/dbmodify.c,v
retrieving revision 1.12
diff -u -r1.12 dbmodify.c
--- lib/dbmodify.c	2001/06/08 22:51:26	1.12
+++ lib/dbmodify.c	2001/08/28 14:25:52
@@ -179,7 +179,7 @@
 
   if (cstatus >= msdbrw_write) {
     createimptmp();
-    uvb.used= 0;
+    uvb.used= uvb.l10n= 0;
     uvb.size= 10240;
     uvb.buf= m_malloc(uvb.size);
   }
Index: lib/dump.c
===================================================================
RCS file: /cvs/dpkg/dpkg/lib/dump.c,v
retrieving revision 1.6
diff -u -r1.6 dump.c
--- lib/dump.c	2001/05/07 21:06:16	1.6
+++ lib/dump.c	2001/08/28 14:25:52
@@ -88,6 +88,16 @@
   varbufaddc(vb,'\n');
 }
 
+void w_i18n_charfield(struct varbuf *vb,
+                 const struct pkginfo *pigp, const struct pkginfoperfile *pifp,
+                 const struct fieldinfo *fip) {
+  const char *value= pifp->valid ? PKGPFIELD(pifp,fip->integer,const char*) : NULL;
+  if (!value || !*value) return;
+  varbufaddstr(vb,fip->name); varbufaddstr(vb, ": "); 
+  varbufaddstr(vb, vb->l10n ? GETTEXT_DESC(value) : value);  
+  varbufaddc(vb,'\n');
+}
+
 void w_filecharf(struct varbuf *vb,
                  const struct pkginfo *pigp, const struct pkginfoperfile *pifp,
                  const struct fieldinfo *fip) {
@@ -208,7 +218,7 @@
   if (pifp->valid) {
     for (afp= pifp->arbs; afp; afp= afp->next) {
       varbufaddstr(vb,afp->name); varbufaddstr(vb,": ");
-      varbufaddstr(vb,afp->value); varbufaddc(vb,'\n');
+      varbufaddstr(vb,vb->l10n ? GETTEXT_DESC(afp->value) : afp->value); varbufaddc(vb,'\n');
     }
   }
 }
@@ -218,6 +228,7 @@
   struct varbuf vb;
 
   varbufinit(&vb);
+  varbufdol10n(&vb);
   varbufrecord(&vb,pigp,pifp);
   varbufaddc(&vb,'\0');
   if (fputs(vb.buf,file) < 0)
Index: lib/parse.c
===================================================================
RCS file: /cvs/dpkg/dpkg/lib/parse.c,v
retrieving revision 1.20
diff -u -r1.20 parse.c
--- lib/parse.c	2001/05/02 04:08:31	1.20
+++ lib/parse.c	2001/08/28 14:25:52
@@ -68,7 +68,7 @@
   { "Size",             f_filecharf,       w_filecharf,      FILEFOFF(size)           },
   { "MD5sum",           f_filecharf,       w_filecharf,      FILEFOFF(md5sum)         },
   { "MSDOS-Filename",   f_filecharf,       w_filecharf,      FILEFOFF(msdosname)      },
-  { "Description",      f_charfield,       w_charfield,      PKGIFPOFF(description)   },
+  { "Description",      f_charfield,       w_i18n_charfield, PKGIFPOFF(description)   },
   /* Note that aliases are added to the nicknames table in parsehelp.c. */
   {  NULL   /* sentinel - tells code that list is ended */                               }
 };
Index: lib/varbuf.c
===================================================================
RCS file: /cvs/dpkg/dpkg/lib/varbuf.c,v
retrieving revision 1.11
diff -u -r1.11 varbuf.c
--- lib/varbuf.c	2001/05/01 05:35:00	1.11
+++ lib/varbuf.c	2001/08/28 14:25:53
@@ -88,12 +88,16 @@
 
 void varbufinit(struct varbuf *v) {
   /* NB: dbmodify.c does its own init to get a big buffer */
-  v->size= v->used= 0;
+  v->size= v->used=v->l10n= 0;
   v->buf= NULL;
 }
 
 void varbufreset(struct varbuf *v) {
   v->used= 0;
+}
+
+void varbufdol10n(struct varbuf *v) {
+  v->l10n= 1;
 }
 
 void varbufextend(struct varbuf *v) {
Index: main/query.c
===================================================================
RCS file: /cvs/dpkg/dpkg/main/query.c,v
retrieving revision 1.8
diff -u -r1.8 query.c
--- main/query.c	2001/08/01 13:41:17	1.8
+++ main/query.c	2001/08/28 14:25:53
@@ -92,7 +92,7 @@
   const char *pdesc, *p;
   int l;
   
-  pdesc= pkg->installed.valid ? pkg->installed.description : 0;
+  pdesc= (pkg->installed.valid ? GETTEXT_DESC(pkg->installed.description) : 0);
   if (!pdesc) pdesc= _("(no description available)");
   p= strchr(pdesc,'\n');
   if (!p) p= pdesc+strlen(pdesc);

Reply to: