Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion backend/doc/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,11 +129,13 @@ class Settings(BaseSettings):
USFM_RESOURCE_TYPES: Sequence[str] = [
"avd",
"ayt",
"bpb",
"blv",
"cuv",
"f10",
"nav",
"reg",
"tbi",

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should bpb and tbi be added to the lists in page.svelte:49 and 99?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, thanks. I really don't like that regex code in the UI. Will improve that, it is a code smell for sure.

# "udb", # Content team doesn't want udb used for any language, e.g., en, mr, tl, gu
"ugnt",
"uhb",
Expand All @@ -145,14 +147,16 @@ class Settings(BaseSettings):
# there are any) that we want to be available to users. These are all
# that I found of relevance in the data API.
RESOURCE_TYPE_CODES_AND_NAMES: Mapping[str, str] = {
"ayt": "Bahasa Indonesian Bible",
"ayt": "Alkitab Yang Terbuka (Easy-to-Read Indonesian Bible)",
"bc": "Bible Commentary",
"blv": "Portuguese Bíblia Livre",
"bpb": "Bulgarian Protestant Bible",
"cuv": "新标点和合本",
"f10": "French Louis Segond 1910 Bible",
"nav": "New Arabic Version (Ketab El Hayat)",
"reg": "Regular",
"rg": "NT Survey Reviewers' Guide",
"tbi": "Terjemahan Baru (Indonesian New Translation Bible)",
"tn": "Translation Notes",
"tn-condensed": "Condensed Translation Notes",
"tq": "Translation Questions",
Expand Down
42 changes: 5 additions & 37 deletions backend/doc/domain/assembly_strategies/assemble_by_book.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
get_usfm_and_tw,
get_usfm_and_tw_verse,
get_non_usfm_resources_verse,
order_usfm_resources,
rg_chapter_verses,
)
from doc.domain.bible_books import BOOK_ID_MAP, BOOK_NAMES
Expand Down Expand Up @@ -47,9 +48,6 @@ def assemble_content_by_book(
show_tn_chapter_intro: bool,
book_names: Mapping[str, str] = BOOK_NAMES,
book_id_map: dict[str, int] = BOOK_ID_MAP,
resource_type_codes_and_names: Mapping[
str, str
] = settings.RESOURCE_TYPE_CODES_AND_NAMES,
) -> list[DocumentPart]:
document_parts: list[DocumentPart] = []
lang_codes = collect_unique_lang_codes(
Expand All @@ -69,23 +67,8 @@ def assemble_content_by_book(
usfm_book2 = None
if len(selected_usfm_books) == 1:
usfm_book = selected_usfm_books[0]
elif (
len(selected_usfm_books) == 2
): # Second USFM chosen, e.g., fr f10, tl udb, pt-br blv.
# Assuming f10 should be treated as secondary to ulb for fr and blv as a
# secondary to ulb for pt-br.
# TODO Later we might do resources types by clicked order at which point we would likely
# just use the body of the else clause below.
if selected_usfm_books[0].resource_type_name in [
resource_type_codes_and_names.get("f10", ""),
resource_type_codes_and_names.get("udb", ""),
resource_type_codes_and_names.get("blv", ""),
]:
usfm_book = selected_usfm_books[1]
usfm_book2 = selected_usfm_books[0]
else:
usfm_book = selected_usfm_books[0]
usfm_book2 = selected_usfm_books[1]
elif len(selected_usfm_books) == 2:
usfm_book, usfm_book2 = order_usfm_resources(selected_usfm_books)
tn_book = next(
(
tn_book
Expand Down Expand Up @@ -227,9 +210,6 @@ def assemble_content_by_verse_book_at_a_time(
show_rg_chapter_commentary: bool,
book_names: Mapping[str, str] = BOOK_NAMES,
book_id_map: dict[str, int] = BOOK_ID_MAP,
resource_type_codes_and_names: Mapping[
str, str
] = settings.RESOURCE_TYPE_CODES_AND_NAMES,
) -> list[DocumentPart]:
document_parts: list[DocumentPart] = []
lang_codes = collect_unique_lang_codes(
Expand All @@ -249,20 +229,8 @@ def assemble_content_by_verse_book_at_a_time(
usfm_book2 = None
if len(selected_usfm_books) == 1:
usfm_book = selected_usfm_books[0]
elif len(selected_usfm_books) == 2: # Second USFM chosen, e.g., fr f10
# TODO Later we might do resources types by clicked order at which point we would likely
# just use the else clause below.
# Assuming f10 should be treated as secondary to ulb for fr
if selected_usfm_books[0].resource_type_name in [
resource_type_codes_and_names.get("f10", ""),
resource_type_codes_and_names.get("udb", ""),
resource_type_codes_and_names.get("blv", ""),
]:
usfm_book = selected_usfm_books[1]
usfm_book2 = selected_usfm_books[0]
else:
usfm_book = selected_usfm_books[0]
usfm_book2 = selected_usfm_books[1]
elif len(selected_usfm_books) == 2:
usfm_book, usfm_book2 = order_usfm_resources(selected_usfm_books)
tn_book = next(
(
tn_book
Expand Down
34 changes: 4 additions & 30 deletions backend/doc/domain/assembly_strategies/assemble_by_chapter.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
get_non_usfm_resources_chapter,
get_usfm_and_tw,
get_usfm_and_tw_verse,
order_usfm_resources,
rg_chapter_verses,
tn_chapter_intro,
tnc_chapter_intro,
Expand Down Expand Up @@ -276,9 +277,6 @@ def assemble_usfm_by_chapter(
show_tn_chapter_intro: bool,
book_chapters: Mapping[str, int] = BOOK_CHAPTERS,
fmt_str: str = settings.BOOK_NAME_FMT_STR,
resource_type_codes_and_names: Mapping[
str, str
] = settings.RESOURCE_TYPE_CODES_AND_NAMES,
) -> list[DocumentPart]:
is_rtl = usfm_books[0].lang_direction == LangDirEnum.RTL if usfm_books else False
document_parts: list[DocumentPart] = []
Expand Down Expand Up @@ -312,20 +310,8 @@ def assemble_usfm_by_chapter(
usfm_book2 = None
if len(selected_usfm_books) == 1:
usfm_book = selected_usfm_books[0]
elif len(selected_usfm_books) == 2: # Second USFM chosen, e.g., fr f10
# Assuming f10 should be treated as secondary to ulb for fr
# TODO Later we might do resources types by clicked order at which point we would likely
# just use the else clause below.
if selected_usfm_books[0].resource_type_name in [
resource_type_codes_and_names.get("f10", ""),
resource_type_codes_and_names.get("udb", ""),
resource_type_codes_and_names.get("blv", ""),
]:
usfm_book = selected_usfm_books[1]
usfm_book2 = selected_usfm_books[0]
else:
usfm_book = selected_usfm_books[0]
usfm_book2 = selected_usfm_books[1]
elif len(selected_usfm_books) == 2:
usfm_book, usfm_book2 = order_usfm_resources(selected_usfm_books)
if usfm_book:
document_parts.append(
DocumentPart(
Expand Down Expand Up @@ -437,9 +423,6 @@ def assemble_usfm_by_verse_chapter_at_a_time(
show_rg_chapter_commentary: bool,
book_chapters: Mapping[str, int] = BOOK_CHAPTERS,
fmt_str: str = settings.RESOURCE_TYPE_NAME_FMT_STR,
resource_type_codes_and_names: Mapping[
str, str
] = settings.RESOURCE_TYPE_CODES_AND_NAMES,
) -> list[DocumentPart]:
is_rtl = usfm_books[0].lang_direction == LangDirEnum.RTL if usfm_books else False
document_parts: list[DocumentPart] = []
Expand Down Expand Up @@ -521,16 +504,7 @@ def assemble_usfm_by_verse_chapter_at_a_time(
if len(selected_usfm_books) == 1:
usfm_book = selected_usfm_books[0]
elif len(selected_usfm_books) == 2:
if selected_usfm_books[0].resource_type_name in [
resource_type_codes_and_names.get("f10", ""),
resource_type_codes_and_names.get("udb", ""),
resource_type_codes_and_names.get("blv", ""),
]:
usfm_book2 = selected_usfm_books[0]
usfm_book = selected_usfm_books[1]
else:
usfm_book = selected_usfm_books[0]
usfm_book2 = selected_usfm_books[1]
usfm_book, usfm_book2 = order_usfm_resources(selected_usfm_books)
if usfm_book and chapter_num in usfm_book.chapters:
usfm_chapter = usfm_book.chapters[chapter_num]
if usfm_book2 and chapter_num in usfm_book2.chapters:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"""

from re import search
from typing import Optional, Sequence
from typing import Mapping, Optional, Sequence

from doc.config import settings
from doc.domain.bible_books import BOOK_ID_MAP
Expand Down Expand Up @@ -1197,6 +1197,42 @@ def filter_books_by_lang_code(
)


def order_usfm_resources(
usfm_books: Sequence[USFMBook],
resource_type_codes_and_names: Mapping[
str, str
] = settings.RESOURCE_TYPE_CODES_AND_NAMES,
) -> tuple[USFMBook, USFMBook]:
usfm_book0 = usfm_books[0]
if (
usfm_book0.lang_code == "fr"
and usfm_book0.resource_type_name
in [
resource_type_codes_and_names.get("ulb", ""),
]
or usfm_book0.resource_type_name
in [
resource_type_codes_and_names.get("udb", ""),
]
or usfm_book0.lang_code == "id"
and usfm_book0.resource_type_name
in [
resource_type_codes_and_names.get("ayt", ""),
]
or usfm_book0.lang_code == "pt-br"
and usfm_book0.resource_type_name
in [
resource_type_codes_and_names.get("blv", ""),
]
):
usfm_book = usfm_books[1]
usfm_book2 = usfm_books[0]
else:
usfm_book = usfm_books[0]
usfm_book2 = usfm_books[1]
return usfm_book, usfm_book2


if __name__ == "__main__":

# To run the doctests in this module, in the root of the project do:
Expand Down
Loading
Loading