Skip to content

Commit 9ace47a

Browse files
Merge pull request #992 from SuffolkLITLab/internationalize-bundle
Better internationalization possibilities within al_document.py
2 parents 6d80c60 + 38ee0fe commit 9ace47a

File tree

4 files changed

+56
-32
lines changed

4 files changed

+56
-32
lines changed

docassemble/AssemblyLine/al_document.py

Lines changed: 32 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
DAStaticFile,
3030
alpha,
3131
showifdef,
32+
word,
3233
)
3334
from docassemble.base.pdfa import pdf_to_pdfa
3435
from textwrap import wrap
@@ -2008,11 +2009,11 @@ def download_list_html(
20082009
refresh: bool = True,
20092010
pdfa: bool = False,
20102011
include_zip: bool = True,
2011-
view_label="View",
2012+
view_label: Optional[str] = None,
20122013
view_icon: str = "eye",
2013-
download_label: str = "Download",
2014+
download_label: Optional[str] = None,
20142015
download_icon: str = "download",
2015-
send_label: str = "Send",
2016+
send_label: Optional[str] = None,
20162017
send_icon: str = "envelope",
20172018
zip_label: Optional[str] = None,
20182019
zip_icon: str = "file-archive",
@@ -2035,11 +2036,11 @@ def download_list_html(
20352036
refresh (bool): Flag to reconsider the 'enabled' attribute, default is True.
20362037
pdfa (bool): Flag to return documents in PDF/A format, default is False.
20372038
include_zip (bool): Flag to include a zip option, default is True.
2038-
view_label (str): Label for the 'view' button, default is "View".
2039+
view_label (str): Label for the 'view' button, default is self.view_label or "View".
20392040
view_icon (str): Icon for the 'view' button, default is "eye".
2040-
download_label (str): Label for the 'download' button, default is "Download".
2041+
download_label (str): Label for the 'download' button, default is self.download_label or "Download".
20412042
download_icon (str): Icon for the 'download' button, default is "download".
2042-
send_label (str): Label for the 'send' button. Default is "Send".
2043+
send_label (str): Label for the 'send' button. Default is self.send_label or "Send".
20432044
send_icon (str): Fontawesome icon for the 'send' button. Default is "envelope".
20442045
zip_label (Optional[str]): Label for the zip option. If not provided, uses the generic template for `self.zip_label` ("Download all").
20452046
zip_icon (str): Icon for the zip option, default is "file-archive".
@@ -2056,11 +2057,14 @@ def download_list_html(
20562057
Returns:
20572058
str: HTML representation of a table with documents and their associated actions.
20582059
"""
2059-
if not hasattr(self, "_cached_zip_label"):
2060-
self._cached_zip_label = str(self.zip_label)
2060+
if not view_label:
2061+
view_label = self.view_label or word("View")
20612062

2062-
if not hasattr(self, "_cached_full_pdf_label"):
2063-
self._cached_full_pdf_label = str(self.full_pdf_label)
2063+
if not download_label:
2064+
download_label = self.download_label or word("Download")
2065+
2066+
if not send_label:
2067+
send_label = self.send_label or word("Send")
20642068

20652069
if zip_format is None:
20662070
zip_format = format
@@ -2135,7 +2139,7 @@ def download_list_html(
21352139
# Add a zip file row if included
21362140
if include_zip and bundled_zip:
21372141
if not zip_label:
2138-
zip_label = self._cached_zip_label
2142+
zip_label = str(self.zip_label)
21392143
filename_root = os.path.splitext(str(self.filename))[0]
21402144
zip_button = action_button_html(
21412145
bundled_zip.url_for(
@@ -2154,7 +2158,7 @@ def download_list_html(
21542158

21552159
if include_full_pdf and bundled_pdf:
21562160
if not full_pdf_label:
2157-
full_pdf_label = self._cached_full_pdf_label
2161+
full_pdf_label = str(self.full_pdf_label)
21582162
filename_root = os.path.splitext(str(self.filename))[0]
21592163
full_pdf_button = action_button_html(
21602164
bundled_pdf.url_for(
@@ -2251,12 +2255,17 @@ def download_html(
22512255
return html
22522256

22532257
def send_email_table_row(
2254-
self, key: str = "final", send_label: str = "Send", send_icon: str = "envelope"
2258+
self,
2259+
key: str = "final",
2260+
send_label: Optional[str] = None,
2261+
send_icon: str = "envelope",
22552262
) -> str:
22562263
"""
22572264
Generate HTML doc table row for an input box and button that allows
22582265
someone to send the bundle to the specified email address.
22592266
2267+
This should normally only be called by download_list_html.
2268+
22602269
Args:
22612270
key (str): A key used to identify which version of the ALDocument to send. Defaults to "final".
22622271
send_label (str): Label for the 'send' button. Default is "Send".
@@ -2265,14 +2274,12 @@ def send_email_table_row(
22652274
Returns:
22662275
str: The generated HTML string for the table row.
22672276
"""
2277+
if not send_label:
2278+
send_label = self.send_label or word("Send")
2279+
22682280
if not self.has_enabled_documents():
22692281
return "" # Don't let people email an empty set of documents
2270-
if not hasattr(self, "_cached_get_email_copy"):
2271-
self._cached_get_email_copy = str(self.get_email_copy)
2272-
if not hasattr(self, "_cached_include_editable_documents"):
2273-
self._cached_include_editable_documents = str(
2274-
self.include_editable_documents
2275-
)
2282+
22762283
name = html_safe_str(self.instanceName) + random_suffix()
22772284
al_wants_editable_input_id = "_ignore_al_wants_editable_" + name
22782285
al_email_input_id = "_ignore_al_doc_email_" + name
@@ -2310,7 +2317,7 @@ def send_button_to_html(
23102317
email: str,
23112318
editable: Optional[bool] = None,
23122319
template_name: str = "",
2313-
label: str = "Send",
2320+
label: Optional[str] = None,
23142321
icon: str = "envelope",
23152322
color: str = "primary",
23162323
key: str = "final",
@@ -2334,10 +2341,11 @@ def send_button_to_html(
23342341
Returns:
23352342
str: The generated HTML string for the button.
23362343
"""
2344+
if label is None:
2345+
label = self.send_label or word("Send")
2346+
23372347
if not self.has_enabled_documents():
23382348
return "" # Don't let people email an empty set of documents
2339-
if not hasattr(self, "_cached_get_email_copy"):
2340-
self._cached_get_email_copy = str(self.get_email_copy)
23412349
name = html_safe_str(self.instanceName) + random_suffix()
23422350
al_send_button_id = "al_send_email_to_button_" + name
23432351

@@ -2404,12 +2412,6 @@ def send_button_html(
24042412
"""
24052413
if not self.has_enabled_documents():
24062414
return "" # Don't let people email an empty set of documents
2407-
if not hasattr(self, "_cached_get_email_copy"):
2408-
self._cached_get_email_copy = str(self.get_email_copy)
2409-
if not hasattr(self, "_cached_include_editable_documents"):
2410-
self._cached_include_editable_documents = str(
2411-
self.include_editable_documents
2412-
)
24132415

24142416
if isinstance(preferred_formats, str):
24152417
preferred_formats = [preferred_formats]
@@ -2443,7 +2445,7 @@ def send_button_html(
24432445
# Container of whole email section with header
24442446
return_str = f"""
24452447
<fieldset class="al_send_bundle al_send_section_alone {html_safe_str(self.instanceName)}" id="al_send_bundle_{name}" name="al_send_bundle_{name}">
2446-
<legend class="h4 al_doc_email_header">{self._cached_get_email_copy}</legend>
2448+
<legend class="h4 al_doc_email_header">{str(self.get_email_copy)}</legend>
24472449
"""
24482450
# "Editable" checkbox
24492451
if (
@@ -2456,7 +2458,7 @@ def send_button_html(
24562458
<div class="form-check-container">
24572459
<div class="form-check">
24582460
<input class="form-check-input al_wants_editable" type="checkbox" id="{al_wants_editable_input_id}">
2459-
<label class="al_wants_editable form-check-label" for="{al_wants_editable_input_id}">{self._cached_include_editable_documents}
2461+
<label class="al_wants_editable form-check-label" for="{al_wants_editable_input_id}">{str(self.include_editable_documents)}
24602462
</label>
24612463
</div>
24622464
</div>

docassemble/AssemblyLine/data/questions/ql_baseline.yml

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2593,4 +2593,20 @@ data:
25932593
- Lt.
25942594
- Sgt.
25952595
- Fr.
2596-
- Sr.
2596+
- Sr.
2597+
---
2598+
generic object: ALDocumentBundle
2599+
template: x.view_label
2600+
content: "View"
2601+
---
2602+
generic object: ALDocumentBundle
2603+
template: x.download_label
2604+
content: "Download"
2605+
---
2606+
generic object: ALDocumentBundle
2607+
template: x.send_label
2608+
content: "Send"
2609+
---
2610+
generic object: ALDocumentBundle
2611+
template: x.send_button_to_label
2612+
content: "Send"

docassemble/AssemblyLine/data/questions/test_aldocument.yml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
---
22
include:
3-
- al_package.yml
3+
- assembly_line.yml
4+
---
5+
code: |
6+
al_interview_languages = ["en", "es", "ht", "pt"]
47
---
58
metadata:
69
title: |

docassemble/AssemblyLine/data/questions/test_question_library.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22
include:
33
- assembly_line.yml
44
---
5+
code: |
6+
al_interview_languages = ["en", "es", "ht", "pt"]
7+
---
58
metadata:
69
title: |
710
Test Question Library

0 commit comments

Comments
 (0)