build(i18n): added fluent files scanning tool

This commit is contained in:
Observer KRypt0n_ 2023-04-17 13:23:27 +02:00
parent db5a27dfd2
commit 3f197708ed
No known key found for this signature in database
GPG key ID: 844DA47BA25FE1E2

74
fluentscan.py Normal file
View file

@ -0,0 +1,74 @@
#!/usr/bin/python
# Author: @xstraok
# Modified by Observer KRypt0n_ <https://github.com/krypt0nn>
import os
import sys
path = "assets/locales/" + sys.argv[1] + "/"
for filename in os.listdir("assets/locales/en"):
with open(os.path.join("assets/locales/en", filename), 'r') as locale_file:
created_locale = open(path + filename)
def to_dict(text):
result={}
for i in text:
if " = " in i:
try:
result[i.split()[0]] = ' '.join(i.split()[2:])
except:
pass
elif i:
result[list(result.keys())[-1]] += i
return result
def dict_compare(d1, d2):
d1_keys = set(d1.keys())
d2_keys = set(d2.keys())
shared_keys = d1_keys.intersection(d2_keys)
added = d1_keys - d2_keys
removed = d2_keys - d1_keys
modified = {o : (d1[o], d2[o]) for o in shared_keys if d1[o] != d2[o]}
same = set(o for o in shared_keys if d1[o] == d2[o])
return added, removed, modified, same
expected=to_dict(locale_file)
expected2=to_dict(created_locale)
# TODO: why modified is not used?
added, removed, modified, same = dict_compare(expected, expected2)
if added or removed or same:
print(f"[{created_locale.name[15:]}]")
if added:
print(" [Added]")
for i in added:
print(f" {i} = {expected[i]}")
if removed:
print(" [Removed]")
for i in removed:
print(f" {i} = {expected2[i]}")
#workaround
if same and same != "set()":
print(" [Untranslated]")
for i in same:
print(f" {i} = {expected[i]}")
print("")