from pathlib import Path
root=Path('/home/ubuntu/clinic-management')
views=root/'resources/views'
fixes={
'admin_clinics.blade.php':{
"['normal'=>'عادية','multi_branch'=>__('ui.multi_branch'),'multi_specialty'=>__('ui.multi_specialty'),'multi_branch_specialty'=>__('ui.multi_branch_specialty')]":"['normal'=>__('ui.normal_clinic'),'multi_branch'=>__('ui.multi_branch'),'multi_specialty'=>__('ui.multi_specialty'),'multi_branch_specialty'=>__('ui.multi_branch_specialty')]",
"<option value=\"monthly\">{{ __('ui.monthly_subscription_short') }}</option>":"<option value=\"monthly\">{{ __('ui.monthly_subscription_short') }}</option>",
"<option value=\"monthly\">شهري — شهر</option>":"<option value=\"monthly\">{{ __('ui.monthly_subscription_short') }}</option>",
},
'admin_clinics_report.blade.php':{
'<th class="p-3">العيادة</th><th class="p-3">النوع</th>':'<th class="p-3">{{ __(\'ui.clinic\') }}</th><th class="p-3">{{ __(\'ui.type\') }}</th>',
},
'admin_revenue_report.blade.php':{
'<th class="p-3">كاش</th>':'<th class="p-3">{{ __(\'ui.cash\') }}</th>',
'<th class="p-3">إنستاباي</th>':'<th class="p-3">{{ __(\'ui.instapay\') }}</th>',
'<th class="p-3">الإجمالي</th>':'<th class="p-3">{{ __(\'ui.grand_total\') }}</th>',
'<th class="p-3">العيادة</th>':'<th class="p-3">{{ __(\'ui.clinic\') }}</th>',
},
'admin_subscription_pricing.blade.php':{
'تعديل الأسعار لا يغير الاشتراكات المحفوظة سابقاً.':"{{ __('ui.price_change_note') }}",
},
'reset_clinic_password.blade.php':{
'حفظ كلمة المرور الجديدة</button>':"{{ __('ui.save_new_password') }}</button>",
},
}
for fn,m in fixes.items():
 p=views/fn;s=p.read_text()
 for a,b in m.items():s=s.replace(a,b)
 p.write_text(s)
# Add missing keys only when absent.
keys={
'en':{'monthly_subscription_short':'Monthly — one month','monthly':'Monthly','quarterly':'Quarterly','semiannual':'Semiannual','annual':'Annual','specialties':'Specialties','amount':'Amount','action':'Action','login_label':'Login','base_price':'Base price','branch_price':'Branch price','doctor_price':'Doctor price','add_doctors':'Add doctors','before_adding_branches_doctors':'Applies to the total number of branches and doctors','price_change_note':'Changing prices does not alter previously saved subscriptions.','currency':'EGP'},
'ar':{'monthly_subscription_short':'شهري — شهر','monthly':'شهري','quarterly':'ربع سنوي','semiannual':'نصف سنوي','annual':'سنوي','specialties':'التخصصات','amount':'المبلغ','action':'إجراء','login_label':'دخول','base_price':'السعر الأساسي','branch_price':'سعر الفرع','doctor_price':'سعر الطبيب','add_doctors':'إضافة الأطباء','before_adding_branches_doctors':'يطبق على إجمالي الفروع والأطباء','price_change_note':'تعديل الأسعار لا يغير الاشتراكات المحفوظة سابقاً.','currency':'ج.م'}
}
for loc,vals in keys.items():
 p=root/f'lang/{loc}/ui.php';s=p.read_text(); additions=''
 for k,v in vals.items():
  if f"'{k}' =>" not in s: additions += f"    '{k}' => {v!r},\n"
 if additions:s=s.replace('\n];','\n'+additions+'];',1)
 p.write_text(s)
print('finalized requested i18n')
