Skip to content

Commit

Permalink
Rework system locale
Browse files Browse the repository at this point in the history
  • Loading branch information
codefiles committed Nov 1, 2022
1 parent b1ab5ba commit a305023
Show file tree
Hide file tree
Showing 3 changed files with 412 additions and 42 deletions.
33 changes: 7 additions & 26 deletions archinstall/lib/installer.py
Expand Up @@ -12,7 +12,7 @@
from .disk import get_partitions_in_use, Partition
from .general import SysCommand, generate_password
from .hardware import has_uefi, is_vm, cpu_vendor
from .locale_helpers import verify_keyboard_layout, verify_x11_keyboard_layout
from .locale_helpers import Locale, LocaleUtils, verify_keyboard_layout, verify_x11_keyboard_layout
from .disk.helpers import findmnt
from .mirrors import use_mirrors
from .plugins import plugins
Expand Down Expand Up @@ -440,32 +440,13 @@ def set_hostname(self, hostname: str, *args :str, **kwargs :str) -> None:
fh.write(hostname + '\n')

def set_locale(self, locale :str, encoding :str = 'UTF-8', *args :str, **kwargs :str) -> bool:
if not len(locale):
return True

modifier = ''

# This is a temporary patch to fix #1200
if '.' in locale:
locale, potential_encoding = locale.split('.', 1)

# Override encoding if encoding is set to the default parameter
# and the "found" encoding differs.
if encoding == 'UTF-8' and encoding != potential_encoding:
encoding = potential_encoding

# Make sure we extract the modifier, that way we can put it in if needed.
if '@' in locale:
locale, modifier = locale.split('@', 1)
modifier = f"@{modifier}"
# - End patch

with open(f'{self.target}/etc/locale.gen', 'a') as fh:
fh.write(f'{locale}.{encoding}{modifier} {encoding}\n')
with open(f'{self.target}/etc/locale.conf', 'w') as fh:
fh.write(f'LANG={locale}.{encoding}{modifier}\n')
try:
locales = [Locale(locale, encoding)]
except ValueError as error:
self.log(f'Invalid locale: {error}', level=logging.ERROR, fg='red')
return False

return True if SysCommand(f'/usr/bin/arch-chroot {self.target} locale-gen').exit_code == 0 else False
return LocaleUtils(locales, self.target).run()

def set_timezone(self, zone :str, *args :str, **kwargs :str) -> bool:
if not zone:
Expand Down

0 comments on commit a305023

Please sign in to comment.