diff --git a/user/package-lock.json b/user/package-lock.json index 1b362aa..428b309 100644 --- a/user/package-lock.json +++ b/user/package-lock.json @@ -4516,6 +4516,7 @@ "url": "https://www.i18next.com/how-to/faq#i18next-is-awesome.-how-can-i-support-the-project" } ], + "license": "MIT", "dependencies": { "@babel/runtime": "^7.27.6" }, @@ -5947,6 +5948,7 @@ "version": "16.3.3", "resolved": "https://registry.npmjs.org/react-i18next/-/react-i18next-16.3.3.tgz", "integrity": "sha512-IaY2W+ueVd/fe7H6Wj2S4bTuLNChnajFUlZFfCTrTHWzGcOrUHlVzW55oXRSl+J51U8Onn6EvIhQ+Bar9FUcjw==", + "license": "MIT", "dependencies": { "@babel/runtime": "^7.27.6", "html-parse-stringify": "^3.0.1", diff --git a/user/src/components/pages/ai-recommender/AskSaralSeva.jsx b/user/src/components/pages/ai-recommender/AskSaralSeva.jsx index 4986b1d..391721e 100644 --- a/user/src/components/pages/ai-recommender/AskSaralSeva.jsx +++ b/user/src/components/pages/ai-recommender/AskSaralSeva.jsx @@ -1,6 +1,6 @@ import React, { useState, useRef, useEffect } from 'react'; import { Send, RefreshCw, HelpCircle, Lightbulb, Bot } from 'lucide-react'; -import { useTranslation } from 'react-i18next'; // ✅ Add i18next hook +import { useTranslation } from 'react-i18next'; import MessageBubble, { TypingIndicator } from './MessageBubble'; import { extractEntities, generateEntitySummary } from '../../../utils/nlpProcessor'; import { recommendSchemes, generateRecommendationExplanation } from '../../../utils/schemeRecommender'; @@ -22,28 +22,32 @@ const tooltipStyle = { }; const AskSaralSeva = () => { - const { t } = useTranslation(); // ✅ Add translation hook - - const [messages, setMessages] = useState([ - { - id: 1, - text: t('aiRecommender.greeting') + '\n\n' + t('aiRecommender.tellAbout'), - isUser: false, - suggestions: [ - t('aiRecommender.suggestion1'), - t('aiRecommender.suggestion2'), - t('aiRecommender.suggestion3'), - t('aiRecommender.suggestion4') - ], - onSuggestionClick: handleSuggestionClick - } - ]); + const { t } = useTranslation(); + const [messages, setMessages] = useState([]); const [inputText, setInputText] = useState(''); const [isTyping, setIsTyping] = useState(false); const messagesEndRef = useRef(null); const inputRef = useRef(null); + // Initialize messages with translations + useEffect(() => { + setMessages([ + { + id: 1, + text: t('aiRecommender.greeting') + '\n\n' + t('aiRecommender.tellAbout'), + isUser: false, + suggestions: [ + t('aiRecommender.suggestion1'), + t('aiRecommender.suggestion2'), + t('aiRecommender.suggestion3'), + t('aiRecommender.suggestion4') + ], + onSuggestionClick: handleSuggestionClick + } + ]); + }, [t]); + useEffect(() => { messagesEndRef.current?.scrollIntoView({ behavior: 'smooth' }); }, [messages, isTyping]); @@ -79,17 +83,22 @@ const AskSaralSeva = () => { responseText = `${entitySummary}\n\n`; } - responseText += `${t('common.success')}! I found ${recommendations.length} scheme${recommendations.length > 1 ? 's' : ''} that match your profile:`; + const schemeCount = recommendations.length; + const foundMessage = schemeCount === 1 + ? t('aiRecommender.foundScheme').replace('{count}', schemeCount) + : t('aiRecommender.foundSchemes').replace('{count}', schemeCount); + + responseText += foundMessage; schemes = recommendations.map(scheme => ({ ...scheme, explanation: generateRecommendationExplanation(scheme, entities) })); } else { - responseText = `${t('common.error')} - couldn't find any matching schemes.\n\n` + - "• " + t('common.noData') + "\n" + + responseText = `${t('aiRecommender.noMatchingSchemes')}\n\n` + + "• " + t('aiRecommender.noDataAvailable') + "\n" + "• " + t('messages.requiredField') + "\n\n" + - "Try rephrasing your query with more specific information."; + t('aiRecommender.tryRephrasing'); } const botMessage = { @@ -98,8 +107,16 @@ const AskSaralSeva = () => { isUser: false, schemes: schemes, suggestions: recommendations.length > 0 - ? ["Show me more schemes", "Tell me about eligibility", "How do I apply?"] - : ["I'm a farmer looking for subsidies", "Education scholarships for students", "Business loans"] + ? [ + t('aiRecommender.moreInfoSuggestion1'), + t('aiRecommender.moreInfoSuggestion2'), + t('aiRecommender.moreInfoSuggestion3') + ] + : [ + t('aiRecommender.fallbackSuggestion1'), + t('aiRecommender.fallbackSuggestion2'), + t('aiRecommender.fallbackSuggestion3') + ] }; setIsTyping(false); @@ -133,17 +150,15 @@ const AskSaralSeva = () => { return (
-
- + {/* Header */}
-
@@ -153,7 +168,7 @@ const AskSaralSeva = () => {

{t('aiRecommender.title')} - AI Beta + {t('aiRecommender.aiBeta')}

@@ -167,32 +182,34 @@ const AskSaralSeva = () => { className="flex items-center gap-2 px-4 py-2 bg-orange-100 dark:bg-orange-900/30 text-orange-700 dark:text-orange-300 rounded-lg hover:bg-orange-200 dark:hover:bg-orange-900/50 transition-colors" title={t('aiRecommender.reset')} data-tooltip-id="reset-tooltip" - data-tooltip-content={t('aiRecommender.reset')}> + data-tooltip-content={t('aiRecommender.reset')} + > - {t('common.ok')} + {t('aiRecommender.reset')} -

+ {/* Pro Tips Section */}
-

💡 Pro Tips for Better Recommendations:

+

💡 {t('aiRecommender.proTips')}

    -
  • Mention your age, occupation, and location
  • -
  • Specify what type of help you need (education, business, housing, etc.)
  • -
  • Include income details if relevant
  • -
  • Be specific about your situation
  • +
  • {t('aiRecommender.tip1')}
  • +
  • {t('aiRecommender.tip2')}
  • +
  • {t('aiRecommender.tip3')}
  • +
  • {t('aiRecommender.tip4')}
+ {/* Chat Container */}
- + {/* Messages */}
{messages.map(message => ( {
+ {/* Input Form */}
-
{ disabled={!inputText.trim() || isTyping} className="px-6 py-3 bg-gradient-to-r from-orange-600 to-amber-500 text-white rounded-lg hover:from-orange-700 hover:to-amber-600 disabled:opacity-50 disabled:cursor-not-allowed transition-all duration-200 flex items-center gap-2 font-medium shadow-lg hover:shadow-xl text-base" data-tooltip-id="send-tooltip" - data-tooltip-content={t('aiRecommender.send')}> + data-tooltip-content={t('aiRecommender.send')} + > {t('aiRecommender.send')} -

- This AI assistant uses local NLP processing. No data is sent to external servers. + {t('aiRecommender.privacyNotice')}

+ {/* Example Queries */}
-

- Example Queries + {t('aiRecommender.exampleQueries')}

- {[ - "I'm a 45-year-old farmer from Maharashtra looking for irrigation subsidy", - "Need scholarship for my daughter who is in college", - "I'm a woman entrepreneur wanting to start a small business", - "Looking for pension schemes for senior citizens above 60", - "I'm unemployed and want skill development training", - "Need health insurance for my family with low income" + t('aiRecommender.example1'), + t('aiRecommender.example2'), + t('aiRecommender.example3'), + t('aiRecommender.example4'), + t('aiRecommender.example5'), + t('aiRecommender.example6') ].map((example, index) => ( ))} -
@@ -289,4 +304,4 @@ const AskSaralSeva = () => { ); }; -export default AskSaralSeva; +export default AskSaralSeva; \ No newline at end of file diff --git a/user/src/i18n/locales/en.json b/user/src/i18n/locales/en.json index 175026c..385b4a6 100644 --- a/user/src/i18n/locales/en.json +++ b/user/src/i18n/locales/en.json @@ -153,6 +153,8 @@ "aiRecommender": { "title": "Ask SaralSeva", "subtitle": "AI-Powered Scheme Recommender", + "aiBeta": "AI Beta", + "aiAssistant": "AI-Powered Assistant", "greeting": "Hello! I'm SaralSeva AI Assistant. I can help you discover government schemes that match your profile.", "tellAbout": "Tell me about yourself - your age, occupation, location, or what kind of help you're looking for!", "typePlaceholder": "Type your query here...", @@ -165,6 +167,31 @@ "matchPercentage": "Match", "category": "Category", "applyNow": "Apply Now", - "explanation": "Why this scheme matches" + "explanation": "Why this scheme matches", + "proTips": "Pro Tips for Better Recommendations:", + "tip1": "Mention your age, occupation, and location", + "tip2": "Specify what type of help you need (education, business, housing, etc.)", + "tip3": "Include income details if relevant", + "tip4": "Be specific about your situation", + "privacyNotice": "This AI assistant uses local NLP processing. No data is sent to external servers.", + "exampleQueries": "Example Queries", + "clickToTry": "Click to try this example", + "example1": "I'm a 45-year-old farmer from Maharashtra looking for irrigation subsidy", + "example2": "Need scholarship for my daughter who is in college", + "example3": "I'm a woman entrepreneur wanting to start a small business", + "example4": "Looking for pension schemes for senior citizens above 60", + "example5": "I'm unemployed and want skill development training", + "example6": "Need health insurance for my family with low income", + "foundSchemes": "I found {count} schemes that match your profile:", + "foundScheme": "I found {count} scheme that matches your profile:", + "noMatchingSchemes": "Sorry, couldn't find any matching schemes.", + "noDataAvailable": "No data available", + "tryRephrasing": "Try rephrasing your query with more specific information.", + "moreInfoSuggestion1": "Show me more schemes", + "moreInfoSuggestion2": "Tell me about eligibility", + "moreInfoSuggestion3": "How do I apply?", + "fallbackSuggestion1": "I'm a farmer looking for subsidies", + "fallbackSuggestion2": "Education scholarships for students", + "fallbackSuggestion3": "Business loans" } } \ No newline at end of file diff --git a/user/src/i18n/locales/hi.json b/user/src/i18n/locales/hi.json index 4eb6270..67b9759 100644 --- a/user/src/i18n/locales/hi.json +++ b/user/src/i18n/locales/hi.json @@ -153,6 +153,8 @@ "aiRecommender": { "title": "सराल सेवा से पूछें", "subtitle": "एआई-संचालित योजना सिफारिशकर्ता", + "aiBeta": "एआई बीटा", + "aiAssistant": "एआई-संचालित सहायक", "greeting": "नमस्ते! मैं SaralSeva AI असिस्टेंट हूँ। मैं आपको आपकी प्रोफाइल से मेल खाने वाली सरकारी योजनाओं की खोज करने में मदद कर सकता हूँ।", "tellAbout": "मुझे अपने बारे में बताएं - आपकी उम्र, व्यवसाय, स्थान, या आपको किस प्रकार की सहायता चाहिए!", "typePlaceholder": "अपनी क्वेरी यहाँ टाइप करें...", @@ -165,6 +167,31 @@ "matchPercentage": "मेल", "category": "श्रेणी", "applyNow": "अभी आवेदन करें", - "explanation": "यह योजना क्यों मेल खाती है" + "explanation": "यह योजना क्यों मेल खाती है", + "proTips": "बेहतर सिफारिशों के लिए प्रो टिप्स:", + "tip1": "अपनी उम्र, व्यवसाय और स्थान का उल्लेख करें", + "tip2": "बताएं कि आपको किस प्रकार की सहायता चाहिए (शिक्षा, व्यवसाय, आवास, आदि)", + "tip3": "प्रासंगिक होने पर आय विवरण शामिल करें", + "tip4": "अपनी स्थिति के बारे में विशिष्ट रहें", + "privacyNotice": "यह एआई सहायक स्थानीय NLP प्रोसेसिंग का उपयोग करता है। कोई डेटा बाहरी सर्वर पर नहीं भेजा जाता है।", + "exampleQueries": "उदाहरण प्रश्न", + "clickToTry": "इस उदाहरण को आज़माने के लिए क्लिक करें", + "example1": "मैं महाराष्ट्र से 45 साल का किसान हूँ जो सिंचाई सब्सिडी की तलाश में हूँ", + "example2": "मेरी बेटी के लिए छात्रवृत्ति चाहिए जो कॉलेज में है", + "example3": "मैं एक महिला उद्यमी हूँ जो छोटा व्यवसाय शुरू करना चाहती हूँ", + "example4": "60 वर्ष से अधिक उम्र के वरिष्ठ नागरिकों के लिए पेंशन योजनाएं खोज रही हूँ", + "example5": "मैं बेरोजगार हूँ और कौशल विकास प्रशिक्षण चाहता हूँ", + "example6": "कम आय वाले अपने परिवार के लिए स्वास्थ्य बीमा चाहिए", + "foundSchemes": "मुझे आपकी प्रोफाइल से मेल खाने वाली {count} योजनाएं मिलीं:", + "foundScheme": "मुझे आपकी प्रोफाइल से मेल खाने वाली {count} योजना मिली:", + "noMatchingSchemes": "क्षमा करें, कोई मेल खाने वाली योजना नहीं मिली।", + "noDataAvailable": "कोई डेटा उपलब्ध नहीं है", + "tryRephrasing": "अधिक विशिष्ट जानकारी के साथ अपनी क्वेरी को दोबारा लिखने का प्रयास करें।", + "moreInfoSuggestion1": "योजनाओं के बारे में अधिक जानकारी दिखाएं", + "moreInfoSuggestion2": "मुझे पात्रता के बारे में बताएं", + "moreInfoSuggestion3": "मैं कैसे आवेदन करूं?", + "fallbackSuggestion1": "मैं एक किसान हूँ जो सब्सिडी की तलाश में हूँ", + "fallbackSuggestion2": "छात्रों के लिए शिक्षा छात्रवृत्ति", + "fallbackSuggestion3": "व्यावसायिक ऋण" } } \ No newline at end of file