Skip to content

Commit

Permalink
translation-tool.pl supports backslash
Browse files Browse the repository at this point in the history
 - When backslash was used in translation then generated template for translation was broken. Only first line was copied, rest was missing and because of \ and next key was also not properly processed.
 - Adds lib for reading properties files instead of own implementation

### Proposed changelog entries

### Submitter checklist

- [ ] JIRA issue is well described
- [ ] Changelog entry appropriate for the audience affected by the change (users or developer, depending on the change).
- [ ] Appropriate autotests or explanation to why this change has no tests
- [ ] For dependency updates: links to external changelogs and, if possible, full diffs

### Desired reviewers
@batmat
  • Loading branch information
damianszczepanik committed Dec 29, 2018
1 parent fe903e1 commit 3bfe97e
Showing 1 changed file with 10 additions and 19 deletions.
29 changes: 10 additions & 19 deletions translation-tool.pl
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@

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 @@ -192,8 +194,7 @@ sub processFile {
foreach (keys %keys) {
if (!$okeys{$_}) {
if (!defined($okeys{$_})) {
print F "# $ekeys{$_}\n" if ($ekeys{$_} && $ekeys{$_} ne "");
print F "$_=\n";
print F "$_=";
if (defined($cache{$_})) {
print F $cache{$_}."\n";
} else {
Expand Down Expand Up @@ -276,23 +277,13 @@ sub loadJellyFile {

# Fill a hash with key/value pairs from a .properties file
sub loadPropertiesFile {
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;
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;
}

# remove unused keys from a file
Expand Down

0 comments on commit 3bfe97e

Please sign in to comment.