From 0af957f93075f4b38d00918fd416f042bd0d61f8 Mon Sep 17 00:00:00 2001 From: Yann Dirson Date: Sat, 7 Aug 2004 21:17:23 +0000 Subject: [PATCH] get some (single-line) ids from wml files --- utils/wml2po.pl | 79 +++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 77 insertions(+), 2 deletions(-) diff --git a/utils/wml2po.pl b/utils/wml2po.pl index 205efeddc46..544d815f6cc 100755 --- a/utils/wml2po.pl +++ b/utils/wml2po.pl @@ -17,17 +17,92 @@ use strict; require "utils/wmltrans.pm"; # get some id->english from english.cfg -our ($wmlfile, $pofile) = @ARGV; +our ($wmltransfile, $pofile) = @ARGV; our %english = readwml ('data/translations/english.cfg'); our %revenglish; +sub set($$) { + my ($id, $str) = @_; + if (defined $english{$id}) { + print STDERR "WARNING: duplicate def for $id: $str\n"; + return; + } + $english{$id}=$str; + print STDERR "$id=$str\n"; +} + +# get ids from unit files +our @wmlfiles = glob ("data/units/*.cfg"); +foreach my $wmlfile (@wmlfiles) { + open (WML, $wmlfile) or die "cannot open $wmlfile"; + my ($id, $str); + while () { + if (m/id\s*=\s*(.*)/) { + $id = $str = $1; + $id =~ s/\s+//g; + set($id,$str); +# } elsif (m,\[/.*\],) { +# $id = undef; + } elsif (m/unit_description\s*=\s*(?:_\s*)\"(.*)\"\s*$/) { + # single-line + if (defined $id) { + set($id . '_description',$1); + } else { + print STDERR "No id for unit_description $1\n"; + } + } + } + close WML; +} + +our %suffix = ( + 'difficulty_descriptions' => '_difficulties', + 'cannot_use_message' => '_cannot_use_message', + ); + +# get ids from other wml files +#our @wmlfiles = glob ("data/*.cfg data/scenarios/*/*.cfg"); +@wmlfiles = glob ("data/*.cfg"); +foreach my $wmlfile (@wmlfiles) { + open (WML, $wmlfile) or die "cannot open $wmlfile"; + my ($id, $str); + while () { +# print STDERR $_; + if (m/id\s*=\s*(.*)/) { + $id = $1; + print STDERR "XXX $id\n"; +# } elsif (m,\[/.*\],) { +# $id = undef; + } elsif (m/unit_description\s*=\s*(?:_\s*)\"(.*)\"\s*$/) { + # single-line + if (defined $id) { + set($id . '_description',$1); + } else { + print STDERR "No id for unit_description $1\n"; + } + } elsif (m/(difficulty\_descriptions|cannot\_use\_message)\s*=\s*(?:_\s*)?\"(.*)\"\s*$/) { + # single-line + if (defined $id) { + set($id . $suffix{$1},$2); + } else { + print STDERR "No id for $1 $2\n"; + } + } elsif (m/(?:title|message|name)\s*=\s*(?:_\s*)\"(.*)\"\s*$/) { + set($id,$1); + } + } + close WML; +} + +exit; + # reverse the hash to use the strings to find the id foreach my $key (keys %english) { $revenglish{$english{$key}} = $key; } # get translations from wml file -our %lang = readwml ($wmlfile); +our %lang = readwml ($wmltransfile); ## process pofile, filling holes when we can