From 465e730962f4301b92b3bc9e5f7d5e61f20549d1 Mon Sep 17 00:00:00 2001 From: Klemek Date: Fri, 26 Feb 2021 13:31:16 +0100 Subject: [PATCH] Update build.py --- build.py | 56 +++++++++++++++++++++++++++++++++----------------------- 1 file changed, 33 insertions(+), 23 deletions(-) diff --git a/build.py b/build.py index 47105cf..6bcb23c 100644 --- a/build.py +++ b/build.py @@ -1,32 +1,42 @@ from os import listdir, remove + + # get last version of french file inp = sorted([f for f in listdir() if f.startswith('usinfr')])[-1] -out = 'usinen' + inp[6:] -# delete english layout -for f in sorted([f for f in listdir() if f.startswith('usinen')]): - remove(f) -lines = [] +def convert(code, name, localeid, localename): + out = 'usin' + code + inp[6:] -# copy file and add changes -with open(inp, encoding='utf8', mode='r') as finp: - with open(out, encoding='utf8', mode='w') as fout: - for line in finp: - line = line.strip() - lines += [line] - if line.startswith('KBD'): - line = line[:4] + out[:8] + '\t"EN' + line[16:] - elif line.startswith('LOCALENAME'): - line = 'LOCALENAME\t"en-US"' - elif line.startswith('LOCALEID'): - line = 'LOCALEID\t"00000409"' - elif line.startswith('0409\tFrench'): - line = '0409\tEnglish (United States)' + # delete english layout + for f in sorted([f for f in listdir() if f.startswith('usin' + code)]): + remove(f) + + lines = [] + + # copy file and add changes + with open(inp, encoding='utf8', mode='r') as finp: + with open(out, encoding='utf8', mode='w') as fout: + for line in finp: + line = line.strip() + lines += [line] + if line.startswith('KBD'): + line = line[:4] + out[:8] + '\t"EN' + line[16:] + elif line.startswith('LOCALENAME'): + line = 'LOCALENAME\t"' + localename + '"' + elif line.startswith('LOCALEID'): + line = 'LOCALEID\t"' + localeid + '"' + elif line.startswith('0409\tFrench'): + line = '0409\t' + name + fout.write(line+'\r\n') + + # rewrite input with CRLF + with open(inp, encoding='utf8', mode='w') as fout: + for line in lines: fout.write(line+'\r\n') -# rewrite input with CRLF -with open(inp, encoding='utf8', mode='w') as fout: - for line in lines: - fout.write(line+'\r\n') + +convert("us", "English (United States)", "00000409", "en-US") +convert("gb", "English (United Kingdom)", "00000809", "en-GB") +