Re: rfc822 format and intltool



On Wed, Aug 14, 2002 at 03:34:49PM +0200, Kenneth Christiaansen wrote:
> I am interested in integrating this if it is made in the intltool spirit and
> doesn't add extra requirements.

Ok, here is a first try to add support for Debian config files in rfc822
format.  Scripts intltool-extract.in.in and intltool-merge.in.in are
patched, and 2 tests are added.

Since processed files have no known extension, I have no idea on
what to do with intltool-prepare and intltool-update.  Could I add
a -t flag similar to the one from intltool-extract in order to
specify input file type?

As mentioned in intltool-extract, processed files can be configuration
files, and so simple strings like "Yes" or "No" may sometimes need
different values.  When duplicates should not happen, any string of the
form "@make-uniq[^ ]*@" may be prepended in order to make msgids
unique.  Also msgstr may contain such a dummy string, e.g. when
an empty value is a valid entry.

My main goal is to propose an alternate solution for translation of
Debconf templates files (similar to the ones found in the patch),
based on intltool.  But other files may also benefit from this
patch, e.g. to integrate package descriptions (if it happens
one day) into debian/control files.

Denis
Index: intltool-extract.in.in
===================================================================
RCS file: /cvs/gnome/intltool/intltool-extract.in.in,v
retrieving revision 1.44
diff -u -u -r1.44 intltool-extract.in.in
--- intltool-extract.in.in	1 Jun 2002 01:06:45 -0000	1.44
+++ intltool-extract.in.in	14 Aug 2002 21:00:29 -0000
@@ -183,6 +183,7 @@
     &type_glade if $gettext_type eq "glade";
     &type_scheme if $gettext_type eq "scheme";
     &type_schemas  if $gettext_type eq "schemas";
+    &type_rfc822deb  if $gettext_type eq "rfc822deb";
 }
 
 sub entity_decode_minimal
@@ -264,6 +265,20 @@
 	s/^ //;
 	s/ $//;
         $messages{entity_decode_minimal($_)} = [];
+    }
+}
+
+sub type_rfc822deb {
+    ### For rfc822-style Debian configuration files ###
+
+    while ($input =~ /(?:^|\n)_[^:]+:\s*(.*?)(?=\n\S|$)/sg) {
+        #   As rfc822deb is for configuration files, duplicates
+        #   should never happen.  Developers must use the
+        #   @make-uniq@ construct to make msgid unique, see also
+        #   intltool-merge
+        print STDERR "Warning: msgid multiply defined:\n  $1\n"
+            if defined($messages{$1});
+        $messages{$1} = [];
     }
 }
 
Index: intltool-merge.in.in
===================================================================
RCS file: /cvs/gnome/intltool/intltool-merge.in.in,v
retrieving revision 1.52
diff -u -u -r1.52 intltool-merge.in.in
--- intltool-merge.in.in	19 May 2002 01:21:22 -0000	1.52
+++ intltool-merge.in.in	14 Aug 2002 21:00:29 -0000
@@ -48,6 +48,7 @@
 my $KEYS_STYLE_ARG = 0;
 my $DESKTOP_STYLE_ARG = 0;
 my $SCHEMAS_STYLE_ARG = 0;
+my $RFC822DEB_STYLE_ARG = 0;
 my $QUIET_ARG = 0;
 my $PASS_THROUGH_ARG = 0;
 my $UTF8_ARG = 0;
@@ -65,6 +66,7 @@
  "keys-style|k" => \$KEYS_STYLE_ARG,
  "desktop-style|d" => \$DESKTOP_STYLE_ARG,
  "schemas-style|s" => \$SCHEMAS_STYLE_ARG,
+ "rfc822deb-style|r" => \$RFC822DEB_STYLE_ARG,
  "pass-through|p" => \$PASS_THROUGH_ARG,
  "utf8|u" => \$UTF8_ARG,
  "cache|c=s" => \$cache_file
@@ -116,6 +118,11 @@
         &print_message;
         &schemas_merge_translations;
 	&finalize;
+} elsif ($RFC822DEB_STYLE_ARG && @ARGV > 2) {
+        &preparation;
+        &print_message;
+        &rfc822deb_merge_translations;
+	&finalize;
 } else {
 	&print_help;
 }
@@ -144,6 +151,7 @@
     print "  -d, --desktop-style    includes translations in the desktop style\n";
     print "  -k, --keys-style       includes translations in the keys style\n";
     print "  -s, --schemas-style    includes translations in the schemas style\n";
+    print "  -r, --rfc822deb-style  includes translations in the RFC822 style\n";
     print "  -x, --xml-style        includes translations in the standard xml style\n";
     print "  -u, --utf8             convert all strings to UTF-8 before merging\n";
     print "  -p, --pass-through     use strings as found in .po files, without\n";
@@ -350,6 +358,8 @@
 
     return "\\" if $sequence eq "\\\\";
     return "\"" if $sequence eq "\\\"";
+    return "\n" if $sequence eq "\\n";
+    return "\t" if $sequence eq "\\t";
 
     # gettext also handles \n, \t, \b, \r, \f, \v, \a, \xxx (octal),
     # \xXX (hex) and has a comment saying they want to handle \u and \U.
@@ -655,3 +665,47 @@
 
     close OUTPUT;
 }
+
+sub rfc822deb_merge_translations
+{
+    my $source;
+
+    {
+       local $/; # slurp mode
+       open INPUT, "<$FILE" or die "can't open $FILE: $!";
+       $source = <INPUT>;
+       close INPUT;
+    }
+
+    open OUTPUT, ">${OUTFILE}" or die;
+
+    while ($source =~ /(^|\n)(_)?([^:]+)(:\s*)(.*?)(?=\n[\S\n]|$)/sg) {
+	    my $sep = $1;
+	    my $non_translated_line = $3.$4;
+	    my $string = $5;
+	    #  Remove @make-uniq@ strings
+	    $string =~ s/\ make-uniq[^\@]*\@//;
+            $non_translated_line .= $string;
+
+            print OUTPUT $sep.$non_translated_line;
+            if (defined($2)) {
+                for my $lang (sort keys %po_files_by_lang) {
+                        my $translation = $translations{$lang, $string};
+                        next if !$translation;
+
+	                #  $translation may also contain @make-uniq@
+                        #  pseudo-string, mostly to indicate an
+                        #  empty string
+                        $translation =~ s/\ make-uniq[^\@]*\@//;
+                        $_ = $non_translated_line;
+                        s/^(\w+):\s*.*/$sep${1}-$lang: $translation/s;
+                        print OUTPUT;
+                }
+            }
+    }
+    print OUTPUT "\n";
+
+    close OUTPUT;
+    close INPUT;
+}
+
Index: tests/selftest.pl.in
===================================================================
RCS file: /cvs/gnome/intltool/tests/selftest.pl.in,v
retrieving revision 1.24
diff -u -u -r1.24 selftest.pl.in
--- tests/selftest.pl.in	18 Apr 2002 20:28:23 -0000	1.24
+++ tests/selftest.pl.in	14 Aug 2002 21:00:30 -0000
@@ -141,4 +141,14 @@
 system("@PERL@ ../intltool-extract --type=gettext/glade --quiet --update cases/$case") == 0 or $failed = 1;
 check_extract_result($case);
 
+print "13. Extract messages from an rfc822 style file:                      ";
+$case = "extract10.templates_";
+system("@PERL@ ../intltool-extract --type=gettext/rfc822deb --quiet --update cases/$case") == 0 or $failed = 1;
+check_extract_result($case);
+
+print "14. Merge translations into an rfc822 style file:                    ";
+$case = "merge10.templates";
+system("@PERL@ ../intltool-merge -r --quiet cases cases/${case}_ cases/$case") == 0 or $failed = 1;
+check_merge_result($case);
+
 exit $failed;
--- tests/cases/extract10.templates_
+++ tests/cases/extract10.templates_
@@ -0,0 +1,19 @@
+Template: timezoneconf/toplevel
+Type: select
+Choices: ${choices}
+_Default: US
+_Description: Select Area
+ Please select your geographical area from the choices provided.  If you
+ are in the United States, you can just use the US option.  You can also
+ find UTC and GMT-offset zone settings in the Etc directory.
+
+Template: timezoneconf/zone
+Type: select
+Choices: ${choices}
+_Description: Time zone
+ Please select the time zone that is appropriate for your location.
+
+Template: timezoneconf/month
+Type: select
+_Choices: January, February, March, April, May, June, July, August, September, October, November, December
+_Description: Current month?
--- tests/cases/fr.po
+++ tests/cases/fr.po
@@ -0,0 +1,51 @@
+# Test file for intltool.
+# 
+#
+# THIS IS A TEST FILE - PLEASE DO NOT CHANGE
+
+msgid ""
+msgstr ""
+"Project-Id-Version: Test file - DON'T CHANGE\n"
+"POT-Creation-Date: 2002-08-14 17:45+0200\n"
+"PO-Revision-Date: 2002-08-14 22:30+0200\n"
+"Last-Translator: Denis Barbier <barbier linuxfr org>\n"
+"Language-Team: NONE <kenneth gnu org>\n"
+"MIME-Version: 1.0\n"
+"Content-Type: text/plain; charset=iso-8859-1\n"
+"Content-Transfer-Encoding: 8bit\n"
+
+#: extract10._templates.h:1
+msgid "Current month?"
+msgstr "Mois en cours ?"
+
+#: extract10._templates.h:2
+msgid ""
+"January, February, March, April, May, June, July, August, September, "
+"October, November, December"
+msgstr ""
+"janvier, février, mars, avril, mai, juin, juillet, août, septembre, "
+"octobre, novembre, décembre"
+
+#: extract10._templates.h:3
+msgid ""
+"Select Area\n"
+" Please select your geographical area from the choices provided.  If you\n"
+" are in the United States, you can just use the US option.  You can also\n"
+" find UTC and GMT-offset zone settings in the Etc directory."
+msgstr ""
+"Sélectionnez la zone\n"
+" Veuillez sélectionner votre zone géographique à partir des choix\n"
+" proposés. Vous pouvez également trouver les paramètres de décalage horaire\n"
+" UTC et GMT dans le répertoire /etc."
+
+#: extract10._templates.h:7
+msgid ""
+"Time zone\n"
+" Please select the time zone that is appropriate for your location."
+msgstr ""
+"Fuseau horaire\n"
+" Veuillez sélectionner le fuseau horaire approprié à votre emplacement."
+
+#: extract10._templates.h:9
+msgid "US"
+msgstr "Europe"
--- tests/cases/merge10.templates_
+++ tests/cases/merge10.templates_
@@ -0,0 +1,19 @@
+Template: timezoneconf/toplevel
+Type: select
+Choices: ${choices}
+_Default: US
+_Description: Select Area
+ Please select your geographical area from the choices provided.  If you
+ are in the United States, you can just use the US option.  You can also
+ find UTC and GMT-offset zone settings in the Etc directory.
+
+Template: timezoneconf/zone
+Type: select
+Choices: ${choices}
+_Description: Time zone
+ Please select the time zone that is appropriate for your location.
+
+Template: timezoneconf/month
+Type: select
+_Choices: January, February, March, April, May, June, July, August, September, October, November, December
+_Description: Current month?
--- tests/results/extract10.templates_.h
+++ tests/results/extract10.templates_.h
@@ -0,0 +1,9 @@
+char *s = N_("Current month?");
+char *s = N_("January, February, March, April, May, June, July, August, September, October, November, December");
+char *s = N_("Select Area\n"
+             " Please select your geographical area from the choices provided.  If you\n"
+             " are in the United States, you can just use the US option.  You can also\n"
+             " find UTC and GMT-offset zone settings in the Etc directory.");
+char *s = N_("Time zone\n"
+             " Please select the time zone that is appropriate for your location.");
+char *s = N_("US");
--- tests/results/merge10.templates
+++ tests/results/merge10.templates
@@ -0,0 +1,28 @@
+Template: timezoneconf/toplevel
+Type: select
+Choices: ${choices}
+Default: US
+Default-fr: Europe
+Description: Select Area
+ Please select your geographical area from the choices provided.  If you
+ are in the United States, you can just use the US option.  You can also
+ find UTC and GMT-offset zone settings in the Etc directory.
+Description-fr: Sélectionnez la zone
+ Veuillez sélectionner votre zone géographique à partir des choix
+ proposés. Vous pouvez également trouver les paramètres de décalage horaire
+ UTC et GMT dans le répertoire /etc.
+
+Template: timezoneconf/zone
+Type: select
+Choices: ${choices}
+Description: Time zone
+ Please select the time zone that is appropriate for your location.
+Description-fr: Fuseau horaire
+ Veuillez sélectionner le fuseau horaire approprié à votre emplacement.
+
+Template: timezoneconf/month
+Type: select
+Choices: January, February, March, April, May, June, July, August, September, October, November, December
+Choices-fr: janvier, février, mars, avril, mai, juin, juillet, août, septembre, octobre, novembre, décembre
+Description: Current month?
+Description-fr: Mois en cours ?


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