#!/usr/bin/env python3 """ Script to directly apply Arabic translations to the main django.po file """ import re def apply_translations_direct(): """ Apply translations directly to the main django.po file """ # Arabic translations for batch 01 translations = { "Website": "الموقع الإلكتروني", "Admin Notes": "ملاحظات المسؤول", "Save Assignment": "حفظ التكليف", "Assignment": "التكليف", "Expires At": "ينتهي في", "Access Token": "رمز الوصول", "Subject": "الموضوع", "Recipients": "المستلمون", "Internal staff involved in the recruitment process for this job": "الموظفون الداخليون المشاركون في عملية التوظيف لهذه الوظيفة", "External Participant": "مشارك خارجي", "External participants involved in the recruitment process for this job": "المشاركون الخارجيون المشاركون في عملية التوظيف لهذه الوظيفة", "Reason for canceling the job posting": "سبب إلغاء نشر الوظيفة", "Name of person who cancelled this job": "اسم الشخص الذي ألغى هذه الوظيفة", "Hired": "تم التوظيف", "Author": "المؤلف", "Endpoint URL for sending candidate data (for outbound sync)": "عنوان URL لنقطة النهاية لإرسال بيانات المرشح (للمزامنة الصادرة)", "HTTP method for outbound sync requests": "طريقة HTTP لطلبات المزامنة الصادرة", "HTTP method for connection testing": "طريقة HTTP لاختبار الاتصال", "Custom Headers": "رؤوس مخصصة", "JSON object with custom HTTP headers for sync requests": "كائن JSON يحتوي على رؤوس HTTP مخصصة لطلبات المزامنة", "Supports Outbound Sync": "يدعم المزامنة الصادرة", "Whether this source supports receiving candidate data from ATS": "ما إذا كان هذا المصدر يدعم استقبال بيانات المرشح من نظام تتبع المتقدمين", "Expired": "منتهي الصلاحية", "Maximum candidates agency can submit for this job": "الحد الأقصى للمرشحين الذين يمكن للوكالة تقديمهم لهذه الوظيفة" } main_po_file = "locale/ar/LC_MESSAGES/django.po" # Read the main django.po file with open(main_po_file, 'r', encoding='utf-8') as f: main_content = f.read() # Apply translations to main file updated_content = main_content applied_count = 0 for english, arabic in translations.items(): # Pattern to find msgid followed by empty msgstr pattern = rf'(msgid "{re.escape(english)}"\s*\nmsgstr) ""' replacement = rf'\1 "{arabic}"' if re.search(pattern, updated_content): updated_content = re.sub(pattern, replacement, updated_content) applied_count += 1 print(f"✓ Applied: '{english}' -> '{arabic}'") else: print(f"✗ Not found: '{english}'") # Write updated content back to main file with open(main_po_file, 'w', encoding='utf-8') as f: f.write(updated_content) print(f"\nApplied {applied_count} translations to {main_po_file}") return applied_count def main(): """Main function to apply batch 01 translations""" print("Applying Batch 01 translations directly to main django.po file...") applied_count = apply_translations_direct() if applied_count > 0: print(f"\n✅ Successfully applied {applied_count} translations!") print("Next steps:") print("1. Run: python manage.py compilemessages") print("2. Test the translations in the application") print("3. Continue with the next batch") else: print("\n❌ No translations were applied.") if __name__ == "__main__": main()