From 35067ea1ad567e8c342a52fba2bd22fb7510ac12 Mon Sep 17 00:00:00 2001 From: linearcombination <4829djaskdfj@gmail.com> Date: Thu, 2 Jul 2026 15:32:42 -0700 Subject: [PATCH 1/3] Provide option to link to TW word definitions online. Closes #321 By default this is now True rather than including TW word definitions in generated documents. --- backend/doc/config.py | 4 ++++ backend/doc/domain/document_generator.py | 7 ++++++- backend/doc/utils/tw_utils.py | 19 +++++++++---------- 3 files changed, 19 insertions(+), 11 deletions(-) diff --git a/backend/doc/config.py b/backend/doc/config.py index a5c63522..41bc44ce 100755 --- a/backend/doc/config.py +++ b/backend/doc/config.py @@ -180,6 +180,10 @@ class Settings(BaseSettings): RESOURCE_TYPE_NAME_FMT_STR: str = "

{}

" HR: str = "
" TW_WORD_LIST_VERTICAL: bool = False + BIEL_TW_RESOURCE_URL_FMT_STR: str = ( + "{}" + ) + LINK_RATHER_THAN_INCLUDE_TW_DEFINITIONS: bool = True DOWNLOAD_ASSETS: bool = False # If true then download assets, else clone assets diff --git a/backend/doc/domain/document_generator.py b/backend/doc/domain/document_generator.py index 8032863f..0b5c488b 100755 --- a/backend/doc/domain/document_generator.py +++ b/backend/doc/domain/document_generator.py @@ -559,6 +559,7 @@ def assemble_content( tw_books: Sequence[TWBook], bc_books: Sequence[BCBook], rg_books: Sequence[RGBook], + link_rather_than_include_tw_definitions: bool = settings.LINK_RATHER_THAN_INCLUDE_TW_DEFINITIONS, ) -> list[DocumentPart]: """ Assemble and return the content from all requested resources according to the @@ -652,7 +653,11 @@ def assemble_content( ) t1 = time.time() logger.info("Time for interleaving document: %s", t1 - t0) - if tw_books and not document_request.layout_for_print: + if ( + tw_books + and not link_rather_than_include_tw_definitions + and not document_request.layout_for_print + ): t0 = time.time() # Add the translation words definition section for each language requested. unique_tw_books = filter_unique_by_lang_code(tw_books) diff --git a/backend/doc/utils/tw_utils.py b/backend/doc/utils/tw_utils.py index 23c36471..c1abf7c6 100644 --- a/backend/doc/utils/tw_utils.py +++ b/backend/doc/utils/tw_utils.py @@ -23,7 +23,6 @@ ) from doc.utils.list_utils import unique_list_of_strings - logger = settings.logger(__name__) TW = "tw" @@ -181,8 +180,9 @@ def translation_words_content( tw_book: TWBook, content: str, use_section_visual_separator: bool, - tw_word_list_vertical: bool = settings.TW_WORD_LIST_VERTICAL, + link_rather_than_include_tw_definitions: bool = settings.LINK_RATHER_THAN_INCLUDE_TW_DEFINITIONS, resource_type_name_fmt_str: str = settings.RESOURCE_TYPE_NAME_FMT_STR, + biel_tw_resource_path_fmt_str: str = settings.BIEL_TW_RESOURCE_URL_FMT_STR, ) -> list[DocumentPart]: is_rtl = tw_book and tw_book.lang_direction == LangDirEnum.RTL document_parts: list[DocumentPart] = [] @@ -196,17 +196,19 @@ def translation_words_content( use_section_visual_separator=False, ) ) - if tw_word_list_vertical: + if link_rather_than_include_tw_definitions: document_parts.append( DocumentPart( - content="", + + "", is_rtl=is_rtl, use_section_visual_separator=False, ) @@ -221,9 +223,6 @@ def translation_words_content( for localized_word, word in unique_words ] ) - + "", - is_rtl=is_rtl, - use_section_visual_separator=False, ) ) return document_parts From 21012970c6314c4e533da44030cff4ca909c5771 Mon Sep 17 00:00:00 2001 From: linearcombination <4829djaskdfj@gmail.com> Date: Thu, 9 Jul 2026 17:03:11 -0700 Subject: [PATCH 2/3] Fix issue with regression when LINK_RATHER_THAN_INCLUDE_TW_DEFINITIONS is False Fixed issue raised in code review. Also clean up code a bit to remove magic strings --- backend/doc/config.py | 1 + backend/doc/utils/tw_utils.py | 16 ++++++++++++---- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/backend/doc/config.py b/backend/doc/config.py index 41bc44ce..fceaac80 100755 --- a/backend/doc/config.py +++ b/backend/doc/config.py @@ -183,6 +183,7 @@ class Settings(BaseSettings): BIEL_TW_RESOURCE_URL_FMT_STR: str = ( "{}" ) + TW_RESOURCE_URL_FMT_STR: str = "{}" LINK_RATHER_THAN_INCLUDE_TW_DEFINITIONS: bool = True DOWNLOAD_ASSETS: bool = False # If true then download assets, else clone assets diff --git a/backend/doc/utils/tw_utils.py b/backend/doc/utils/tw_utils.py index c1abf7c6..55692aea 100644 --- a/backend/doc/utils/tw_utils.py +++ b/backend/doc/utils/tw_utils.py @@ -183,6 +183,9 @@ def translation_words_content( link_rather_than_include_tw_definitions: bool = settings.LINK_RATHER_THAN_INCLUDE_TW_DEFINITIONS, resource_type_name_fmt_str: str = settings.RESOURCE_TYPE_NAME_FMT_STR, biel_tw_resource_path_fmt_str: str = settings.BIEL_TW_RESOURCE_URL_FMT_STR, + tw_resource_path_fmt_str: str = settings.TW_RESOURCE_URL_FMT_STR, + div_open: str = "
", + div_close: str = "
", ) -> list[DocumentPart]: is_rtl = tw_book and tw_book.lang_direction == LangDirEnum.RTL document_parts: list[DocumentPart] = [] @@ -199,7 +202,7 @@ def translation_words_content( if link_rather_than_include_tw_definitions: document_parts.append( DocumentPart( - content="
" + content=div_open + ", ".join( [ biel_tw_resource_path_fmt_str.format( @@ -208,7 +211,7 @@ def translation_words_content( for localized_word, word in unique_words ] ) - + "
", + + div_close, is_rtl=is_rtl, use_section_visual_separator=False, ) @@ -216,13 +219,18 @@ def translation_words_content( else: document_parts.append( DocumentPart( - content="