Handle cyrillic characters (#1309)
* Handle cyrillic characters * Update Co-authored-by: Daniel Girtler <girtler.daniel@gmail.com>
This commit is contained in:
parent
f2492ca574
commit
2d4b262046
|
|
@ -15,4 +15,4 @@ jobs:
|
|||
# one day this will be enabled
|
||||
# run: mypy --strict --module archinstall || exit 0
|
||||
- name: run mypy
|
||||
run: mypy --follow-imports=silent archinstall/lib/menu/selection_menu.py archinstall/lib/menu/global_menu.py archinstall/lib/models/network_configuration.py archinstall/lib/menu/list_manager.py archinstall/lib/user_interaction/network_conf.py archinstall/lib/models/users.py
|
||||
run: mypy --follow-imports=silent archinstall/lib/menu/selection_menu.py archinstall/lib/menu/global_menu.py archinstall/lib/models/network_configuration.py archinstall/lib/menu/list_manager.py archinstall/lib/user_interaction/network_conf.py archinstall/lib/models/users.py archinstall/lib/translation.py
|
||||
|
|
|
|||
|
|
@ -58,10 +58,6 @@ storage['__version__'] = __version__
|
|||
DeferredTranslation.install()
|
||||
|
||||
|
||||
def set_unicode_font():
|
||||
SysCommand('setfont UniCyr_8x16')
|
||||
|
||||
|
||||
def define_arguments():
|
||||
"""
|
||||
Define which explicit arguments do we allow.
|
||||
|
|
@ -249,9 +245,6 @@ def post_process_arguments(arguments):
|
|||
load_config()
|
||||
|
||||
|
||||
# to ensure that cyrillic characters work in the installer
|
||||
# set_unicode_font()
|
||||
|
||||
define_arguments()
|
||||
arguments = get_arguments()
|
||||
post_process_arguments(arguments)
|
||||
|
|
|
|||
|
|
@ -15,15 +15,6 @@ if TYPE_CHECKING:
|
|||
_: Any
|
||||
|
||||
|
||||
def select_archinstall_language(preset_value: str) -> Optional[Any]:
|
||||
"""
|
||||
copied from user_interaction/general_conf.py as a temporary measure
|
||||
"""
|
||||
languages = Translation.get_available_lang()
|
||||
language = Menu(_('Archinstall language'), languages, preset_values=preset_value).run()
|
||||
return language.value
|
||||
|
||||
|
||||
class Selector:
|
||||
def __init__(
|
||||
self,
|
||||
|
|
@ -462,6 +453,7 @@ class GeneralMenu:
|
|||
return mandatory_fields, mandatory_waiting
|
||||
|
||||
def _select_archinstall_language(self, preset_value: str) -> str:
|
||||
from ... import select_archinstall_language
|
||||
language = select_archinstall_language(preset_value)
|
||||
if language is not None:
|
||||
self._translation.activate(language)
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
from __future__ import annotations
|
||||
|
||||
import json
|
||||
import logging
|
||||
import os
|
||||
import gettext
|
||||
|
||||
|
|
@ -13,12 +14,19 @@ if TYPE_CHECKING:
|
|||
|
||||
|
||||
class LanguageDefinitions:
|
||||
_languages = 'languages.json'
|
||||
_cyrillic = 'cyrillic.json'
|
||||
|
||||
def __init__(self):
|
||||
self._mappings = self._get_language_mappings()
|
||||
self._cyrillic_languages = self._get_cyrillic_languages()
|
||||
|
||||
def is_cyrillic(self, language: str) -> bool:
|
||||
return language in self._cyrillic_languages
|
||||
|
||||
def _get_language_mappings(self) -> List[Dict[str, str]]:
|
||||
locales_dir = Translation.get_locales_dir()
|
||||
languages = Path.joinpath(locales_dir, 'languages.json')
|
||||
languages = Path.joinpath(locales_dir, self._languages)
|
||||
|
||||
with open(languages, 'r') as fp:
|
||||
return json.load(fp)
|
||||
|
|
@ -30,6 +38,14 @@ class LanguageDefinitions:
|
|||
|
||||
raise ValueError(f'No language with abbreviation "{abbr}" found')
|
||||
|
||||
def _get_cyrillic_languages(self) -> List[str]:
|
||||
locales_dir = Translation.get_locales_dir()
|
||||
languages = Path.joinpath(locales_dir, self._cyrillic)
|
||||
|
||||
with open(languages, 'r') as fp:
|
||||
data = json.load(fp)
|
||||
return data['languages']
|
||||
|
||||
|
||||
class DeferredTranslation:
|
||||
def __init__(self, message: str):
|
||||
|
|
@ -78,10 +94,26 @@ class Translation:
|
|||
|
||||
def activate(self, name):
|
||||
if language := self._languages.get(name, None):
|
||||
languages = LanguageDefinitions()
|
||||
|
||||
if languages.is_cyrillic(name):
|
||||
self._set_font('UniCyr_8x16')
|
||||
else:
|
||||
# this will reset a possible previously set font to a default font
|
||||
self._set_font('')
|
||||
|
||||
language.install()
|
||||
else:
|
||||
raise ValueError(f'Language not supported: {name}')
|
||||
|
||||
def _set_font(self, font: str):
|
||||
from archinstall import SysCommand, log
|
||||
try:
|
||||
log(f'Setting new font: {font}', level=logging.DEBUG)
|
||||
SysCommand(f'setfont {font}')
|
||||
except Exception:
|
||||
log(f'Unable to set font {font}', level=logging.ERROR)
|
||||
|
||||
@classmethod
|
||||
def load_nationalization(cls) -> Translation:
|
||||
locales_dir = cls.get_locales_dir()
|
||||
|
|
|
|||
|
|
@ -118,10 +118,13 @@ def select_mirror_regions(preset_values: Dict[str, Any] = {}) -> Dict[str, Any]:
|
|||
case _: return {selected: mirrors[selected] for selected in selected_mirror.value}
|
||||
|
||||
|
||||
def select_archinstall_language(default='English'):
|
||||
def select_archinstall_language(preset_values: str):
|
||||
languages = Translation.get_available_lang()
|
||||
language = Menu(_('Archinstall language'), languages, default_option=default).run()
|
||||
return language
|
||||
choice = Menu(_('Archinstall language'), languages, default_option=preset_values).run()
|
||||
|
||||
match choice.type_:
|
||||
case MenuSelectionType.Esc: return preset_values
|
||||
case MenuSelectionType.Selection: return choice.value
|
||||
|
||||
|
||||
def select_profile(preset) -> Optional[Profile]:
|
||||
|
|
|
|||
|
|
@ -0,0 +1,19 @@
|
|||
{
|
||||
"languages": [
|
||||
"Abkhazian",
|
||||
"Azerbaijani",
|
||||
"Bashkir",
|
||||
"Belarusian",
|
||||
"Bulgarian",
|
||||
"Chuvash",
|
||||
"Komi",
|
||||
"Macedonian",
|
||||
"Mongolian",
|
||||
"Russian",
|
||||
"Serbo-Croatian",
|
||||
"Tajik",
|
||||
"Tatar",
|
||||
"Ukrainian",
|
||||
"Uzbek"
|
||||
]
|
||||
}
|
||||
Loading…
Reference in New Issue