Skip to content

Commit 8742680

Browse files
committed
fix(scripts): handle non-string titles in translation logic
1 parent fec1781 commit 8742680

File tree

2 files changed

+12
-9
lines changed

2 files changed

+12
-9
lines changed

original/2025-01-14-error-en.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ title: 404
1212
**Page not found :(**
1313

1414
{: .centered }
15-
The requested page could not be found.
15+
The requested page could not be found. Please check the URL or return to the homepage.
1616

1717
{: .centered }
1818
[Home](/ "Home")

scripts/update_lang.py

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -78,15 +78,18 @@ def translate_front_matter(front_matter, target_language, input_file):
7878
if 'title' in front_matter_dict:
7979
print(f" Translating title: {front_matter_dict['title']}")
8080
if not (input_file == 'original/2025-01-11-resume-en.md' and target_language in ['zh', 'fr']):
81-
translated_title = translate_text(front_matter_dict['title'], target_language)
82-
if translated_title:
83-
translated_title = translated_title.strip()
84-
if len(translated_title) > 300:
85-
translated_title = translated_title.split('\n')[0]
86-
front_matter_dict['title'] = translated_title
87-
print(f" Translated title to: {translated_title}")
81+
if isinstance(front_matter_dict['title'], str):
82+
translated_title = translate_text(front_matter_dict['title'], target_language)
83+
if translated_title:
84+
translated_title = translated_title.strip()
85+
if len(translated_title) > 300:
86+
translated_title = translated_title.split('\n')[0]
87+
front_matter_dict['title'] = translated_title
88+
print(f" Translated title to: {translated_title}")
89+
else:
90+
print(f" Title translation failed for: {input_file}")
8891
else:
89-
print(f" Title translation failed for: {input_file}")
92+
print(f" Title is not a string, skipping translation for: {input_file}")
9093
else:
9194
print(f" Skipping title translation for {input_file} to {target_language}")
9295
# Always set lang to target_language

0 commit comments

Comments
 (0)