From 65d8fd9639754a4a721e0d43a3525879f0f77ccd Mon Sep 17 00:00:00 2001
From: Luc Didry <luc@didry.org>
Date: Tue, 20 Mar 2018 17:09:02 +0100
Subject: [PATCH] [zanata] Use en translation string if not translated

---
 .po2json.sh     |  4 +++-
 .renest_json.pl | 18 ++++++++++++++++--
 2 files changed, 19 insertions(+), 3 deletions(-)

diff --git a/.po2json.sh b/.po2json.sh
index c39517e2..2ff9045f 100755
--- a/.po2json.sh
+++ b/.po2json.sh
@@ -1,7 +1,9 @@
 #!/bin/bash
+po2json -i po/en.po -t locale/en.json --progress none -o po/default.json
+
 for i in po/*.po
 do
     j=$(echo $i | cut -d '.' -f 1 | cut -d '/' -f 2)
     po2json -i $i -t locale/en.json --progress none | ./.renest_json.pl > po/$j.json
+    mv po/$j.json locale/
 done
-mv po/*.json locale/
diff --git a/.renest_json.pl b/.renest_json.pl
index 55bf8d1e..2c722783 100755
--- a/.renest_json.pl
+++ b/.renest_json.pl
@@ -3,10 +3,20 @@ use strict;
 use warnings;
 
 use JSON;
-#use Hash::Merge::Simple qw(merge);
 
 my $json = JSON->new->utf8->space_before(0)->space_after(1)->indent(4)->canonical(1);
 
+my $en_file = 'po/default.json';
+my $en;
+{
+    open my $fh, '<', $en_file or die;
+    local $/ = undef;
+    $en = <$fh>;
+    close $fh;
+}
+
+$en = $json->decode($en);
+
 my $new_json = {};
 my $old_json = '';
 
@@ -20,7 +30,11 @@ for my $key (keys %{$old_json}) {
     my $real_key = substr($key, 0, $index++);
     my $trad_key = substr($key, $index);
 
-    $new_json->{$real_key}->{$trad_key} = $old_json->{$key} if $old_json->{$key};
+    if ($old_json->{$key}) {
+        $new_json->{$real_key}->{$trad_key} = $old_json->{$key};
+    } else {
+        $new_json->{$real_key}->{$trad_key} = $en->{$key};
+    }
 }
 
 print $json->encode($new_json);
-- 
GitLab