Prune i18n files (#110)
Reviewed-on: https://akkoma.dev/AkkomaGang/pleroma-fe/pulls/110
This commit is contained in:
parent
dfcc91c8c6
commit
2e92aaaaa3
34 changed files with 11372 additions and 11865 deletions
29
src/i18n/dotted-to-nested
Executable file
29
src/i18n/dotted-to-nested
Executable file
|
@ -0,0 +1,29 @@
|
|||
#!/usr/bin/env python3
|
||||
# For restructuring files that have keys like "chat.title"
|
||||
# into more useful formats
|
||||
|
||||
import sys
|
||||
import json
|
||||
from collections import defaultdict
|
||||
|
||||
with open(sys.argv[1], "r") as f:
|
||||
data = json.load(f)
|
||||
|
||||
d = defaultdict(str)
|
||||
|
||||
|
||||
def create_and_set(dic, key_path, value):
|
||||
if len(key_path) == 1:
|
||||
dic[key_path[0]] = value
|
||||
else:
|
||||
if key_path[0] not in dic:
|
||||
dic[key_path[0]] = {}
|
||||
create_and_set(dic[key_path[0]], key_path[1:], value)
|
||||
|
||||
|
||||
for key, value in data.items():
|
||||
nested_key = key.split(".")
|
||||
create_and_set(d, nested_key, value)
|
||||
|
||||
with open(sys.argv[1], "w", encoding="utf-8") as f:
|
||||
json.dump(d, f, indent=4, sort_keys=True, ensure_ascii=False)
|
Loading…
Add table
Add a link
Reference in a new issue