diff --git a/archinstall/lib/installer.py b/archinstall/lib/installer.py index 5d0369f809..db4e351e8c 100644 --- a/archinstall/lib/installer.py +++ b/archinstall/lib/installer.py @@ -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 list_locales, verify_keyboard_layout, verify_x11_keyboard_layout from .disk.helpers import findmnt from .mirrors import use_mirrors from .plugins import plugins @@ -440,31 +440,41 @@ def set_hostname(self, hostname: str, *args :str, **kwargs :str) -> None: fh.write(hostname + '\n') def set_locale(self, locale :str, *args :str, **kwargs :str) -> bool: + space_count = locale.count(' ') + if space_count == 1: + locale_name = locale.split()[0] + elif space_count == 0: + locale_name = locale + locale = '' + for locale_entry in list_locales(): + if locale_name == locale_entry.split()[0]: + locale = locale_entry + if not locale: + return False - 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', 'r') as fp: + contents = fp.readlines() + + uncommented = False + for line in contents: + if locale == line.replace('#', '').strip() and line[0] != '#': + uncommented = True + + if not uncommented: + count = 0 + found = False + for count, line in enumerate(contents): + uncommentted_line = line.replace('#', '') + if locale == uncommentted_line.rstrip(): + contents[count] = uncommentted_line + found = True + break + if found: + with open(f'{self.target}/etc/locale.gen', 'w') as fh: + fh.writelines(contents) - 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') + fh.write(f'LANG={locale_name}\n') return True if SysCommand(f'/usr/bin/arch-chroot {self.target} locale-gen').exit_code == 0 else False diff --git a/archinstall/lib/locale_helpers.py b/archinstall/lib/locale_helpers.py index 5580fa917b..dec5f1b399 100644 --- a/archinstall/lib/locale_helpers.py +++ b/archinstall/lib/locale_helpers.py @@ -14,18 +14,11 @@ def list_keyboard_languages() -> Iterator[str]: def list_locales() -> List[str]: with open('/etc/locale.gen', 'r') as fp: locales = [] - # before the list of locales begins there's an empty line with a '#' in front - # so we'll collect the localels from bottom up and halt when we're donw - entries = fp.readlines() - entries.reverse() - - for entry in entries: - text = entry.replace('#', '').strip() - if text == '': - break - locales.append(text) - - locales.reverse() + for line in fp: + text = line.replace('#', '') + if text[0].isspace(): + continue + locales.append(text.strip()) return locales def get_locale_mode_text(mode):