Skip to content
Open
Show file tree
Hide file tree
Changes from 3 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
1 change: 1 addition & 0 deletions archinstall/lib/args.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@ def from_config(cls, args_config: dict[str, Any], args: Arguments) -> Self:

if archinstall_lang := args_config.get('archinstall-language', None):
arch_config.archinstall_language = translation_handler.get_language_by_name(archinstall_lang)
translation_handler.activate(arch_config.archinstall_language)

if disk_config := args_config.get('disk_config', {}):
enc_password = args_config.get('encryption_password', '')
Expand Down
6 changes: 3 additions & 3 deletions archinstall/lib/general/general_menu.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,9 +106,9 @@ async def select_archinstall_language(languages: list[Language], preset: Languag
group = MenuItemGroup(items, sort_items=True)
group.set_focus_by_value(preset)

title = 'NOTE: If a language can not displayed properly, a proper font must be set manually in the console.\n'
title += 'All available fonts can be found in "/usr/share/kbd/consolefonts"\n'
title += 'e.g. setfont LatGrkCyr-8x16 (to display latin/greek/cyrillic characters)\n'
title = 'NOTE: Console font will be set automatically for supported languages.\n'
title += 'For other languages, fonts can be found in "/usr/share/kbd/consolefonts"\n'
title += 'and set manually with: setfont <fontname>\n'

result = await Selection[Language](
header=title,
Expand Down
30 changes: 29 additions & 1 deletion archinstall/lib/translationhandler.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import gettext
import json
import os
import subprocess
from dataclasses import dataclass
from pathlib import Path
from typing import override
Expand All @@ -14,6 +15,7 @@ class Language:
translation: gettext.NullTranslations
translation_percent: int
translated_lang: str | None
console_font: str | None = None

@property
def display_name(self) -> str:
Expand All @@ -31,6 +33,29 @@ def json(self) -> str:
return self.name_en


_DEFAULT_FONT = 'default8x16'
_ENV_FONT = os.environ.get('FONT')


def _set_console_font(font_name: str | None) -> None:
"""
Set the console font via setfont.
Falls back to default8x16 if font_name is None or setfont fails.
"""
target = font_name or _DEFAULT_FONT

try:
result = subprocess.run(['setfont', target], capture_output=True, check=False, timeout=10)
if result.returncode != 0 and target != _DEFAULT_FONT:
subprocess.run(['setfont', _DEFAULT_FONT], capture_output=True, check=False, timeout=10)
except (FileNotFoundError, subprocess.TimeoutExpired, OSError):
if target != _DEFAULT_FONT:
try:
subprocess.run(['setfont', _DEFAULT_FONT], capture_output=True, check=False, timeout=10)
except (FileNotFoundError, subprocess.TimeoutExpired, OSError):
pass
Comment thread
Softer marked this conversation as resolved.
Outdated


class TranslationHandler:
def __init__(self) -> None:
self._base_pot = 'base.pot'
Expand All @@ -57,6 +82,7 @@ def _get_translations(self) -> list[Language]:
abbr = mapping_entry['abbr']
lang = mapping_entry['lang']
translated_lang = mapping_entry.get('translated_lang', None)
console_font = mapping_entry.get('console_font', None)

try:
# get a translation for a specific language
Expand All @@ -71,7 +97,7 @@ def _get_translations(self) -> list[Language]:
# prevent cases where the .pot file is out of date and the percentage is above 100
percent = min(100, percent)

language = Language(abbr, lang, translation, percent, translated_lang)
language = Language(abbr, lang, translation, percent, translated_lang, console_font)
languages.append(language)
except FileNotFoundError as err:
raise FileNotFoundError(f"Could not locate language file for '{lang}': {err}")
Expand Down Expand Up @@ -134,6 +160,8 @@ def activate(self, language: Language) -> None:
# The install() call has the side effect of assigning GNUTranslations.gettext to builtins._
language.translation.install()

_set_console_font(_ENV_FONT if _ENV_FONT else language.console_font)

def _get_locales_dir(self) -> Path:
"""
Get the locales directory path
Expand Down
2 changes: 1 addition & 1 deletion archinstall/locales/languages.json
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@
{"abbr": "tr", "lang": "Turkish", "translated_lang" : "Türkçe"},
{"abbr": "tw", "lang": "Twi"},
{"abbr": "ug", "lang": "Uighur"},
{"abbr": "uk", "lang": "Ukrainian"},
{"abbr": "uk", "lang": "Ukrainian", "console_font": "UniCyr_8x16"},
{"abbr": "ur", "lang": "Urdu", "translated_lang": "اردو"},
{"abbr": "uz", "lang": "Uzbek", "translated_lang": "O'zbek"},
{"abbr": "ve", "lang": "Venda"},
Expand Down
7 changes: 6 additions & 1 deletion archinstall/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
from archinstall.lib.output import debug, error, info, warn
from archinstall.lib.packages.util import check_version_upgrade
from archinstall.lib.pacman.pacman import Pacman
from archinstall.lib.translationhandler import tr
from archinstall.lib.translationhandler import _ENV_FONT, _set_console_font, tr
from archinstall.lib.utils.util import running_from_iso
from archinstall.tui.ui.components import tui

Expand Down Expand Up @@ -79,6 +79,9 @@ def run() -> int:
OR straight as a module: python -m archinstall
In any case we will be attempting to load the provided script to be run from the scripts/ folder
"""
if _ENV_FONT:
_set_console_font(_ENV_FONT)

arch_config_handler = ArchConfigHandler()

if '--help' in sys.argv or '-h' in sys.argv:
Expand Down Expand Up @@ -159,6 +162,8 @@ def main() -> int:
_error_message(exc)
rc = 1

_set_console_font(None)

return rc


Expand Down
Loading