Skip to content

Commit

Permalink
[JENKINS-57922] - Ability to specify target directory for translation…
Browse files Browse the repository at this point in the history
…-tool.pl (#4083)

* [JENKINS-57922] - Ability to specify output directory for
translation-tool.pl

* Prevent printing everything on same line if values are empty
  • Loading branch information
mustafau authored and oleg-nenashev committed Jun 22, 2019
1 parent f23b93a commit a5e29cb
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions translation-tool.pl
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,11 @@
# to Jenkins instead of the old name.

use strict;
use File::Basename;
use File::Find;
use File::Path;

my ($lang, $editor, $dir, $toiso, $toascii, $add, $remove, $reuse, $counter) = (undef, undef, "./", undef, undef, undef, undef, undef, undef);
my ($lang, $editor, $dir, $toiso, $toascii, $add, $remove, $reuse, $counter, $target) = (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);
## read arguments
foreach (@ARGV) {
Expand All @@ -64,6 +66,8 @@
$reuse = $1;
} elsif (/^--counter$/ || /^--counter=true$/) {
$counter = 1;
} elsif (/^--target=(.*)$/) {
$target = $1;
} else {
$dir=$_;
}
Expand Down Expand Up @@ -122,6 +126,7 @@ sub processFile {
# efile -> english file
my $file = shift;
my ($ofile, $efile) = ($file, $file);
$ofile =~ s/$dir/$target/;
$ofile =~ s/(\.jelly)|(\.properties)/_$lang.properties/;
$efile =~ s/(\.jelly)/.properties/;

Expand Down Expand Up @@ -199,6 +204,8 @@ sub processFile {
if ($counter) {
# add unique value for each added translation
print F "---TranslateMe ".$countervalue."--- ".($ekeys{$_} ? $ekeys{$_} : $_)."\n";
} else {
print F "\n";
}
}
$countervalue++;
Expand Down Expand Up @@ -367,6 +374,7 @@ sub isUtf8 {
# Note: the license is read from the head of this file
my $license;
sub printLicense {
my $file = shift;
if (!$license && open(F, $0)) {
$license = "";
my $on = 0;
Expand All @@ -378,7 +386,11 @@ sub printLicense {
close(F);
}
if ($license && $license ne "") {
open(F, ">" . shift) || die $!;
my $dirname = dirname($file);
unless (-d $dirname) {
mkpath($dirname);
}
open(F, ">" . $file) || die $!;
print F "$license\n";
close(F);
}
Expand Down Expand Up @@ -412,6 +424,7 @@ sub usage {
order to utilize them when the same key appears
--counter=true -> to each translated key, unique value is added to easily identify match missing translation
with value in source code (default false)
--target=folder -> target folder for writing files
Examples:
- Look for Spanish files with incomplete keys in the 'main' folder,
Expand Down

0 comments on commit a5e29cb

Please sign in to comment.