From c8b7bd4e47dae51c891b3f8fe43437a3fba01270 Mon Sep 17 00:00:00 2001 From: KG Date: Tue, 20 Aug 2024 13:47:14 -0400 Subject: [PATCH] Use display names whenever possible --- scripts/tokenide.py | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/scripts/tokenide.py b/scripts/tokenide.py index debc553..375ade6 100644 --- a/scripts/tokenide.py +++ b/scripts/tokenide.py @@ -31,6 +31,7 @@ class TokenIDESheet: def __init__(self, sheet: dict[str] = None): self.sheet = sheet or {"tokens": {}, "meta": []} + self.sheet["tokens"] |= {"$00": {"string": "", "variants": set(), "attrib": {}, "tokens": {}}} @staticmethod def from_xml_string(xml_str: str) -> 'TokenIDESheet': @@ -137,7 +138,11 @@ def for_version(self, *, version: OsVersion = None, lang: str = 'en') -> 'TokenI with open(os.path.join(os.path.dirname(__file__), "../8X.xml"), encoding="UTF-8") as file: tokens = Tokens.from_xml_string(file.read(), version or OsVersions.LATEST) - for byte, token in tokens.bytes.items(): + all_bytes = tokens.bytes + all_names = [name for token in all_bytes.values() + for name in {*token.langs.get(lang, "en").names(), token.langs.get(lang, "en").display}] + + for byte, token in all_bytes.items(): if version is not None and token.since > version: continue @@ -160,9 +165,7 @@ def for_version(self, *, version: OsVersion = None, lang: str = 'en') -> 'TokenI translation = token.langs.get(lang, "en") display = translation.display - if new[value]["string"] not in [*translation.names(), display]: - new[value]["string"] = translation.accessible - + new[value]["string"] = display if all_names.count(display) == 1 else translation.accessible new[value]["variants"] |= {*translation.names()} new[value]["variants"] -= {new[value]["string"]}