Spaces:
Build error
Build error
Commit
·
fc7ba9a
1
Parent(s):
619355d
Update app.py
Browse files
app.py
CHANGED
@@ -108,7 +108,9 @@ def docx_replace(doc, data):
|
|
108 |
for paragraph in cell.paragraphs:
|
109 |
paragraphs.append(paragraph)
|
110 |
|
111 |
-
for
|
|
|
|
|
112 |
for p in paragraphs:
|
113 |
#key_name = '${{{}}}'.format(key) # I'm using placeholders in the form ${PlaceholderName}
|
114 |
key_name = key
|
@@ -205,17 +207,17 @@ def translate_fill(document_name,output_file, src, trg):
|
|
205 |
|
206 |
template_document = Document(document_name)
|
207 |
|
208 |
-
variables =
|
209 |
for paragraph in template_document.paragraphs:
|
210 |
if(paragraph.text.strip() != ""):
|
211 |
-
variables
|
212 |
|
213 |
for t in template_document.tables:
|
214 |
for row in t.rows:
|
215 |
for cell in row.cells:
|
216 |
for paragraph in cell.paragraphs:
|
217 |
if(paragraph.text.strip() != ""):
|
218 |
-
variables
|
219 |
|
220 |
docx_replace(template_document, variables)
|
221 |
template_document.save(output_file)
|
|
|
108 |
for paragraph in cell.paragraphs:
|
109 |
paragraphs.append(paragraph)
|
110 |
|
111 |
+
for each in data:
|
112 |
+
key = list(each.keys())[0]
|
113 |
+
val = list(each.values())[0]
|
114 |
for p in paragraphs:
|
115 |
#key_name = '${{{}}}'.format(key) # I'm using placeholders in the form ${PlaceholderName}
|
116 |
key_name = key
|
|
|
207 |
|
208 |
template_document = Document(document_name)
|
209 |
|
210 |
+
variables = []
|
211 |
for paragraph in template_document.paragraphs:
|
212 |
if(paragraph.text.strip() != ""):
|
213 |
+
variables.append({paragraph.text : translate_paragraph(paragraph.text, src, trg)})
|
214 |
|
215 |
for t in template_document.tables:
|
216 |
for row in t.rows:
|
217 |
for cell in row.cells:
|
218 |
for paragraph in cell.paragraphs:
|
219 |
if(paragraph.text.strip() != ""):
|
220 |
+
variables.append({paragraph.text : translate_paragraph(paragraph.text, src, trg)})
|
221 |
|
222 |
docx_replace(template_document, variables)
|
223 |
template_document.save(output_file)
|