|
|
|
@ -4,27 +4,43 @@
|
|
|
|
|
# usage : ./tools/compareLocalizedStrings.py en de
|
|
|
|
|
|
|
|
|
|
import re
|
|
|
|
|
import os
|
|
|
|
|
from os import path, listdir
|
|
|
|
|
from glob import glob
|
|
|
|
|
import json
|
|
|
|
|
import sys
|
|
|
|
|
|
|
|
|
|
if len(sys.argv) != 3:
|
|
|
|
|
print(f'usage: {sys.argv[0]} <source_local> <compare_local>')
|
|
|
|
|
LOCALES_FOLDER = './_locales'
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if len(sys.argv) != 1 and len(sys.argv) != 2:
|
|
|
|
|
print(f'usage: {sys.argv[0]} <compared_locale>. If compared locale is not set, all found locales will be cleaned')
|
|
|
|
|
sys.exit(1)
|
|
|
|
|
|
|
|
|
|
src = sys.argv[1]
|
|
|
|
|
dest = sys.argv[2]
|
|
|
|
|
print(f'src {src}, dest {dest}')
|
|
|
|
|
jsonInEn = json.loads(open(f'_locales/{src}/messages.json', 'r').read())
|
|
|
|
|
jsonInDe = json.loads(open(f'_locales/{dest}/messages.json', 'r').read())
|
|
|
|
|
keysInEn = jsonInEn.keys()
|
|
|
|
|
keysInDe = jsonInDe.keys()
|
|
|
|
|
if (len(sys.argv) > 1):
|
|
|
|
|
localesToCheck = [f'{LOCALES_FOLDER}{sys.argv[1]}']
|
|
|
|
|
else:
|
|
|
|
|
localesToCheck = [path.join(LOCALES_FOLDER, o) for o in listdir(LOCALES_FOLDER) if path.isdir(path.join(LOCALES_FOLDER,o))]
|
|
|
|
|
|
|
|
|
|
for dest in localesToCheck:
|
|
|
|
|
if dest == f'{LOCALES_FOLDER}/en':
|
|
|
|
|
print('skipping "en" locale...')
|
|
|
|
|
continue
|
|
|
|
|
|
|
|
|
|
destFilePath = f'{dest}/messages.json'
|
|
|
|
|
# print(f'dest {dest}, destFilePath {destFilePath}')
|
|
|
|
|
|
|
|
|
|
jsonInSrc = json.loads(open(f'{LOCALES_FOLDER}/en/messages.json', 'r').read())
|
|
|
|
|
jsonInDest = json.loads(open(destFilePath, 'r').read())
|
|
|
|
|
keysInSrc = jsonInSrc.keys()
|
|
|
|
|
keysInDest = jsonInDest.keys()
|
|
|
|
|
|
|
|
|
|
print(keysInEn)
|
|
|
|
|
destMinusSrc = list(set(keysInDest) - set(keysInSrc))
|
|
|
|
|
for key in destMinusSrc:
|
|
|
|
|
# print(f'Present in "{dest}" but not found in "{src}": {key}')
|
|
|
|
|
del jsonInDest[key]
|
|
|
|
|
|
|
|
|
|
for key in keysInEn:
|
|
|
|
|
if key not in keysInDe:
|
|
|
|
|
print(f'not found in de:{key}')
|
|
|
|
|
print(f'total keys in "{dest}" to remove: {len(destMinusSrc)}')
|
|
|
|
|
|
|
|
|
|
print(f'total keys in en {len(keysInEn)}')
|
|
|
|
|
# write the updated json dict to the file
|
|
|
|
|
with open(destFilePath, 'w') as outfile:
|
|
|
|
|
json.dump(jsonInDest, outfile, indent=4, ensure_ascii=False)
|
|
|
|
|