From 13b81a410114c08564ad97a2681e95b12e8d94e4 Mon Sep 17 00:00:00 2001 From: dkanada Date: Tue, 4 Aug 2020 04:26:57 +0900 Subject: [PATCH] add a new script for string management --- scripts/duplicates.py | 33 +++++++++++++++++++++++++++++++++ scripts/{scrm.py => remove.py} | 2 +- scripts/{scdup.py => source.py} | 0 scripts/{scgen.py => unused.py} | 0 4 files changed, 34 insertions(+), 1 deletion(-) create mode 100644 scripts/duplicates.py rename scripts/{scrm.py => remove.py} (95%) rename scripts/{scdup.py => source.py} (100%) rename scripts/{scgen.py => unused.py} (100%) diff --git a/scripts/duplicates.py b/scripts/duplicates.py new file mode 100644 index 0000000000..bbacffd0f1 --- /dev/null +++ b/scripts/duplicates.py @@ -0,0 +1,33 @@ +import sys +import os +import json + +# load every string in the source language +# print all duplicate values to a file + +cwd = os.getcwd() +source = cwd + '/../src/strings/en-us.json' + +reverse = {} +duplicates = {} + +with open(source) as en: + strings = json.load(en) + for key, value in strings.items(): + if value not in reverse: + reverse[value] = [key] + else: + reverse[value].append(key) + +for key, value in reverse.items(): + if len(value) > 1: + duplicates[key] = reverse[key] + +print('LENGTH: ' + str(len(duplicates))) +with open('duplicates.txt', 'w') as out: + for item in duplicates: + out.write(json.dumps(item) + ': ') + out.write(json.dumps(duplicates[item]) + '\n') + out.close() + +print('DONE') diff --git a/scripts/scrm.py b/scripts/remove.py similarity index 95% rename from scripts/scrm.py rename to scripts/remove.py index 9bd5bc2a48..dba48537aa 100644 --- a/scripts/scrm.py +++ b/scripts/remove.py @@ -11,7 +11,7 @@ langlst = os.listdir(langdir) keys = [] -with open('scout.txt', 'r') as f: +with open('unused.txt', 'r') as f: for line in f: keys.append(line.strip('\n')) diff --git a/scripts/scdup.py b/scripts/source.py similarity index 100% rename from scripts/scdup.py rename to scripts/source.py diff --git a/scripts/scgen.py b/scripts/unused.py similarity index 100% rename from scripts/scgen.py rename to scripts/unused.py