aboutsummaryrefslogtreecommitdiffstats
path: root/po/ui-extract.pl
diff options
context:
space:
mode:
Diffstat (limited to 'po/ui-extract.pl')
-rwxr-xr-xpo/ui-extract.pl144
1 files changed, 112 insertions, 32 deletions
diff --git a/po/ui-extract.pl b/po/ui-extract.pl
index a7ccf78bfc..602649c8de 100755
--- a/po/ui-extract.pl
+++ b/po/ui-extract.pl
@@ -1,25 +1,61 @@
#!/usr/bin/perl -w
+#
# The XML UI Translation Extractor
-# (C) 2000 The Free Software Foundation
+#
+# Copyright (C) 2000 Free Software Foundation.
+#
+# This library is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License as
+# published by the Free Software Foundation; either version 2 of the
+# License, or (at your option) any later version.
+#
+# This script is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+# General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this library; if not, write to the Free Software
+# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
#
# Authors: Kenneth Christiansen <kenneth@gnu.org>
+#
+
+
use strict;
+use File::Basename;
use Getopt::Long;
-my $VERSION = "0.6.1";
+#---------------------------
+
+my $VERSION = "0.8.5";
-my $FILE = $ARGV[0];
+#---------------------------
+
+my $LOCAL_ARG = "0";
my $HELP_ARG = "0";
my $VERSION_ARG = "0";
my $UPDATE_ARG = "0";
-my %string = ();
-my $n = 0;
+
+#---------------------------
+
+my $FILE;
+my $OUTFILE;
+
+#---------------------------
+
+my %string = ();
+my @elements;
+my $n;
+
+#---------------------------
$| = 1;
GetOptions (
+ "local|l" => \$LOCAL_ARG,
"help|h|?" => \$HELP_ARG,
"version|v" => \$VERSION_ARG,
"update" => \$UPDATE_ARG,
@@ -39,14 +75,23 @@ sub SplitOnArgument {
&Version;
} elsif ($HELP_ARG) {
- &Help;
+ &Help;
+
+ } elsif ($LOCAL_ARG) {
+ &PlaceLocal;
+ &Preparation;
+ &WriteFile;
} elsif ($UPDATE_ARG) {
- &Xmlfiles;
+ &PlaceNormal;
+ &Preparation;
+ &WriteFile;
} elsif (@ARGV > 0) {
+ &PlaceNormal;
&Message;
- &Xmlfiles;
+ &Preparation;
+ &WriteFile;
} else {
&Help;
@@ -54,6 +99,21 @@ sub SplitOnArgument {
}
}
+sub PlaceNormal {
+ $FILE = $ARGV[0];
+ $OUTFILE = "$FILE.h";
+}
+
+sub PlaceLocal {
+ $FILE = $ARGV[0];
+ $OUTFILE = fileparse($FILE, ());
+ if (!-e "tmp/") {
+ system("mkdir tmp/");
+ }
+ $OUTFILE = "./tmp/$OUTFILE.h"
+}
+
+
#-------------------
sub Version{
print "The XML UI Translations Extractor $VERSION\n";
@@ -87,31 +147,27 @@ sub Message {
print "Generating headerfile for XML translation.\n";
}
-sub Xmlfiles {
+sub Preparation {
- if (-s "$FILE.h"){
- unlink "$FILE.h";
+ if (-s "$OUTFILE"){
+ unlink "$OUTFILE";
}
- &Convert ($FILE);
+ &Convert ($FILE);
+}
+sub WriteFile {
- open OUT, ">>$FILE.h";
+ open OUT, ">>$OUTFILE";
&addMessages;
close OUT;
- print "Wrote $FILE.h\n";
+ print "Wrote $OUTFILE\n";
}
#-------------------
sub Convert($) {
- if ($ARGV[1]){
- $FILE = $ARGV[1];
- } else {
- $FILE = $ARGV[0];
- }
-
#-----------------
# Reading the file
#-----------------
@@ -122,8 +178,8 @@ sub Convert($) {
$input = <IN>;
}
- if (!-s "$FILE.h"){
- open OUT, ">$FILE.h";
+ if (!-s "$OUTFILE"){
+ open OUT, ">$OUTFILE";
print OUT "/*\n";
print OUT " * Translatable strings file generated by extract-ui.\n";
@@ -148,10 +204,17 @@ sub Convert($) {
### For translatable Glade XML files ###
if ($FILE =~ /glade$/sg){
- my $translate = "label|title|text|format|copyright|comments|preview_text|tooltip";
+ my $translate = "label|items|title|text|format|copyright|comments|preview_text|tooltip";
while ($input =~ /<($translate)>(..[^<]*)<\/($translate)>/sg) {
+
+ # Glade has some bugs, especially it uses translations tags to contain little
+ # non-translatable content. We work around this, by not including these
+ # strings that only includes something like: label4, and window1
+ if ($2 =~ /^(window|label)[0-9]$/g) {
+ } else {
$string{$2} = [];
+ }
}}
}
@@ -160,16 +223,33 @@ sub addMessages{
foreach my $theMessage (sort keys %string) {
my ($lineNo,$fileName) = @{ $string{$theMessage} };
+ # Replace XML codes for special chars to
+ # geniune gettext syntax
+ #---------------------------------------
+ $theMessage =~ s/&quot;/\\"/mg;
+ $theMessage =~ s/&lt;/</mg;
+ $theMessage =~ s/&gt;/>/mg;
+
if ($theMessage =~ /\n/) {
- print OUT "gchar *s = N_(";
-
- $n = 1;
- for (split /\n/, $theMessage) {
- $_ =~ s/^\s+//mg;
- if ($n > 1) { print OUT " ";}
- $n++;
- print OUT "\"$_\");\n";
- }
+
+ @elements = split (/\n/, $theMessage);
+ for ($n = 0; $n < @elements; $n++) {
+
+ if ($n == 0) {
+ print OUT "gchar *s = N_";
+ print OUT "(\"$elements[$n]\\n\"\n";
+ }
+
+ elsif ($n == @elements - 1) {
+ print OUT " ";
+ print OUT "\"$elements[$n]\");\n";
+ }
+
+ elsif ($n > 0) {
+ print OUT " ";
+ print OUT "(\"$elements[$n]\\n\");\n";
+ }
+ }
} else {