#!/usr/bin/perl
######################
#
# Meganizer - Media Organzier is a media management software
# Copyright (C) 2010 EngSaS - Engineering Solutions and Services Langenbach. All rights reserved.
#
# 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 3 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, see .
#
######################
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 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";
foreach my $lang (@langs){
print $space ." ". $lang ." - ";
my $tsFile = $dir ."/". $file ."/". lc($actDir) ."_". lc($lang) .".ts";
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;
}