Skip to content

Commit

Permalink
Prefer Master Duel zh-CN translations to OurOCG
Browse files Browse the repository at this point in the history
  • Loading branch information
kevinlul committed Jul 6, 2024
1 parent 1adfff6 commit 76bcd49
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 23 deletions.
17 changes: 5 additions & 12 deletions src/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -186,9 +186,7 @@ def transform_image(image: str) -> List[Dict[str, str]]:
return [transform_image_entry(entry) for entry in tokens]


def transform_names(
wikitext: Dict[str, str], zh_cn_fallback: Optional[str] = None
) -> Dict[str, str]:
def transform_names(wikitext: Dict[str, str]) -> Dict[str, str]:
return {
"en": wikitext["en_name"],
"de": wikitext.get("de_name"),
Expand All @@ -201,13 +199,11 @@ def transform_names(
"ko": wikitext.get("ko_name"),
"ko_rr": wikitext.get("ko_rr_name"),
"zh-TW": wikitext.get("tc_name"),
"zh-CN": wikitext.get("sc_name") or zh_cn_fallback,
"zh-CN": wikitext.get("sc_name"),
}


def transform_texts(
wikitext: Dict[str, str], zh_cn_fallback: Optional[str] = None
) -> Dict[str, str]:
def transform_texts(wikitext: Dict[str, str]) -> Dict[str, str]:
return {
"en": str_or_none(wikitext.get("lore")), # should never be none
"de": str_or_none(wikitext.get("de_lore")),
Expand All @@ -218,7 +214,7 @@ def transform_texts(
"ja": str_or_none(wikitext.get("ja_lore")),
"ko": str_or_none(wikitext.get("ko_lore")),
"zh-TW": str_or_none(wikitext.get("tc_lore")),
"zh-CN": str_or_none(wikitext.get("sc_lore") or zh_cn_fallback),
"zh-CN": str_or_none(wikitext.get("sc_lore")),
}


Expand Down Expand Up @@ -285,10 +281,7 @@ def annotate_shared(document: Dict[str, Any], wikitext: Dict[str, str]) -> None:
"ja": str_or_none(wikitext.get("ja_pendulum_effect")),
"ko": str_or_none(wikitext.get("ko_pendulum_effect")),
"zh-TW": str_or_none(wikitext.get("tc_pendulum_effect")),
"zh-CN": str_or_none(
wikitext.get("sc_pendulum_effect")
or wikitext.get("ourocg_pendulum")
),
"zh-CN": str_or_none(wikitext.get("sc_pendulum_effect")),
}
# bonus derived fields
if "ritualcard" in wikitext:
Expand Down
32 changes: 21 additions & 11 deletions src/job_ocgtcg.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,18 +28,28 @@


def annotate_zh_cn(
yaml: YAML, logger: logging.Logger, zh_cn_dir: str, wikitext: Dict[str, str]
yaml: YAML, logger: logging.Logger, document: Dict[str, str], zh_cn_dir: str
) -> None:
password = int_or_none(wikitext.get("password") or "")
if document["name"]["zh-CN"] and document["text"]["zh-CN"]:
return
password = int_or_none(document.get("password") or "")
zh_cn_path = os.path.join(zh_cn_dir, f"{password}.yaml")
if os.path.isfile(zh_cn_path):
logger.info(f"zh-CN: {zh_cn_path}")
with open(zh_cn_path) as f:
document = yaml.load(f)
wikitext["ourocg_name"] = document["name"]
wikitext["ourocg_text"] = document["text"]
if document.get("pendulum"):
wikitext["ourocg_pendulum"] = document["pendulum"]
zh_cn = yaml.load(f)
if not document["name"]["zh-CN"]:
document["name"]["zh-CN"] = zh_cn["name"]
if not document["text"]["zh-CN"]:
document["text"]["zh-CN"] = LiteralScalarString(zh_cn["text"])
if (
document.get("pendulum_effect")
and not document["pendulum_effect"]["zh-CN"]
and zh_cn.get("pendulum")
):
document["pendulum_effect"]["zh-CN"] = LiteralScalarString(
zh_cn["pendulum"]
)


def transform_structure(
Expand Down Expand Up @@ -74,8 +84,8 @@ def transform_structure(
document = {
"konami_id": konami_id,
"password": password,
"name": transform_names(wikitext, wikitext.get("ourocg_name")),
"text": transform_texts(wikitext, wikitext.get("ourocg_text")),
"name": transform_names(wikitext),
"text": transform_texts(wikitext),
}
annotate_shared(document, wikitext)
if wikitext.get("image"):
Expand Down Expand Up @@ -414,8 +424,6 @@ def job(
logger.info(f"Skip: {filepath}")
continue
properties["yugipedia_page_id"] = page_id
if zh_cn_dir:
annotate_zh_cn(yaml, logger, zh_cn_dir, properties)
document = transform_structure(logger, properties)
if document:
annotate_limit_regulation(document, tcg_vector, ocg_vector)
Expand All @@ -427,6 +435,8 @@ def job(
annotate_assignments(document, assignments)
if ko_override:
override_ko(logger, document, ko_override)
if zh_cn_dir:
annotate_zh_cn(yaml, logger, document, zh_cn_dir)
write_output(yaml, logger, document)
if return_results:
results.append(document)
Expand Down

0 comments on commit 76bcd49

Please sign in to comment.