from pathlib import Path
root=Path('/home/ubuntu/clinic-management')
translations={
'en': {'clinic_login_link':'Clinic login link','open_clinic_login':'Open clinic login'},
'ar': {'clinic_login_link':'رابط دخول العيادة','open_clinic_login':'فتح دخول العيادة'},
}
for locale, items in translations.items():
    path=root/f'lang/{locale}/ui.php'
    text=path.read_text()
    additions=[]
    for key,value in items.items():
        if f"'{key}' =>" not in text:
            additions.append(f"    '{key}' => '{value}',")
    if additions:
        marker='\n];'
        if marker not in text:
            raise RuntimeError(f'Cannot locate dictionary end in {path}')
        text=text.replace(marker, '\n'+'\n'.join(additions)+marker, 1)
        path.write_text(text)
print('clinic link translations added')
