Language file expanded
This commit is contained in:
Vendored
+21
@@ -0,0 +1,21 @@
|
||||
{
|
||||
"version": "2.0.0",
|
||||
"tasks": [
|
||||
{
|
||||
"label": "JSON zusammenführen",
|
||||
"type": "shell",
|
||||
"command": "python merge_json.py",
|
||||
"group": {
|
||||
"kind": "build",
|
||||
"isDefault": true
|
||||
},
|
||||
"presentation": {
|
||||
"echo": true,
|
||||
"reveal": "always",
|
||||
"focus": false,
|
||||
"panel": "shared"
|
||||
},
|
||||
"problemMatcher": []
|
||||
}
|
||||
]
|
||||
}
|
||||
+1712
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,42 @@
|
||||
import json
|
||||
import os
|
||||
|
||||
ziel_datei = 'de.json'
|
||||
quelle_datei = 'en.json'
|
||||
neue_keys_datei = 'neue_keys.json'
|
||||
|
||||
def lade_json(pfad):
|
||||
if os.path.exists(pfad):
|
||||
with open(pfad, 'r', encoding='utf-8') as f:
|
||||
return json.load(f)
|
||||
return {}
|
||||
|
||||
ziel_daten = lade_json(ziel_datei)
|
||||
quelle_daten = lade_json(quelle_datei)
|
||||
neue_keys_daten = {}
|
||||
|
||||
def merge_recursive(ziel, quelle, neu_dict):
|
||||
neue_keys = 0
|
||||
for key, value in quelle.items():
|
||||
if key not in ziel:
|
||||
ziel[key] = value
|
||||
neu_dict[key] = value
|
||||
neue_keys += 1
|
||||
elif isinstance(value, dict) and isinstance(ziel.get(key), dict):
|
||||
if key not in neu_dict:
|
||||
neu_dict[key] = {}
|
||||
neue_keys += merge_recursive(ziel[key], value, neu_dict[key])
|
||||
return neue_keys
|
||||
|
||||
anzahl_neue = merge_recursive(ziel_daten, quelle_daten, neue_keys_daten)
|
||||
|
||||
# Ziel-JSON speichern
|
||||
with open(ziel_datei, 'w', encoding='utf-8') as f:
|
||||
json.dump(ziel_daten, f, ensure_ascii=False, indent=2)
|
||||
|
||||
# Neue Keys separat speichern
|
||||
with open(neue_keys_datei, 'w', encoding='utf-8') as f:
|
||||
json.dump(neue_keys_daten, f, ensure_ascii=False, indent=2)
|
||||
|
||||
print(f"{anzahl_neue} neue Schlüssel wurden rekursiv hinzugefügt.")
|
||||
print(f"Neue Einträge wurden zusätzlich in '{neue_keys_datei}' gespeichert.")
|
||||
Reference in New Issue
Block a user