Skip to content
This repository has been archived by the owner on Jul 26, 2023. It is now read-only.

Commit

Permalink
updated translations including Thai and Tamil. There is a bug in fpdf…
Browse files Browse the repository at this point in the history
…2 (issue #7)
  • Loading branch information
carlhiggs committed Apr 6, 2022
1 parent 1868e66 commit 09bd5d6
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 2 deletions.
26 changes: 24 additions & 2 deletions scorecard_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,7 @@ def li_profile(
f"{num}%",
ha="center",
va="center",
backgroundcolor="white",
size=textsize,
)
# Add text to explain the meaning of the height of the bar and the
Expand Down Expand Up @@ -607,7 +608,10 @@ def generate_resources(


def pdf_template_setup(
template, template_sheet="scorecard_template_elements", font=None
template,
template_sheet="scorecard_template_elements",
font=None,
language="English",
):
"""
Takes a template xlsx sheet defining elements for use in fpdf2's FlexTemplate function.
Expand All @@ -622,6 +626,19 @@ def pdf_template_setup(
# read in elements
elements = pd.read_excel(template, sheet_name=template_sheet)
document_pages = elements.page.unique()

# Conditional formatting to help avoid inappropriate line breaks and gaps in Thai
if language == "Thai":
elements["align"] = elements["align"].replace("J", "L")
elements.loc[
(elements["type"] == "T") & (elements["size"] < 12), "size"
] = (
elements.loc[
(elements["type"] == "T") & (elements["size"] < 12), "size"
]
- 1
)

if font is not None:
elements.loc[elements.font == "custom", "font"] = font

Expand Down Expand Up @@ -832,7 +849,9 @@ def generate_scorecard(
phrases = prepare_phrases(xlsx_scorecard_template, city, language)

# Set up PDF document template pages
pages = pdf_template_setup(xlsx_scorecard_template, font=font)
pages = pdf_template_setup(
xlsx_scorecard_template, font=font, language=language
)
pages = format_pages(pages, phrases)

# initialise PDF
Expand Down Expand Up @@ -961,6 +980,9 @@ def generate_scorecard(
template = FlexTemplate(pdf, elements=pages["5"])
template["citations"] = phrases["citations"]
template["study_executive_names"] = phrases["study_executive_names"]
template["local_collaborators"] = template["local_collaborators"].format(
title_city=phrases["title_city"]
)
template["local_collaborators_names"] = phrases[
"local_collaborators_names"
]
Expand Down
Binary file modified scorecard_template_elements.xlsx
Binary file not shown.

0 comments on commit 09bd5d6

Please sign in to comment.