From 2739006b5201322e9e978c98693ce4850713ecfc Mon Sep 17 00:00:00 2001 From: xstraok <89219595+xstraok@users.noreply.github.com> Date: Mon, 17 Apr 2023 13:14:03 -0400 Subject: [PATCH] Update fluentscan.py added: initial error checking support, detecting of unused entries --- fluentscan.py | 34 +++++++++++++++++++++++++++++++++- 1 file changed, 33 insertions(+), 1 deletion(-) diff --git a/fluentscan.py b/fluentscan.py index cf05b5e..85ad790 100644 --- a/fluentscan.py +++ b/fluentscan.py @@ -5,6 +5,17 @@ import os import sys +import glob + +valid_args=["diff","unused"] + +if len(sys.argv)<3 or len(sys.argv) == 0: + print("missing arguments") + sys.exit() + +if sys.argv[2] not in valid_args: + print(f"invalid argument:{sys.argv[2]}") + sys.exit() path = "assets/locales/" + sys.argv[1] + "/" @@ -48,8 +59,27 @@ for filename in os.listdir("assets/locales/en"): # TODO: why modified is not used? added, removed, modified, same = dict_compare(expected, expected2) + if sys.argv[2] == "unused" or sys.argv[2] == "missing": + files = glob.glob("src/" + '/**/*.rs', recursive=True) + used=[] + for i in files: + with open(i,"r") as script: + text=script.read() + if sys.argv[2] == "unused": + for j in expected: + if '"'+j+'"' in text: + used.append(j) + #elif sys.argv[2] == "missing": + #for j in text.split(): + #find all cases of tr( + + for i in expected: + if i not in used: + print(f"{i} is not used ({locale_file.name})") - if added or removed or same: + continue + + if (added or removed or same) and sys.argv[2] == "diff": print(f"[{created_locale.name[15:]}]") if added: @@ -72,3 +102,5 @@ for filename in os.listdir("assets/locales/en"): print(f" {i} = {expected[i]}") print("") + +