Skip to content
Merged
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
Binary file added fonts/sarasa-mono-sc-light-nerd-font+patched.ttf
Binary file not shown.
43 changes: 37 additions & 6 deletions python/PiFinder/ui/fonts.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@

from pathlib import Path
from PIL import ImageFont
import gettext
import os


class Font:
Expand All @@ -20,9 +22,8 @@ def __init__(
height: int = 0,
width: int = 0,
):
self.font = ImageFont.truetype(
ttf_file, size, layout_engine=ImageFont.Layout.BASIC
)
# CHANGED: Removed layout_engine for better Unicode support
self.font = ImageFont.truetype(ttf_file, size)

# calculate height/width
# Use several chars to get space between
Expand All @@ -43,10 +44,40 @@ def __init__(
huge_size=35,
screen_width=128,
):
base_dir = Path(__file__).parent.parent.parent
font_path = str(Path(Path.cwd(), "../fonts"))
boldttf = str(Path(font_path, "RobotoMonoNerdFontMono-Bold.ttf"))
regularttf = str(Path(font_path, "RobotoMonoNerdFontMono-Regular.ttf"))

print(font_path)
# CHANGED: Check if Chinese language is active
is_chinese = False
try:
locale_path = str(base_dir / "locale")
# Try to load Chinese translation
lang = gettext.translation(
"messages",
locale_path,
languages=["zh"],
fallback=True
)
# Check if translation is actually Chinese (not fallback)
info = lang.info()
if info and info.get('language', '').startswith('zh'):
# Additional check: verify translation works
test = lang.gettext("Star")
if test and test != "Star":
is_chinese = True
except Exception:
pass

if is_chinese:
# Use Chinese font for Chinese language
chinesettf = str(Path(font_path, "sarasa-mono-sc-light-nerd-font+patched.ttf"))
boldttf = chinesettf
regularttf = chinesettf
else:
# Use default fonts for other languages
boldttf = str(Path(font_path, "RobotoMonoNerdFontMono-Bold.ttf"))
regularttf = str(Path(font_path, "RobotoMonoNerdFontMono-Regular.ttf"))
print(boldttf)
self.base = Font(boldttf, base_size, screen_width) # 10
self.bold = Font(boldttf, bold_size, screen_width) # 12
self.large = Font(regularttf, large_size, screen_width) # 15
Expand Down
5 changes: 5 additions & 0 deletions python/PiFinder/ui/menu_structure.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ def _(key: str) -> Any:
s = _("Language: en")
s = _("Language: es")
s = _("Language: fr")
s = _("Language: zh")
s = s
del s

Expand Down Expand Up @@ -719,6 +720,10 @@ def _(key: str) -> Any:
"name": _("Spanish"),
"value": "es",
},
{
"name": _("Chinese"),
"value": "zh",
},
],
},
],
Expand Down
Binary file added python/locale/zh/LC_MESSAGES/messages.mo
Binary file not shown.
Loading