Skip to content

Commit

Permalink
Use display names whenever possible
Browse files Browse the repository at this point in the history
  • Loading branch information
kg583 committed Aug 20, 2024
1 parent 6a819d1 commit c8b7bd4
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions scripts/tokenide.py
Original file line number Diff line number Diff line change
Expand Up @@ -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':
Expand Down Expand Up @@ -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

Expand All @@ -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"]}

Expand Down

0 comments on commit c8b7bd4

Please sign in to comment.