1#!/usr/local/bin/perl 2use warnings; 3# Update utility for XASTIR language files 17.04.2001 4# Copyright (C) 2001 Rolf Bleher http://www.dk7in.de 5 6# This program is free software; you can redistribute it and/or modify 7# it under the terms of the GNU General Public License as published by 8# the Free Software Foundation; either version 2 of the License, or 9# (at your option) any later version. 10# 11# This program is distributed in the hope that it will be useful, 12# but WITHOUT ANY WARRANTY; without even the implied warranty of 13# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14# GNU General Public License for more details. 15# 16# You should have received a copy of the GNU General Public License 17# along with this program; if not, write to the Free Software 18# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 19 20# see file COPYING for details 21 22#-------------------------------------------------------------------------- 23 24# This program adds missing entries to the translated language files and 25# deletes obsolete entries. 26# If a translated comment before an entry block is found it will be preserved. 27# There might be problems with the comment with a changed block sequence. 28# I assume that you start it in the directory with the language files, 29# call it with the translated language file as parameter. 30 31# DK7IN: for now it assumes that the language files reside 32# in the current directory 33 34#-------------------------------------------------------------------------- 35$LF1 = "language-English.sys"; # original language file 36$LF2 = "language-German.sys"; # translated language file 37$LFOUT = "language-new.sys"; # modified translated language file 38if (@ARGV) { 39 $LF2 = shift @ARGV; 40} 41#-------------------------------------------------------------------------- 42open(IN1,$LF1) or die "ERROR: could not open $LF1!\n"; 43open(IN2,$LF2) or die "ERROR: could not open $LF2!\n"; 44open(OUT,">$LFOUT") or die "ERROR: could not write to $LFOUT!\n"; 45#-------------------------------------------------------------------------- 46%token = (); # translated tokens 47@cmt1 = (); # original comment 48@cmt2 = (); # translated comment 49 50# collect all available translated tokens 51while (<IN2>) { 52 next if (/^#/); # skip comment lines 53 if (/^([A-Z]+[0-9]+)(|.+|.?|.*)$/) { 54 $token{$1} = $2; # store translated text entry 55 } 56} 57 58# process language file 59while (<IN1>) { # original language file 60 if (/^#/) { # comment line 61 push(@cmt1,$_); # store comment 62 } else { 63 if (/^([A-Z]+)([0-9]+)(|.+|.?|.*)$/) { # data line 64 $name = $1; 65 $numb = $2; 66 $arg = $3; 67 68 if (@cmt1) { # pending comment 69 # try to find the translation 70 seek IN2, 0, 0; # reposition to begin of file 71 @cmt2 = (); # translated comment 72 $match = 0; 73 while (<IN2>) { 74 $line = $_; 75 if (/^([A-Z]+)([0-9]+)(|.+|.?|.*)$/) { 76 $curr = $1; 77 if ($name eq $curr) { # same block 78 $match = 1; 79 last; 80 } else { 81 @cmt2 = (); # clear wrong comment 82 } 83 } else { 84 if (/^#/) { # store comment 85 push(@cmt2,$_); 86 } 87 } 88 } 89 if ($match && @cmt2) { # found translated comment 90 foreach $line (@cmt2) { 91 print(OUT $line); # translated comment 92 } 93 } else { 94 foreach $line (@cmt1) { 95 print(OUT $line); # original comment 96 } 97 } 98 @cmt1 = (); 99 } 100 101 if ($token{$name.$numb}) { # found translation 102 $arg = $token{$name.$numb}; 103 } 104 printf(OUT "%s%s%s\n",$name,$numb,$arg); 105 } else { 106 print("ERROR: $_"); # bad line format 107 } 108 } 109} 110close(IN1); 111close(IN2); 112close(OUT); 113 114exit; 115#-------------------------------------------------------------------------- 116 117