diff options
author | Michael Meeks <michael@helixcode.com> | 2000-11-05 07:50:35 +0800 |
---|---|---|
committer | Michael Meeks <mmeeks@src.gnome.org> | 2000-11-05 07:50:35 +0800 |
commit | 69be7df04c882a49352b9a291321f29661d18b91 (patch) | |
tree | f3a79e41c74ca94cedd69ad1c736e5979015b045 /po/ui-extract.pl | |
parent | f126381a0c3a2004e286eb61ecc59f29bf87cfc7 (diff) | |
download | gsoc2013-evolution-69be7df04c882a49352b9a291321f29661d18b91.tar.gz gsoc2013-evolution-69be7df04c882a49352b9a291321f29661d18b91.tar.zst gsoc2013-evolution-69be7df04c882a49352b9a291321f29661d18b91.zip |
update all of ui/*.h to ui/*.xml
2000-11-05 Michael Meeks <michael@helixcode.com>
* POTFILES.in: update all of ui/*.h to ui/*.xml
* Makefile.i18npatch: sort out the xml bits.
* ui-extract.pl: add from Kenneth.
* update.pl: Update to the version in bonobo.
svn path=/trunk/; revision=6399
Diffstat (limited to 'po/ui-extract.pl')
-rwxr-xr-x | po/ui-extract.pl | 182 |
1 files changed, 182 insertions, 0 deletions
diff --git a/po/ui-extract.pl b/po/ui-extract.pl new file mode 100755 index 0000000000..a7ccf78bfc --- /dev/null +++ b/po/ui-extract.pl @@ -0,0 +1,182 @@ +#!/usr/bin/perl -w + +# The XML UI Translation Extractor +# (C) 2000 The Free Software Foundation +# +# Authors: Kenneth Christiansen <kenneth@gnu.org> + +use strict; +use Getopt::Long; + +my $VERSION = "0.6.1"; + +my $FILE = $ARGV[0]; +my $HELP_ARG = "0"; +my $VERSION_ARG = "0"; +my $UPDATE_ARG = "0"; +my %string = (); +my $n = 0; + +$| = 1; + +GetOptions ( + "help|h|?" => \$HELP_ARG, + "version|v" => \$VERSION_ARG, + "update" => \$UPDATE_ARG, + ) or &Error; + +&SplitOnArgument; + + +#--------------------------------------------------- +# Check for options. +# This section will check for the different options. +#--------------------------------------------------- + +sub SplitOnArgument { + + if ($VERSION_ARG) { + &Version; + + } elsif ($HELP_ARG) { + &Help; + + } elsif ($UPDATE_ARG) { + &Xmlfiles; + + } elsif (@ARGV > 0) { + &Message; + &Xmlfiles; + + } else { + &Help; + + } +} + +#------------------- +sub Version{ + print "The XML UI Translations Extractor $VERSION\n"; + print "Written by Kenneth Christiansen, 2000.\n\n"; + print "Copyright (C) 2000 Free Software Foundation, Inc.\n"; + print "This is free software; see the source for copying conditions. There is NO\n"; + print "warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\n"; + exit; +} + +#------------------- +sub Help{ + print "Usage: ui-extract.pl [FILENAME] [OPTIONS] ...\n"; + print "Generates a headerfile from an xml source.\n\nGraps all strings "; + print "between <_translatable_node> and it's end tag,\nwhere tag are all allowed "; + print "xml tags. Read the docs for more info.\n\n"; + print " -V, --version shows the version\n"; + print " -H, --help shows this help page\n"; + print "\nReport bugs to <kenneth\@gnu.org>.\n"; + exit; +} + +#------------------- +sub Error{ +# print "ui-extract: invalid option @ARGV\n"; + print "Try `ui-extract.pl --help' for more information.\n"; + exit; +} + +sub Message { + print "Generating headerfile for XML translation.\n"; +} + +sub Xmlfiles { + + if (-s "$FILE.h"){ + unlink "$FILE.h"; + } + + &Convert ($FILE); + + + open OUT, ">>$FILE.h"; + &addMessages; + close OUT; + + print "Wrote $FILE.h\n"; +} + +#------------------- +sub Convert($) { + + if ($ARGV[1]){ + $FILE = $ARGV[1]; + } else { + $FILE = $ARGV[0]; + } + + #----------------- + # Reading the file + #----------------- + my $input; { + local (*IN); + local $/; #slurp mode + open (IN, "<$FILE") || die "can't open $FILE: $!"; + $input = <IN>; + } + + if (!-s "$FILE.h"){ + open OUT, ">$FILE.h"; + + print OUT "/*\n"; + print OUT " * Translatable strings file generated by extract-ui.\n"; + print OUT " * Add this file to your project's POTFILES.in\n"; + print OUT " * DO NOT compile it as part of your application.\n"; + print OUT " */\n\n"; + + } + close OUT; + + ### For generic translatable XML files ### + + if ($FILE =~ /xml$/sg){ + while ($input =~ /[\t\n\s]_[a-zA-Z0-9_]+=\"([^\"]+)\"/sg) { + $string{$1} = []; + } + + while ($input =~ /<_[a-zA-Z0-9_]+>(..[^_]*)<\/_[a-zA-Z0-9_]+>/sg) { + $string{$1} = []; + }} + + ### For translatable Glade XML files ### + + if ($FILE =~ /glade$/sg){ + my $translate = "label|title|text|format|copyright|comments|preview_text|tooltip"; + + while ($input =~ /<($translate)>(..[^<]*)<\/($translate)>/sg) { + $string{$2} = []; + }} + } + +sub addMessages{ + + foreach my $theMessage (sort keys %string) { + my ($lineNo,$fileName) = @{ $string{$theMessage} }; + + 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"; + } + + } else { + + print OUT "gchar *s = N_(\"$theMessage\");\n"; + + } + + } +} + |