File: intltool-update.patch

package info (click to toggle)
intltool-debian 0.30+20040213
  • links: PTS
  • area: main
  • in suites: sarge
  • size: 132 kB
  • ctags: 83
  • sloc: perl: 1,998; makefile: 41
file content (255 lines) | stat: -rw-r--r-- 8,234 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
Index: intltool-update.in.in
===================================================================
RCS file: /cvs/gnome/intltool/intltool-update.in.in,v
retrieving revision 1.100
diff -u -r1.100 intltool-update.in.in
--- intltool-update.in.in	21 Jan 2004 08:09:43 -0000	1.100
+++ intltool-update.in.in	11 Feb 2004 07:59:01 -0000
@@ -156,7 +156,7 @@
 	&GeneratePOTemplate;
     }
     &POFile_Update ($lang, $OUTPUT_FILE);
-    &Console_Write_TranslationStatus ($lang, $OUTPUT_FILE);
+    &Console_Write_TranslationStatus ($lang, $OUTPUT_FILE) if $VERBOSE;
 } 
 else 
 {
@@ -571,174 +571,70 @@
 #
 sub GeneratePOTemplate
 {
-    my $XGETTEXT = `which xgettext 2>/dev/null`;
-    my $XGETTEXT_ARGS = '';
-    chomp $XGETTEXT;
+    print "Building the $MODULE.pot...\n" if $VERBOSE;
 
-    $XGETTEXT = $ENV{"XGETTEXT"} if $ENV{"XGETTEXT"};
-    $XGETTEXT_ARGS = $ENV{"XGETTEXT_ARGS"} if $ENV{"XGETTEXT_ARGS"};
+    open LISTFILES, "| xgettext --default-domain=$MODULE --output=$MODULE.pot-update --directory=..  --add-comments --keyword=_ --keyword=N_ --keyword=U_ --files-from=-";
 
-    if (! -x $XGETTEXT)
+    open FILE, "<POTFILES.in";
+    while (<FILE>)
     {
-	print STDERR " *** xgettext is not found on this system!\n".
-		     " *** Without it, intltool-update can not extract strings.\n";
-	exit;
+        chomp;
+        s/\.($xml_support|$ini_support)$/$&.h/;
+        s/^\[.*]\s*(.*)/$1.h/;
+        print LISTFILES $_."\n";
     }
+    close FILE;
 
-    print "Building $MODULE.pot...\n" if $VERBOSE;
-
-    open INFILE, $POTFILES_in;
-    unlink "POTFILES.in.temp";
-    open OUTFILE, ">POTFILES.in.temp";
+    close LISTFILES;
 
-    my $gettext_support_nonascii = 0;
+    print "Removing generated header (.h) files..." if $VERBOSE;
 
-    # checks for GNU gettext >= 0.12
-    my $dummy = `$XGETTEXT --version --from-code=UTF-8 >/dev/null 2>/dev/null`;
-    if ($? == 0)
+    open FILE, "<POTFILES.in";
+    while (<FILE>)
     {
-	$gettext_support_nonascii = 1;
+        chomp;
+        unlink "../$_.h" if /\.($xml_support|$ini_support)$/ || s/^\[.*]\s*//;
     }
-    else
-    {
-	# urge everybody to upgrade gettext
-	print STDERR "WARNING: This version of gettext does not support extracting non-ASCII\n".
-		     "         strings. That means you should install a version of gettext\n".
-		     "         that supports non-ASCII strings (such as GNU gettext >= 0.12),\n".
-		     "         or have to let non-ASCII strings untranslated. (If there is any)\n";
-    }
-
-    my $encoding = "ASCII";
-    my $forced_gettext_code;
-    my @temp_headers;
-    my $encoding_problem_is_reported = 0;
+    close FILE;
+    print "done\n" if $VERBOSE;
 
-    while (<INFILE>) 
+    if (!-e "$MODULE.pot-update") 
     {
-	next if (/^#/ or /^\s*$/);
-
-	chomp;
-
-	my $gettext_code;
-
-	if (/^\[\s*encoding:\s*(.*)\s*\]/)
-	{
-	    $forced_gettext_code=$1;
-	}
-	elsif (/\.($xml_support|$ini_support)$/ || /^\[/)
-	{
-	    s/^\[.*]\s*//;
-	    print OUTFILE "$_.h\n";
-	    push @temp_headers, "../$_.h";
-	    $gettext_code = &TextFile_DetermineEncoding ("../$_.h") if ($gettext_support_nonascii and not defined $forced_gettext_code);
-	} 
-	else 
-	{
-	    if ($SRCDIR eq ".") {
-	        print OUTFILE "$_\n";
-	    } else {
-	        print OUTFILE "$SRCDIR/../$_\n";
-	    }
-	    $gettext_code = &TextFile_DetermineEncoding ("../$_") if ($gettext_support_nonascii and not defined $forced_gettext_code);
-	}
-
-	next if (! $gettext_support_nonascii);
-
-	if (defined $forced_gettext_code)
-	{
-	    $encoding=$forced_gettext_code;
-	}
-	elsif (defined $gettext_code and "$encoding" ne "$gettext_code")
-	{
-	    if ($encoding eq "ASCII")
-	    {
-		$encoding=$gettext_code;
-	    }
-	    elsif ($gettext_code ne "ASCII")
-	    {
-		# Only report once because the message is quite long
-		if (! $encoding_problem_is_reported)
-		{
-		    print STDERR "WARNING: You should use the same file encoding for all your project files,\n".
-				 "         but $PROGRAM thinks that most of the source files are in\n".
-				 "         $encoding encoding, while \"$_\" is (likely) in\n".
-		       		 "         $gettext_code encoding. If you are sure that all translatable strings\n".
-				 "         are in same encoding (say UTF-8), please \e[1m*prepend*\e[0m the following\n".
-				 "         line to POTFILES.in:\n\n".
-				 "                 [encoding: UTF-8]\n\n".
-				 "         and make sure that configure.in/ac checks for $PACKAGE >= 0.27 .\n".
-				 "(such warning message will only be reported once.)\n";
-		    $encoding_problem_is_reported = 1;
-		}
-	    }
-	}
+        print STDERR "WARNING: It seems that none of the files in POTFILES.in ".
+              	     "contain marked strings\n";
+        exit (1);
     }
 
-    close OUTFILE;
-    close INFILE;
-
-    unlink "$MODULE.pot";
-    my @xgettext_argument=("$XGETTEXT",
-			   "--add-comments",
-			   "--directory\=\.\.",
-			   "--output\=$MODULE\.pot",
-			   "--files-from\=\.\/POTFILES\.in\.temp");
-    my $XGETTEXT_KEYWORDS = &FindPOTKeywords;
-    push @xgettext_argument, $XGETTEXT_KEYWORDS;
-    push @xgettext_argument, "--from-code\=$encoding" if ($gettext_support_nonascii);
-    push @xgettext_argument, $XGETTEXT_ARGS if $XGETTEXT_ARGS;
-    my $xgettext_command = join ' ', @xgettext_argument;
-
-    # intercept xgettext error message
-    print "Running $xgettext_command\n" if $VERBOSE;
-    my $xgettext_error_msg = `$xgettext_command 2>\&1`;
-    my $command_failed = $?;
-
-    unlink "POTFILES.in.temp";
-
-    print "Removing generated header (.h) files..." if $VERBOSE;
-    unlink foreach (@temp_headers);
-    print "done.\n" if $VERBOSE;
-
-    if (! $command_failed)
+    if (-e "$MODULE.pot") 
     {
-	if (! -e "$MODULE.pot")
-	{
-	    print "None of the files in POTFILES.in contain strings marked for translation.\n" if $VERBOSE;
-	}
-	else
-	{
-	    print "Wrote $MODULE.pot\n" if $VERBOSE;
-	}
+	RemovePOHeader("$MODULE.pot", "$MODULE.1po");
+	RemovePOHeader("$MODULE.pot-update", "$MODULE.2po");
+	system("cmp", "-s", "$MODULE.1po", "$MODULE.2po");
+	rename("$MODULE.pot-update", "$MODULE.pot") if $?;
+	unlink "$MODULE.1po", "$MODULE.2po", "$MODULE.pot-update";
     }
     else
     {
-	if ($xgettext_error_msg =~ /--from-code/)
-	{
-	    # replace non-ASCII error message with a more useful one.
-	    print STDERR "ERROR: xgettext failed to generate PO template file because there is non-ASCII\n".
-			 "       string marked for translation. Please make sure that all strings marked\n".
-			 "       for translation are in uniform encoding (say UTF-8), then \e[1m*prepend*\e[0m the\n".
-			 "       following line to POTFILES.in and rerun $PROGRAM:\n\n".
-			 "           [encoding: UTF-8]\n\n";
-	}
-	else
-	{
-	    print STDERR "$xgettext_error_msg";
-	    if (-e "$MODULE.pot")
-	    {
-		# is this possible?
-		print STDERR "ERROR: xgettext failed but still managed to generate PO template file.\n".
-			     "       Please consult error message above if there is any.\n";
-	    }
-	    else
-	    {
-		print STDERR "ERROR: xgettext failed to generate PO template file. Please consult\n".
-			     "       error message above if there is any.\n";
-	    }
-	}
-	exit (1);
+	rename("$MODULE.pot-update", "$MODULE.pot");
+    }
+
+    print "Wrote $MODULE.pot\n" if $VERBOSE;
+}
+
+sub RemovePOHeader
+{
+    my ($infile, $outfile) = @_;
+    my $first = 1;
+
+    open (IN, "< $infile") || die "file $infile does not exist";
+    open (OUT, "> $outfile") || die "Unable to write into $outfile: $!";
+    local $/ = "\n\n";
+    while (<IN>) {
+        next if m/^msgid ""\nmsgstr/m;
+        print OUT;
     }
+    close IN;
+    close OUT;
 }
 
 sub POFile_Update
@@ -753,7 +649,7 @@
     $outfile = "$lang.po" if ($outfile eq "");
 
     # I think msgmerge won't overwrite old file if merge is not successful
-    system ("msgmerge", "-o", $outfile, $infile, "$MODULE.pot");
+    system ("msgmerge", "-q", "-o", $outfile, $infile, "$MODULE.pot");
 }
 
 sub Console_WriteError_NotExisting
@@ -862,7 +758,7 @@
 	    my $makefile_source;
 
 	    local (*IN);
-	    open IN, "<Makefile" || die "can't open Makefile: $!";
+	    open (IN, "<Makefile") || die "can't open Makefile: $!";
 
 	    while (<IN>) 
 	    {