From d76f7e13b3424eac3aeabcd9452976a08f404eb0 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Daniel=20Mart=C3=AD?= <mvdan@mvdan.cc>
Date: Sun, 8 Mar 2015 20:34:56 +0100
Subject: [PATCH] Add script to remove partially translated arrays

They may crash the client, so better use the original english instead
---
 F-Droid/tools/remove-partial-arrays.py | 36 ++++++++++++++++++++++++++
 1 file changed, 36 insertions(+)
 create mode 100755 F-Droid/tools/remove-partial-arrays.py

diff --git a/F-Droid/tools/remove-partial-arrays.py b/F-Droid/tools/remove-partial-arrays.py
new file mode 100755
index 000000000..97254fc1e
--- /dev/null
+++ b/F-Droid/tools/remove-partial-arrays.py
@@ -0,0 +1,36 @@
+#!/bin/env python2
+
+# Remove translated arrays that are missing elements
+
+import glob
+import os
+import re
+from xml.etree import ElementTree
+
+number = dict()
+
+for e in ElementTree.parse(os.path.join('res', 'values', 'array.xml')).getroot().findall('.//string-array'):
+    name = e.attrib['name']
+    count = len(e.findall('item'))
+    number[name] = count
+
+for d in glob.glob(os.path.join('res', 'values-*')):
+
+    arr_path = os.path.join(d, 'array.xml')
+    if os.path.exists(arr_path):
+        tree = ElementTree.parse(arr_path)
+        root = tree.getroot()
+
+        elems = root.findall('.//string-array')
+        for e in elems:
+            name = e.attrib['name']
+            count = len(e.findall('item'))
+            if count != number[name]:
+                root.remove(e)
+
+        result = re.sub(r' />', r'/>', ElementTree.tostring(root, encoding='utf-8'))
+
+        with open(arr_path, 'w+') as f:
+            f.write('<?xml version="1.0" encoding="utf-8"?>\n')
+            f.write(result)
+            f.write('\n')