From 2fc62a0b1e07ce8b3d185213e267a491cc9fd283 Mon Sep 17 00:00:00 2001 From: "Wim V. (rv0)" Date: Mon, 7 Oct 2019 17:48:05 +0200 Subject: [PATCH 1/2] Force 2 spaced indents to be 4 spaces --- android2po/commands.py | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/android2po/commands.py b/android2po/commands.py index 8f79458..6ca0c7c 100644 --- a/android2po/commands.py +++ b/android2po/commands.py @@ -9,6 +9,7 @@ from io import open from lxml import etree from babel.messages import pofile, Catalog +#from elementtree import ElementTree from termcolor import colored from . import convert @@ -50,8 +51,23 @@ def xml2string(tree, action): """ ENCODING = 'utf-8' dom = convert.write_xml(tree, warnfunc=action.message) - return etree.tostring(dom, xml_declaration=True, - encoding=ENCODING, pretty_print=True).decode('utf-8') + + # By default lxml's pretty print uses 2 spaces to indent. There's no way to + # change this without manually adding more spaces line by line. + lines = etree.tostring(dom, xml_declaration=True, encoding=ENCODING, + pretty_print=True).decode(ENCODING).split("\n") + + for i in range(len(lines)): + line = lines[i] + new_line = "" + for j in range(0, len(line), 2): + if line[j:j + 2] == " ": + new_line += " " + else: + new_line += line[j:] + break + lines[i] = new_line + return "\n".join(lines) def read_xml(action, filename, **kw): From 26ad359c3880319ffed84a16996e1f57e101f3dd Mon Sep 17 00:00:00 2001 From: "Wim V. (rv0)" Date: Mon, 7 Oct 2019 17:55:10 +0200 Subject: [PATCH 2/2] Remove unused import --- android2po/commands.py | 1 - 1 file changed, 1 deletion(-) diff --git a/android2po/commands.py b/android2po/commands.py index 6ca0c7c..4450c66 100644 --- a/android2po/commands.py +++ b/android2po/commands.py @@ -9,7 +9,6 @@ from io import open from lxml import etree from babel.messages import pofile, Catalog -#from elementtree import ElementTree from termcolor import colored from . import convert