svnno****@sourc*****
svnno****@sourc*****
2012年 4月 19日 (木) 00:20:52 JST
Revision: 23 http://sourceforge.jp/projects/miranda-jp/svn/view?view=rev&revision=23 Author: taguchi-ch Date: 2012-04-19 00:20:51 +0900 (Thu, 19 Apr 2012) Log Message: ----------- script to make a langDB.txt Added Paths: ----------- trunk/miranda-tools/lpgen/lplink.pl -------------- next part -------------- Added: trunk/miranda-tools/lpgen/lplink.pl =================================================================== --- trunk/miranda-tools/lpgen/lplink.pl (rev 0) +++ trunk/miranda-tools/lpgen/lplink.pl 2012-04-18 15:20:51 UTC (rev 23) @@ -0,0 +1,62 @@ +#!/usr/bin/perl +# +# Thie Script generate a new file included all translation using existing langpack_*. +# Words in langpack_* will overwrite the previously saved words in langDB. +# + +use POSIX; +use strict; +use warnings; + +#Check argument +if(@ARGV < 2) +{ + print "lplink <(new or old) langDB> <old langpack_* > [<next langpack_*> ...]\n"; + exit; +} + +#Add all words to langDB. +my ($langDB_file, @lang_files) = @ARGV; +my $key = ''; +my %trans; +foreach my $lang_file (@lang_files) +{ + open my $fh1, '<', $lang_file or die "Error Cannot open '$lang_file': $!"; + while( my $get_key = <$fh1>) + { + chomp $get_key; + if( $get_key =~ /^\[(.*?\[.*?\])*.*?\]/ ) + { + $key = $get_key; + next; + } + elsif( $get_key and !$trans{$get_key} and $get_key !~ /^;/ and $key ne '' ) + { + $trans{$key} = $get_key; + } + } + close $fh1; +} + +#Sort orignal words in alphabetical order. +my @keywords = sort( keys ( %trans )); + +#All result write to langDB. +open my $fh, '>', $langDB_file or die "Error Cannot open '$langDB_file': $!"; + +foreach my $keyword (@keywords) +{ + if( $keyword =~ /^\[(.*?\[.*?\])*.*?\]/ ) + { + print $fh $keyword; + print $fh "\n"; + print $fh $trans{$keyword}; + print $fh "\n"; + } + else + { + print $fh $keyword; + print $fh "\n"; + } +} +close $fh;