On Mon, Oct 06, 2003 at 01:03:20PM -0600, [EMAIL PROTECTED] wrote:
> Update of /cvs/debian-boot/debian-installer/tools/cdebconf/src/modules/frontend/text
> In directory gluck:/tmp/cvs-serv19180/src/modules/frontend/text
> 
> Modified Files:
>       text.c 
> Log Message:
> Add translations of the other (non-newt) frontends.
[...]

Hi,

here is a first try to automatically extract templates files from C
source files.  It has not been fully tested, please check it before
applying.  It also fixes minor problems with l10n: it is safer to
remove \n from msgids, sentences should not be cut into small pieces,
and comments are added for translators.

If you are interested, I will have a look at other frontends.
The generation of templates is not automatically performed, one has
to run 'make templates' under the text/ subdirectory.

Denis
Index: text/Makefile
===================================================================
RCS file: 
/cvs/debian-boot/debian-installer/tools/cdebconf/src/modules/frontend/text/Makefile,v
retrieving revision 1.4
diff -u -r1.4 Makefile
--- text/Makefile       9 Jul 2002 05:25:05 -0000       1.4
+++ text/Makefile       6 Oct 2003 22:24:16 -0000
@@ -3,3 +3,21 @@
 OBJS=text.opic
 
 include ../modules.mak
+
+XGETTEXT = xgettext
+
+templates: $(srcdir)/debian/cdebconf-text-udeb.templates
+$(srcdir)/debian/cdebconf-text-udeb.templates: text.c
+       $(XGETTEXT) -c --keyword=get_text:2,3 --omit-header --no-location $? -o - | 
$(srcdir)/src/modules/frontend/src2po > [EMAIL PROTECTED]
+       @if test -f $@; then \
+           if cmp $@ [EMAIL PROTECTED] >/dev/null 2>&1; then \
+               rm -f [EMAIL PROTECTED]; \
+           else \
+               rm -f $@; \
+               mv -f [EMAIL PROTECTED] $@; \
+           fi; \
+       else \
+           mv -f [EMAIL PROTECTED] $@; \
+       fi
+
+.PHONY: templates
Index: text/text.c
===================================================================
RCS file: 
/cvs/debian-boot/debian-installer/tools/cdebconf/src/modules/frontend/text/text.c,v
retrieving revision 1.42
diff -u -r1.42 text.c
--- text/text.c 6 Oct 2003 19:03:18 -0000       1.42
+++ text/text.c 6 Oct 2003 22:24:17 -0000
@@ -154,23 +154,6 @@
        wrap_print(question_get_field(q, "", "extended_description"));
 }
 
-/* 
- * Get translated versions of strings
- */
-static char *
-yes_no_text(struct frontend *obj, int can_go_back )
-{
-       struct question *q;
-       if (can_go_back)  
-       {
-               q = obj->qdb->methods.get(obj->qdb,"debconf/prompt-yes-no-cancel");
-               return q ?  q_get_description(q) : "Prompt: yes/no/cancel";
-       } else  {
-               q = obj->qdb->methods.get(obj->qdb, "debconf/prompt-yes-no");
-               return q ? q_get_description(q) : "Prompt: yes/no";
-       }
-}
-
 /*
  * Function: get_text
  * Input: struct frontend *obj - frontend object
@@ -215,10 +198,34 @@
         * get very messy
         */
        do {
-               printf("%s%s> ", yes_no_text(obj, obj->methods.can_go_back(obj, q)),
-                      (defval == NULL ? "" : 
-                               (def == 0 ? get_text(obj, "debconf/default-yes", ", 
default=Yes") :
-                                           get_text(obj, "debconf/default-no", ", 
default=No"))));
+               if (defval == NULL) {
+                       if (obj->methods.can_go_back(obj, q))
+                                      /*  Prompt: Yes/No/Cancel> */
+                               printf(get_text(obj, "debconf/prompt-yes-no-cancel", 
"Prompt: %s/%s/%s> "),
+                                       get_text(obj, "debconf/yes", "Yes"),
+                                       get_text(obj, "debconf/no", "No"),
+                                       get_text(obj, "debconf/cancel", "Cancel"));
+                       else
+                                      /*  Prompt: Yes/No> */
+                               printf(get_text(obj, "debconf/prompt-yes-no", "Prompt: 
%s/%s> "),
+                                       get_text(obj, "debconf/yes", "Yes"),
+                                       get_text(obj, "debconf/no", "No"));
+               }
+               else {
+                       if (obj->methods.can_go_back(obj, q))
+                               /*  Prompt: Yes/No/Cancel, default=foo> */
+                               printf(get_text(obj, 
"debconf/prompt-yes-no-cancel-default", "Prompt: %s/%s/%s, default=%s> "),
+                                       get_text(obj, "debconf/yes", "Yes"),
+                                       get_text(obj, "debconf/no", "No"),
+                                       get_text(obj, "debconf/cancel", "Cancel"),
+                                       (def == 0 ? get_text(obj, "debconf/yes", 
"Yes") : get_text(obj, "debconf/default-no", "No")));
+                        else
+                               /*  Prompt: Yes/No, default=foo> */
+                               printf(get_text(obj, "debconf/prompt-yes-no-default", 
"Prompt: %s/%s, default=%s> "),
+                                       get_text(obj, "debconf/yes", "Yes"),
+                                       get_text(obj, "debconf/no", "No"),
+                                       (def == 0 ? get_text(obj, "debconf/yes", 
"Yes") : get_text(obj, "debconf/no", "No")));
+                }
                fgets(buf, sizeof(buf), stdin);
                if (strcasecmp(buf, get_text(obj, "debconf/cancel", "Cancel")) == 0)
                        return DC_GOBACK;
@@ -287,24 +294,31 @@
 
        while (1) {
            for (line = 0; i < count && line < getheight()-1; i++, line++)
-               printf("%3d. %s%s\n", i+1, choices_translated[i], 
-                      (selected[i] ? get_text(obj, "debconf/selected", " (selected)") 
: ""));
+               if (selected[i])
+                      printf("%3d. %s", i+1, choices_translated[i]);
+               else
+                      /* A selected item in a Multiselect question */
+                      printf(get_text(obj, "debconf/multiselect-selected", "%3d. %s 
(selected)"), i+1, choices_translated[i]);
+               printf("\n");
 
            if (i == count && count < getheight()-1) {
-               printf(get_text (obj, "debconf/prompt-1-page", 
-                                "Prompt: 1 - %d, q to end> "), count);
+               printf(get_text(obj, "debconf/prompt-1-page", 
+                               "Prompt: 1 - %d, q to end> "), count);
            } else if (i == count) {
                printf(get_text(obj, "debconf/prompt-last-page",
-                               "Prompt: 1 - %d, q to end, b for begin> "), count);
+                               "Prompt: 1 - %d, q to end, b for begin> "), count);
            } else {
                printf(get_text(obj, "debconf/prompt-multi-page", 
-                               "Prompt: 1 - %d/%d, q to end, n for next page> "), i, 
count);
+                               "Prompt: 1 - %d/%d, q to end, n for next page> "), i, 
count);
            }
 
            fgets(answer, sizeof(answer), stdin);
            MAKE_UPPER(answer[0]); 
+                              /* q to end */
            if (answer[0] == *(get_text(obj,"debconf/quit-key", "Q"))) break;
+                              /* n for next page */
            if (answer[0] == *(get_text(obj,"debconf/next-key", "N"))) continue;
+                              /* b for begin */
            if (answer[0] == *(get_text(obj,"debconf/begin-key", "B"))) 
                        { i = 0; continue; }
 
@@ -354,14 +368,15 @@
 {
        int c;
        if (obj->methods.can_go_back (obj, q))
-               printf (get_text(obj , "debconf/cont-cancel-prompt", 
-                                       "[Press enter to continue, or 'c to cancel]"));
+               printf("%s\n", get_text(obj , "debconf/cont-cancel-prompt", 
+                                 "[Press enter to continue, or 'c to cancel]"));
        else
-               printf(get_text(obj, "debconf/cont-prompt", "[Press enter to 
continue]\n"));
+               printf("%s\n", get_text(obj, "debconf/cont-prompt", "[Press enter to 
continue]"));
        do { 
                c = fgetc(stdin);
                MAKE_UPPER(c); 
                if ((obj->methods.can_go_back (obj, q)) &&  
+                           /*  Cancel key */ 
                    (c == *(get_text(obj, "debconf/cancel-key", "C"))))
                        return DC_GOBACK;
        } while (c != '\r' && c != '\n');
@@ -451,9 +466,14 @@
        i = 0;
 
        do {
-           for (line = 0; i < count && line < getheight()-1; i++, line++)
-               printf("%3d. %s%s\n", i+1, choices_translated[i],
-                      (def == i + 1 ? get_text(obj, "debconf/default-text", " 
(default)") : ""));
+           for (line = 0; i < count && line < getheight()-1; i++, line++) {
+               if (def == i + 1)
+                      /* A selected item in a Select question */
+                      printf(get_text(obj, "debconf/select-default", "%3d. %s 
(default)"), i+1, choices_translated[i]);
+               else
+                      printf("%3d. %s", i+1, choices_translated[i]);
+               printf("\n");
+           }
  
            if (i == count) {
                if (def > 0 && choices_translated[def-1]) {
@@ -535,7 +555,7 @@
        int sz = 1;
 
         out = malloc(sz);
-       printf(get_text(obj, "debconf/enter-line", "Enter . on a line by itself when 
you are done\n"));
+       printf("%s\n", get_text(obj, "debconf/enter-line", "Enter . on a line by 
itself when you are done"));
        while (fgets(buf, sizeof(buf), stdin))
        {
                if (strcmp(buf, ".\n") == 0) break;
@@ -561,10 +581,10 @@
 {
        int c;
        if (obj->methods.can_go_back (obj, q))
-               printf (get_text(obj, "debconf/cont-cancel-prompt", 
-                                "[Press enter to continue, or 'c to cancel]"));
+               printf("%s\n", get_text(obj , "debconf/cont-cancel-prompt", 
+                                 "[Press enter to continue, or 'c to cancel]"));
        else
-               printf(get_text(obj, "debconf/cont-prompt", "[Press enter to 
continue]\n"));
+               printf("%s\n", get_text(obj, "debconf/cont-prompt", "[Press enter to 
continue]"));
        do { 
                c = fgetc(stdin); 
                MAKE_UPPER(c);
--- src2po      2003-08-30 00:41:58.000000000 +0200
+++ src2po      2003-10-06 23:59:43.000000000 +0200
@@ -0,0 +1,15 @@
+#! /usr/bin/perl
+
+$/="\n\n";
+my $first = 1;
+while (<>) {
+        s/"\n"//g;
+        my ($pre, $name, $descr) = m/(.*)msgid "([^\n]+)"\nmsgid_plural "([^\n]+)"/s;
+        print "\n" unless $first;
+        $first = 0;
+        print "Template: $name\n";
+        print "Type: text\n";
+        $pre =~ s/^#[,:].*//mg;
+        print "# $pre\n" if $pre =~ s/.*#\. ([^\n]+)\n*$/$1/s;
+        print "_Description: $descr\n";
+}

Reply via email to