Created
April 6, 2022 06:44
-
-
Save Xzonn/016bae54f67be89a7bb7f675787074ba to your computer and use it in GitHub Desktop.
FC & SFC Nintendo Switch Online string extractor
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os | |
import json | |
os.chdir(os.path.dirname(__file__)) | |
with open("../../../titles/lclassics.titlesdb", "r", -1, "utf-8") as f: | |
titles = json.load(f)["titles"] | |
dirs = os.listdir("./") | |
for dir in dirs: | |
if not os.path.isdir(dir): | |
continue | |
path = os.path.join(dir, "strings.lng") | |
with open(path, "r", -1, "utf-8") as f: | |
data = json.load(f) | |
with open(f"{dir}.txt", "w", -1, "utf-8") as f: | |
f.write("strings\n") | |
for k, v in data["strings"].items(): | |
v = v.replace("\n", "\\n").replace("\t", "\\t") | |
f.write(f"{k}\t{v}\n") | |
f.write("exploded_strings\n") | |
for k, v in data["exploded_strings"].items(): | |
t = "" | |
for sub_v in v: | |
if sub_v["type"] == "TEXT_PART_TYPE_TEXT": | |
t += sub_v["value"] | |
elif sub_v["type"] == "TEXT_PART_TYPE_VARIABLE": | |
t += "[" + sub_v["name"] + "]" | |
else: | |
raise ValueError | |
t = t.replace("\n", "\\n").replace("\t", "\\t") | |
f.write(f"{k}\t{t}\n") | |
f.write("titles\n") | |
for k, v in titles.items(): | |
if dir == "ja": | |
t = v["title"] | |
elif dir == "zh-hans": | |
t = v["title_zhHans"] | |
elif dir == "zh-hant": | |
t = v["title_zhHant"] | |
else: | |
t = v["title"] | |
f.write(f"{k}\t{t}\n") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment