Skip to content

Commit

Permalink
Rework system locale
Browse files Browse the repository at this point in the history
  • Loading branch information
codefiles committed Sep 29, 2022
1 parent 5ed38b7 commit 7314c2b
Showing 1 changed file with 10 additions and 13 deletions.
23 changes: 10 additions & 13 deletions archinstall/lib/locale_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,7 @@ def uncomment(self) -> bool:
return False

index = 0
locales = self.locales.copy()

# Comment all uncommented entries.
for index, entry in enumerate(contents):
Expand All @@ -204,8 +205,13 @@ def uncomment(self) -> bool:

if locale == Locale(*uncommented_entry.strip().split()):
contents[index] = uncommented_entry
locales.remove(locale)
break

# Append locales that are supported but did not match entries.
for locale in locales:
contents.append(f'{locale.name} {locale.encoding}\n')

# Open the file again in write mode, to replace the contents.
try:
with open(self.locale_gen, 'w') as fh:
Expand Down Expand Up @@ -391,25 +397,16 @@ def run(self) -> bool:

def list_locales(target: str = '') -> List[str]:
supported = f'{target}/usr/share/i18n/SUPPORTED'
locales = []

try:
with open(supported, 'r') as fh:
entries = fh.readlines()
locales = fh.readlines()
except FileNotFoundError:
log(f"Supported locale file not found: '{supported}'", fg="red", level=logging.ERROR)
else:
# Remove lines that do not contain locales.
for index, line in enumerate(entries):
if line == 'SUPPORTED-LOCALES=\\\n':
entries = entries[index + 1:]
break

# Remove C.UTF-8 since it is provided by the glibc package.
entries.remove('C.UTF-8/UTF-8 \\\n')
return None

for entry in entries:
locales.append(entry[:-3].replace('/', ' '))
# Remove C.UTF-8 since it is provided by the glibc package.
locales.remove('C.UTF-8 UTF-8\n')

return locales

Expand Down

0 comments on commit 7314c2b

Please sign in to comment.