import { createContext, useContext, useState, useEffect, ReactNode } from 'react'; type Language = 'en' | 'mr'; interface LanguageContextType { language: Language; toggleLanguage: () => void; t: (key: string) => string; } const translations = { en: { // App Name 'app.name': 'Mirchi Trading', 'app.tagline': 'Invoice & Inventory Management', // Navigation 'nav.home': 'Home', 'nav.invoice': 'Invoice', 'nav.purchase': 'Purchase', 'nav.stock': 'Stock', 'nav.ledger': 'Ledger', // Dashboard 'dashboard.title': 'Mirchi Trading', 'dashboard.quickActions': 'Quick Actions', 'dashboard.recentActivity': 'Recent Activity', 'dashboard.totalSales': 'Total Sales', 'dashboard.thisMonth': 'This Month', 'dashboard.invoices': 'Invoices', 'dashboard.totalCreated': 'Total Created', 'dashboard.stockValue': 'Stock Value', 'dashboard.currentStock': 'Current Stock', 'dashboard.parties': 'Parties', 'dashboard.tradingPartners': 'Trading Partners', // Quick Actions 'action.newInvoice': 'New Invoice', 'action.newPurchase': 'New Purchase', 'action.stockReport': 'Stock Report', 'action.partyLedger': 'Party Ledger', 'action.billBooks': 'Bill Books', // Invoice 'invoice.title': 'Invoice', 'invoice.new': 'New Invoice', 'invoice.billDetails': 'Bill Details', 'invoice.billBook': 'Bill Book', 'invoice.billNumber': 'Bill Number', 'invoice.date': 'Date', 'invoice.partyName': 'Party Name', 'invoice.selectParty': 'Select Party', 'invoice.itemDetails': 'Item Details', 'invoice.selectItem': 'Select Item', 'invoice.lotNumber': 'Lot Number', 'invoice.selectLot': 'Select Lot', 'invoice.bags': 'Bags', 'invoice.grossWeight': 'Gross Weight', 'invoice.netWeight': 'Net Weight', 'invoice.rate': 'Rate', 'invoice.amount': 'Amount', 'invoice.charges': 'Additional Charges', 'invoice.bardhana': 'Packing', 'invoice.perBag': 'per bag', 'invoice.hamali': 'Labor', 'invoice.adhath': 'Commission', 'invoice.cess': 'Cess', 'invoice.gaadiBharni': 'Vehicle Loading', 'invoice.summary': 'Summary', 'invoice.itemTotal': 'Item Total', 'invoice.grandTotal': 'Grand Total', 'invoice.save': 'Save', 'invoice.print': 'Print', 'invoice.share': 'Share', 'invoice.shareWhatsApp': 'Share on WhatsApp', 'invoice.billNumberWarning': 'Changing bill number may cause issues. Use with caution.', // Purchase Entry 'purchase.title': 'Purchase Entry', 'purchase.inward': 'Inward', 'purchase.basicInfo': 'Basic Information', 'purchase.lotDetails': 'Lot Details', 'purchase.addLot': 'Add Lot', 'purchase.lotNumber': 'Lot Number', 'purchase.variety': 'Variety', 'purchase.selectVariety': 'Select Variety', 'purchase.quality': 'Quality', 'purchase.vehicleDetails': 'Vehicle Details', 'purchase.vehicleNumber': 'Vehicle Number', 'purchase.freight': 'Freight', 'purchase.paymentDetails': 'Payment Details', 'purchase.totalAmount': 'Total Amount', 'purchase.advancePaid': 'Advance Paid', 'purchase.remaining': 'Remaining', // Party Ledger 'ledger.title': 'Party Ledger', 'ledger.selectParty': 'Select Party', 'ledger.currentBalance': 'Current Balance', 'ledger.toReceive': 'To Receive', 'ledger.toPay': 'To Pay', 'ledger.credit': 'Credit', 'ledger.debit': 'Debit', 'ledger.balance': 'Balance', 'ledger.particulars': 'Particulars', 'ledger.reference': 'Reference', 'ledger.search': 'Search', // Bill Books 'billbook.title': 'Bill Books', 'billbook.new': 'New Bill Book', 'billbook.add': 'Add Bill Book', 'billbook.name': 'Book Name', 'billbook.serialFrom': 'First Number', 'billbook.serialTo': 'Last Number', 'billbook.active': 'Active', 'billbook.currentNumber': 'Current Number', 'billbook.remaining': 'Remaining Bills', 'billbook.activate': 'Activate', // Common 'common.save': 'Save', 'common.cancel': 'Cancel', 'common.add': 'Add', 'common.edit': 'Edit', 'common.delete': 'Delete', 'common.search': 'Search', 'common.filter': 'Filter', 'common.export': 'Export', 'common.print': 'Print', 'common.back': 'Back', 'common.next': 'Next', 'common.previous': 'Previous', 'common.close': 'Close', 'common.confirm': 'Confirm', 'common.yes': 'Yes', 'common.no': 'No', 'common.total': 'Total', 'common.date': 'Date', 'common.amount': 'Amount', 'common.quantity': 'Quantity', 'common.kg': 'kg', 'common.bags': 'bags', }, mr: { // App Name 'app.name': 'मिर्ची ट्रेडिंग', 'app.tagline': 'आवक-जावक व्यवस्थापन', // Navigation 'nav.home': 'होम', 'nav.invoice': 'जावक', 'nav.purchase': 'आवक', 'nav.stock': 'स्टॉक', 'nav.ledger': 'लेजर', // Dashboard 'dashboard.title': 'मिर्ची ट्रेडिंग', 'dashboard.quickActions': 'त्वरित कार्ये', 'dashboard.recentActivity': 'अलीकडील व्यवहार', 'dashboard.totalSales': 'एकूण विक्री', 'dashboard.thisMonth': 'या महिन्यात', 'dashboard.invoices': 'जावक बिले', 'dashboard.totalCreated': 'एकूण तयार केलेली', 'dashboard.stockValue': 'माल मूल्य', 'dashboard.currentStock': 'सध्याचा साठा', 'dashboard.parties': 'पार्टी', 'dashboard.tradingPartners': 'व्यापारी भागीदार', // Quick Actions 'action.newInvoice': 'जावक बिल', 'action.newPurchase': 'आवक एंट्री', 'action.stockReport': 'स्टॉक रिपोर्ट', 'action.partyLedger': 'पार्टी लेजर', 'action.billBooks': 'बिल बुक्स', // Invoice 'invoice.title': 'जावक बिल', 'invoice.new': 'नवीन जावक बिल', 'invoice.billDetails': 'बिल तपशील', 'invoice.billBook': 'बिल बुक', 'invoice.billNumber': 'बिल नंबर', 'invoice.date': 'तारीख', 'invoice.partyName': 'पार्टी नाव', 'invoice.selectParty': 'पार्टी निवडा', 'invoice.itemDetails': 'माल तपशील', 'invoice.selectItem': 'माल निवडा', 'invoice.lotNumber': 'लॉट नंबर', 'invoice.selectLot': 'लॉट निवडा', 'invoice.bags': 'पोत्या', 'invoice.grossWeight': 'एकूण वजन', 'invoice.netWeight': 'निव्वळ वजन', 'invoice.rate': 'रेट', 'invoice.amount': 'रक्कम', 'invoice.charges': 'अतिरिक्त खर्च', 'invoice.bardhana': 'बर्डाणा', 'invoice.perBag': 'प्रति पोती', 'invoice.hamali': 'हमाली', 'invoice.adhath': 'अडत', 'invoice.cess': 'सेस', 'invoice.gaadiBharni': 'गाडी भरणी', 'invoice.summary': 'सारांश', 'invoice.itemTotal': 'एकूण रक्कम', 'invoice.grandTotal': 'एकूण रक्कम', 'invoice.save': 'जतन करा', 'invoice.print': 'प्रिंट', 'invoice.share': 'शेअर करा', 'invoice.shareWhatsApp': 'WhatsApp वर शेअर करा', 'invoice.billNumberWarning': 'बिल नंबर बदलल्यास समस्या येऊ शकतात. सावधगिरीने वापरा.', // Purchase Entry 'purchase.title': 'आवक एंट्री', 'purchase.inward': 'माल आला', 'purchase.basicInfo': 'मूळ माहिती', 'purchase.lotDetails': 'लॉट तपशील', 'purchase.addLot': 'नवीन लॉट जोडा', 'purchase.lotNumber': 'लॉट नंबर', 'purchase.variety': 'जात', 'purchase.selectVariety': 'जात निवडा', 'purchase.quality': 'गुणवत्ता', 'purchase.vehicleDetails': 'गाडी तपशील', 'purchase.vehicleNumber': 'गाडी नंबर', 'purchase.freight': 'भाडे', 'purchase.paymentDetails': 'पेमेंट तपशील', 'purchase.totalAmount': 'एकूण रक्कम', 'purchase.advancePaid': 'अॅडव्हान्स दिले', 'purchase.remaining': 'बाकी', // Party Ledger 'ledger.title': 'पार्टी लेजर', 'ledger.selectParty': 'पार्टी निवडा', 'ledger.currentBalance': 'चालू बाकी', 'ledger.toReceive': 'घेणे', 'ledger.toPay': 'देणे', 'ledger.credit': 'जमा', 'ledger.debit': 'नावे', 'ledger.balance': 'बाकी', 'ledger.particulars': 'तपशील', 'ledger.reference': 'संदर्भ', 'ledger.search': 'शोधा', // Bill Books 'billbook.title': 'बिल बुक्स', 'billbook.new': 'नवीन बिल बुक', 'billbook.add': 'बिल बुक जोडा', 'billbook.name': 'बुकचे नाव', 'billbook.serialFrom': 'पहिला नंबर', 'billbook.serialTo': 'शेवटचा नंबर', 'billbook.active': 'सक्रिय', 'billbook.currentNumber': 'चालू नंबर', 'billbook.remaining': 'शिल्लक बिले', 'billbook.activate': 'सक्रिय करा', // Common 'common.save': 'जतन करा', 'common.cancel': 'रद्द करा', 'common.add': 'जोडा', 'common.edit': 'बदला', 'common.delete': 'काढा', 'common.search': 'शोधा', 'common.filter': 'फिल्टर', 'common.export': 'एक्सपोर्ट', 'common.print': 'प्रिंट', 'common.back': 'मागे', 'common.next': 'पुढे', 'common.previous': 'मागील', 'common.close': 'बंद करा', 'common.confirm': 'खात्री करा', 'common.yes': 'होय', 'common.no': 'नाही', 'common.total': 'एकूण', 'common.date': 'तारीख', 'common.amount': 'रक्कम', 'common.quantity': 'संख्या', 'common.kg': 'kg', 'common.bags': 'पोत्या', } }; const LanguageContext = createContext(undefined); export function LanguageProvider({ children }: { children: ReactNode }) { const [language, setLanguage] = useState(() => { // Load from localStorage or default to Marathi const saved = localStorage.getItem('language'); return (saved === 'en' || saved === 'mr') ? saved : 'mr'; }); useEffect(() => { // Save to localStorage whenever language changes localStorage.setItem('language', language); // Update document direction if needed (for future RTL support) document.documentElement.lang = language === 'mr' ? 'mr' : 'en'; }, [language]); const toggleLanguage = () => { setLanguage(prev => prev === 'en' ? 'mr' : 'en'); }; const t = (key: string): string => { return translations[language][key as keyof typeof translations['en']] || key; }; return ( {children} ); } export function useLanguage() { const context = useContext(LanguageContext); if (!context) { throw new Error('useLanguage must be used within a LanguageProvider'); } return context; }