#!/usr/bin/perl ###################### # # Copyright (C) 2010 - 2015 EngSaS - Engineering Solutions and Services Langenbach. All rights reserved. # # This library is free software; you can redistribute it and/or # modify it under the terms of the GNU Lesser General Public # License as published by the Free Software Foundation; either # version 2.1 of the License, or (at your option) any later version. # # This library 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 # Lesser General Public License for more details. # # You should have received a copy of the GNU Lesser General Public # License along with this library; if not, write to the Free Software # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, # MA 02110-1301 USA. # ###################### use strict; my @langs=("EN", "DE", "FR"); use FindBin qw($Bin); print "Updating files\n"; my @changedFiles = searchFolder($Bin); my $input = 0; while($input != -1){ my $i = 1; foreach my $file (@changedFiles){ if($file =~ m/lang\/([\w\W]+).ts$/){ if($i == $input){ system("linguist ". $file ." 2>&1"); delete $changedFiles[$i - 1]; $input = -2; } else{ if($input != -2){ if($input == 0){ print $i .": ". $1 ."\n"; } $i++; } } } } if(scalar(@changedFiles) == 0){ $input = -1; } else{ # we edited an item, so build menu again without asking for input if($input == -2){ $input = 0; } else{ print "Please enter a number to start linguist or -1 to exit:\n"; $input = <>; } } } exit 0; sub determineTsFile { my $dir = shift; my $actDir = shift; my $filesRef = shift; my $lang = shift; my @files = @{$filesRef}; foreach my $file (@files){ if(-f $dir ."/". $file){ my $regex = quotemeta("_". lc($lang) .".ts"); if($file =~ m/$regex/){ return $dir ."/". $file; } } } return $dir ."/". lc($actDir) ."_". lc($lang) .".ts"; } sub searchFolder { my $dir = shift; my $level = shift || 0; my $actDir; my @updatedFiles; my $space; for(my $i = 0; $i < $level; $i++){ $space .= " "; } if($dir =~ m/([^\/]+)$/){ $actDir = $1; } else{ print "Could not determine actual directory"; return; } opendir(DIR, $dir) || die "Could not open directory ". $!; my @content = readdir(DIR); closedir(DIR); foreach my $file (@content){ if((-d $dir ."/". $file) && ($file =~ /^[^\.]/)){ if($file eq "lang"){ print $space . $actDir ."\n"; my $currentLangDir = $dir ."/". $file ."/"; opendir(LANGDIR, $currentLangDir) || die "Could not open lang directory ". $!; my @langDirContent = readdir(LANGDIR); closedir(LANGDIR); foreach my $lang (@langs){ print $space ." ". $lang ." - "; my $tsFile = determineTsFile($currentLangDir, $actDir, \@langDirContent, $lang); my $found = 0; my $new = 0; my $exists = 0; my $obsolete = 0; my $guessed = 0; open LUPDATE, "lupdate ". $dir ." -ts ". $tsFile ." 2>&1 |"; while() { if($_ =~ m/Found ([0-9]+)[\w\W]+([0-9]+) new and ([0-9]+) already/){ $found = $1; $new = $2; $exists = $3; } if($_ =~ m/Kept ([0-9]+)/){ $obsolete = $1; } if($_ =~ m/provided ([0-9]+)/){ $guessed = $1; } } close LUPDATE; if(! -e $tsFile){ print "FAILED\n"; } else{ my $untranslated = 0; if($new == 0){ # we must use lrelease to test, wether untranslated texts exists my $qmFile = "/tmp/test.qm"; open LRELEASE, "lrelease ". $tsFile ." -qm ". $qmFile ." 2>&1 |"; while() { if($_ =~ m/([0-9]+) untranslated/){ $untranslated = $1; } } close LRELEASE; system("rm ". $qmFile); } if(($untranslated > 0) || ($new > 0)){ push(@updatedFiles, $tsFile); } print "OK (". $new ." (Guessed: ". $guessed .") of ". $found .", Obsolete: ". $obsolete .", Untranslated: ". $untranslated .")\n"; } } } else{ push(@updatedFiles, searchFolder($dir ."/". $file, $level)); } } } return @updatedFiles; }