111 lines
4.4 KiB
Python
Executable File
111 lines
4.4 KiB
Python
Executable File
import os
|
|
import json
|
|
|
|
APP_PATH = r'c:\Dockers\dockersyscms\app'
|
|
LOCALES_PATH = os.path.join(APP_PATH, 'templates', 'locales')
|
|
|
|
LANGS = ['pt_BR', 'es_ES', 'de_DE', 'fr_FR']
|
|
SOURCE_LANG = 'en_US'
|
|
|
|
TRANSLATIONS = {
|
|
'pt_BR': {
|
|
'about': 'Sobre', 'contact': 'Contato', 'services': 'Serviços', 'posts': 'Posts',
|
|
'dashboard': 'Painel', 'logout': 'Sair', 'login': 'Entrar', 'register': 'Cadastrar',
|
|
'profile': 'Perfil', 'settings': 'Configurações', 'pages': 'Páginas', 'faq': 'FAQ',
|
|
'vitrine': 'Vitrine', 'search': {'placeholder': 'Buscar...'}
|
|
},
|
|
'es_ES': {
|
|
'about': 'Sobre', 'contact': 'Contacto', 'services': 'Servicios', 'posts': 'Publicaciones',
|
|
'dashboard': 'Tablero', 'logout': 'Cerrar sesión', 'login': 'Iniciar sesión', 'register': 'Registrarse',
|
|
'profile': 'Perfil', 'settings': 'Configuraciones', 'pages': 'Páginas', 'faq': 'FAQ',
|
|
'vitrine': 'Vitrina', 'search': {'placeholder': 'Buscar...'}
|
|
},
|
|
'de_DE': {
|
|
'about': 'Über', 'contact': 'Kontakt', 'services': 'Dienstleistungen', 'posts': 'Beiträge',
|
|
'dashboard': 'Dashboard', 'logout': 'Abmelden', 'login': 'Anmelden', 'register': 'Registrieren',
|
|
'profile': 'Profil', 'settings': 'Einstellungen', 'pages': 'Seiten', 'faq': 'FAQ',
|
|
'vitrine': 'Vitrine', 'search': {'placeholder': 'Suchen...'}
|
|
},
|
|
'fr_FR': {
|
|
'about': 'À propos', 'contact': 'Contact', 'services': 'Services', 'posts': 'Articles',
|
|
'dashboard': 'Tableau de bord', 'logout': 'Déconnexion', 'login': 'Connexion', 'register': 'S\'inscrire',
|
|
'profile': 'Profil', 'settings': 'Paramètres', 'pages': 'Pages', 'faq': 'FAQ',
|
|
'vitrine': 'Vitrine', 'search': {'placeholder': 'Rechercher...'}
|
|
}
|
|
}
|
|
|
|
def load_json(path):
|
|
try:
|
|
with open(path, 'r', encoding='utf-8') as f:
|
|
return json.load(f)
|
|
except Exception as e:
|
|
print(f"Error reading {path}: {e}")
|
|
return {}
|
|
|
|
def save_json(path, data):
|
|
try:
|
|
with open(path, 'w', encoding='utf-8') as f:
|
|
json.dump(data, f, indent=4, ensure_ascii=False)
|
|
print(f"Updated: {path}")
|
|
except Exception as e:
|
|
print(f"Error writing {path}: {e}")
|
|
|
|
def update_recursive(source, target, lang_code, key_prefix=''):
|
|
modified = False
|
|
for k, v in source.items():
|
|
if k not in target:
|
|
# Key missing in target
|
|
print(f"Missing key in {lang_code}: {key_prefix}{k}")
|
|
if isinstance(v, dict):
|
|
target[k] = {}
|
|
update_recursive(v, target[k], lang_code, f"{key_prefix}{k}.")
|
|
else:
|
|
# Try to translate
|
|
trans = None
|
|
|
|
# Check explicit translations map
|
|
if lang_code in TRANSLATIONS:
|
|
# Try direct key match
|
|
if k in TRANSLATIONS[lang_code]:
|
|
val = TRANSLATIONS[lang_code][k]
|
|
if isinstance(val, str):
|
|
trans = val
|
|
|
|
# Try nested map if v is simple string but we mapped a dict? No, v is string here.
|
|
|
|
if trans is None:
|
|
# Use source value (fallback)
|
|
trans = v
|
|
|
|
target[k] = trans
|
|
modified = True
|
|
elif isinstance(v, dict):
|
|
if not isinstance(target[k], dict):
|
|
# Conflict
|
|
print(f"Conflict at {key_prefix}{k}")
|
|
continue
|
|
if update_recursive(v, target[k], lang_code, f"{key_prefix}{k}."):
|
|
modified = True
|
|
return modified
|
|
|
|
def sync_layout():
|
|
source_path = os.path.join(LOCALES_PATH, SOURCE_LANG, 'layout.json')
|
|
source_data = load_json(source_path)
|
|
|
|
if not source_data:
|
|
print("Source file not found or empty.")
|
|
return
|
|
|
|
for lang in LANGS:
|
|
target_path = os.path.join(LOCALES_PATH, lang, 'layout.json')
|
|
target_data = load_json(target_path)
|
|
|
|
# We need to preserve existing data but add missing keys from source
|
|
if update_recursive(source_data, target_data, lang):
|
|
save_json(target_path, target_data)
|
|
else:
|
|
print(f"No changes for {lang}")
|
|
|
|
if __name__ == "__main__":
|
|
sync_layout()
|