Skip to content

Commit

Permalink
Improvements for translation-tool.pl
Browse files Browse the repository at this point in the history
After several tests of 3bfe97e I found that library does not support:
- proper using characters stored as \uXXXX so then translated files have values without \u
- keys with spaces such as `jenkins\ title` is not supported

So then I decided to revert last commit and add a little improvement but still there are problems with
- values which ends with `\` so value is provided as multiline
- lines with more than single `=` character that are already translated
  • Loading branch information
damianszczepanik committed Jan 5, 2019
1 parent 9ce4c4c commit 049fe2c
Showing 1 changed file with 19 additions and 11 deletions.
30 changes: 19 additions & 11 deletions translation-tool.pl
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,6 @@

use strict;
use File::Find;
# to install the module: cpan install Config::Properties
use Config::Properties;

my ($lang, $editor, $dir, $toiso, $toascii, $add, $remove, $reuse, $counter) = (undef, undef, "./", undef, undef, undef, undef, undef, undef);
my ($tfiles, $tkeys, $tmissing, $tunused, $tempty, $tsame, $tnojenkins, $countervalue) = (0, 0, 0, 0, 0, 0, 0, 1);
Expand Down Expand Up @@ -78,13 +76,13 @@
exit();
}

print STDERR "\rFinding files ...";
print STDERR "Finding files ...\n";
## look for Message.properties and *.jelly files in the provided folder
my @files = findTranslatableFiles($dir);
print STDERR "Found ".(scalar keys @files)." files\n";

## load a cache with keys already translated to utilize in the case the same key is used
my %cache = loadAllTranslatedKeys($reuse, $lang) if ($reuse && -e $reuse);
print STDERR "\r ";

## process each file
foreach (@files) {
Expand Down Expand Up @@ -277,13 +275,23 @@ sub loadJellyFile {

# Fill a hash with key/value pairs from a .properties file
sub loadPropertiesFile {
my $filename = shift;
my $properties = Config::Properties->new();

open my $file, '<', $filename or die "unable to open property file: ". $filename;
$properties->load($file);
close(F);
return $properties->properties;
my $file = shift;
my %ret;
if (open(F, "$file")) {
my ($cont, $key, $val) = (0, undef, undef);
while (<F>) {
s/[\r\n]+//;
$ret{$key} .= "\n$1" if ($cont && /\s*(.*)[\\\s]*$/);
if (/^([^#\s].*?[^\\])=(.*)[\s\\]*$/) {
($key, $val) = (trim($1), trim($2));
$ret{$key}=$val;
}
$cont = (/\\\s*$/) ? 1 : 0;
}
close(F);
$ret{$key} .= "\n$1" if ($cont && /\s*(.*)[\\\s]*$/);
}
return %ret;
}

# remove unused keys from a file
Expand Down

0 comments on commit 049fe2c

Please sign in to comment.