summaryrefslogtreecommitdiff
path: root/ishtar_common/ooo_replace.py
diff options
context:
space:
mode:
Diffstat (limited to 'ishtar_common/ooo_replace.py')
-rw-r--r--ishtar_common/ooo_replace.py35
1 files changed, 28 insertions, 7 deletions
diff --git a/ishtar_common/ooo_replace.py b/ishtar_common/ooo_replace.py
index 4c487dd17..54ecfced4 100644
--- a/ishtar_common/ooo_replace.py
+++ b/ishtar_common/ooo_replace.py
@@ -23,6 +23,18 @@ from cStringIO import StringIO
from xml.etree.cElementTree import ElementTree, fromstring
from django.conf import settings
+from ooo_translation import ooo_translation
+
+def translate_context(context, locale):
+ if locale not in ooo_translation:
+ return context
+ new_context = {}
+ for k in context:
+ new_key = k
+ if k in ooo_translation[locale]:
+ new_key = ooo_translation[locale][k]
+ new_context[new_key] = context[k]
+ return new_context
OOO_NS = "{urn:oasis:names:tc:opendocument:xmlns:text:1.0}"
@@ -135,13 +147,9 @@ def _custom_parsing(context, value, default_value=''):
value = re.sub(sub_exp % (pre_tag, base_key), v, value)
return value
-def ooo_replace(infile, outfile, context, default_value=''):
- inzip = ZipFile(infile, 'r', ZIP_DEFLATED)
- outzip = ZipFile(outfile, 'w', ZIP_DEFLATED)
+def _ooo_replace(content, context, missing_keys, default_value=''):
# regular ooo parsing
- content = ElementTree(fromstring(inzip.read('content.xml')))
- missing_keys = set()
for xp in ('variable-set', 'variable-get'):
for p in content.findall(".//"+OOO_NS+xp):
name = p.get(OOO_NS+"name")
@@ -167,12 +175,25 @@ def ooo_replace(infile, outfile, context, default_value=''):
content.write(str_io)
value = str_io.getvalue()
value = _custom_parsing(context, value, default_value).encode('utf-8')
+ return value
+
+def ooo_replace(infile, outfile, context, default_value=''):
+ inzip = ZipFile(infile, 'r', ZIP_DEFLATED)
+ outzip = ZipFile(outfile, 'w', ZIP_DEFLATED)
+
+ values = {}
+ missing_keys = set()
+ for xml_file in ('content.xml', 'styles.xml'):
+ content = ElementTree(fromstring(inzip.read(xml_file)))
+ values[xml_file] = _ooo_replace(content, context, missing_keys,
+ default_value)
for f in inzip.infolist():
- if f.filename == 'content.xml':
- outzip.writestr('content.xml', value)
+ if f.filename in values:
+ outzip.writestr(f.filename, values[f.filename])
else:
outzip.writestr(f, inzip.read(f.filename))
+
inzip.close()
outzip.close()
return missing_keys