svnno****@sourc*****
svnno****@sourc*****
2012年 5月 1日 (火) 22:23:50 JST
Revision: 26 http://sourceforge.jp/projects/miranda-jp/svn/view?view=rev&revision=26 Author: taguchi-ch Date: 2012-05-01 22:23:50 +0900 (Tue, 01 May 2012) Log Message: ----------- modyfied trans.pl Added Paths: ----------- trunk/miranda-tools/lpgen/trans.pl -------------- next part -------------- Added: trunk/miranda-tools/lpgen/trans.pl =================================================================== --- trunk/miranda-tools/lpgen/trans.pl (rev 0) +++ trunk/miranda-tools/lpgen/trans.pl 2012-05-01 13:23:50 UTC (rev 26) @@ -0,0 +1,167 @@ +#!/usr/bin/perl +# +# Script generating new translation from template, using old translation +# +# Miranda IM: the free IM client for Microsoft* Windows* +# +# Copyright 2000-2008 Miranda ICQ/IM project, +# all portions of this codebase are copyrighted to the people +# listed in contributors.txt. +# +# This program 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 program 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 program; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + +use POSIX; +use strict; +use warnings; + +#Check argument +if(@ARGV != 3) +{ + print " '$0' <langpack_english.txt> < langDB.txt > <new langpack_*.txt>\n"; + exit; +} +my ($lang_english, $langDB_file, $newlang_file) = @ARGV; + +my $key = ''; +my %old_headers; +my @all_headers = ("Miranda Language Pack","Language:","Locale:","Authors:","Author-email:","Last-Modified-Using:","Plugins-included:","; Generated by lpgen on","; Translations:"); +my @headers = ("Language:","Locale:","Authors:","Author-email:"); + +#Get words from exited langDBfile or langpack_*.txt. +my %old_trans = get_langDB( $langDB_file, @all_headers ); + +#Pre-Header-Processing. +my %new_headers = get_newheader( $lang_english, @all_headers ); + +#Get words from new langpack_english.txt +open my $fh1, '<', $lang_english + or die qq/Error : Cannot open "$lang_english": $!/; + +#Write result to tempfile +my $temp_file = "\$file.\$\$."; +open my $fh2, '>', $temp_file + or die qq/Error : Cannot open "$temp_file": $!/; + +my $header_check = 0; +foreach my $all_header ( @all_headers ) +{ + foreach my $header ( @headers ) + { + if( $header eq $all_header ) + { + printf $fh2 "%s\n", $old_headers{$header}; + $header_check = 1; + last; + } + } + if( $header_check == 0 ) + { + printf $fh2 "%s\n", $new_headers{$all_header}; + } + $header_check = 0; +} +printf $fh2 "\n"; + +#Body +while( my $ignore_line = <$fh1>) +{ + chomp $ignore_line; + if( $ignore_line =~ /; Common strings that belong to many files/) + { + printf $fh2 "%s\n", $ignore_line; + last; + } +} + +while( my $get_line = <$fh1> ) +{ + chomp $get_line; + if( $get_line =~ /^;(\[(.*?)\]$)/ and $old_trans{$1} ) + { + printf $fh2 "%s\n%s\n", $1, $old_trans{$1}; + next; + } + else + { + printf $fh2 "%s\n", $get_line; + } +} +close $fh1; +close $fh2; + +#Rename tempfile to langDB. +rename $temp_file, $newlang_file + or die qq/Error : Cannot move "$temp_file" to "$newlang_file": $!/; + + +#Get words from exited langDB. +sub get_langDB +{ + my ($langDB_file, @all_headers) = @_; + my %old_trans; + + open my $fh, '<', $langDB_file + or die qq/Error : Cannot open "$langDB_file": $!/; + + while( my $get_line = <$fh>) + { + chomp $get_line; + foreach my $all_header ( @all_headers ) + { + if( $get_line =~ /^$all_header/) + { + $old_headers{$all_header} = $get_line; + last; + } + } + if( $get_line =~ /^\[(.*?)\]$/ ) + { + $key = $get_line; + $get_line = <$fh>; + chomp $get_line; + $old_trans{$key} = $get_line; + next; + } + } + close $fh; + return %old_trans; +} + +#Pre-Header-Processing. +sub get_newheader +{ + my ($lang_english, @all_headers) = @_; + my %new_headers; + + open my $fh, '<', $lang_english + or die qq/Error : Cannot open "$lang_english": $!/; + + while( my $get_line = <$fh>) + { + chomp $get_line; + if( $get_line =~ /^; Common strings that belong to many files/) + {last;} + + foreach my $all_header ( @all_headers ) + { + if( $get_line =~ /^$all_header/ ) + { + $new_headers{$all_header} = $get_line; + } + } + } + close $fh; + return %new_headers; +}