Prepare to handle locale better. re #37
This commit is contained in:
parent
60f865f51b
commit
ab01a2d035
|
@ -9,7 +9,7 @@
|
||||||
|
|
||||||
use strict;
|
use strict;
|
||||||
|
|
||||||
my @strings = ();
|
our @strings = ();
|
||||||
my %values;
|
my %values;
|
||||||
my %allstrings;
|
my %allstrings;
|
||||||
|
|
||||||
|
@ -43,38 +43,54 @@ closedir $dirhandle;
|
||||||
|
|
||||||
# Load existing json files with strings and values
|
# Load existing json files with strings and values
|
||||||
|
|
||||||
|
handleLanguageFile ("Localization_en.json");
|
||||||
|
|
||||||
opendir (my($dirhandle), "../lang") or die ("Directory not found\n");
|
opendir (my($dirhandle), "../lang") or die ("Directory not found\n");
|
||||||
for (readdir ($dirhandle)) {
|
for (readdir ($dirhandle)) {
|
||||||
next if (-d $_ ); # skip directories
|
next if (-d $_ ); # skip directories
|
||||||
next if (/^[.]/); # skip dot-files
|
next if (/^[.]/); # skip dot-files
|
||||||
next if not (/(.+)[.]json$/);
|
next if not (/(.+)[.]json$/);
|
||||||
|
next if (/en\.json$/);
|
||||||
|
|
||||||
my $file = "../lang/" . $_;
|
handleLanguageFile ($_);
|
||||||
(my $lang = $_) =~ s/Localization_(\w\w)\.json/$1/;
|
}
|
||||||
debug ("language file: $_ / $lang \n");
|
closedir $dirhandle;
|
||||||
|
|
||||||
|
sub handleLanguageFile {
|
||||||
|
my ($file) = @_;
|
||||||
|
(my $lang = $file) =~ s/Localization_(\w\w)\.json/$1/;
|
||||||
|
my $file = "../lang/" . $file;
|
||||||
|
|
||||||
|
debug ("language file: $file / $lang \n");
|
||||||
|
|
||||||
my $content = loadFile ($file);
|
my $content = loadFile ($file);
|
||||||
|
|
||||||
while ($content =~ /"(.*?)"\:"(.*?)",/igs) {
|
while ($content =~ /"(.*?)"\:"(.*?)",/igs) {
|
||||||
#push @strings, $1;
|
my $key = $1;
|
||||||
$values{$lang}{$1} = $2;
|
my $value = $2;
|
||||||
|
next if ($key =~ /^##TODO##/);
|
||||||
|
if ($lang eq "en" && $key =~ /^languages\.\w\w\w$/) {
|
||||||
|
push (@strings, $key);
|
||||||
|
}
|
||||||
|
$values{$lang}{$key} = $value;
|
||||||
#debug (" * $1 \n");
|
#debug (" * $1 \n");
|
||||||
}
|
}
|
||||||
|
|
||||||
open OUTPUT, ">$file.new";
|
open OUTPUT, ">$file";
|
||||||
|
|
||||||
print OUTPUT "{\n";
|
print OUTPUT "{\n";
|
||||||
foreach my $name (@strings) {
|
foreach my $name (@strings) {
|
||||||
print OUTPUT "\"$name\":\"$values{$lang}{$name}\",\n";
|
if (not exists ($values{$lang}{$name})) {
|
||||||
|
print OUTPUT "\"##TODO##$name\":\"$values{en}{$name}\",\n";
|
||||||
|
} else {
|
||||||
|
print OUTPUT "\"$name\":\"$values{$lang}{$name}\",\n";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
print OUTPUT "\"end\":\"end\"\n";
|
print OUTPUT "\"end\":\"end\"\n";
|
||||||
print OUTPUT "}\n";
|
print OUTPUT "}\n";
|
||||||
|
|
||||||
close OUTPUT;
|
close OUTPUT;
|
||||||
}
|
}
|
||||||
closedir $dirhandle;
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
sub loadFile {
|
sub loadFile {
|
||||||
my ($file) = @_;
|
my ($file) = @_;
|
||||||
|
|
Loading…
Reference in a new issue