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 (
@@ -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')}
+ >
💡 Pro Tips for Better Recommendations:
+💡 {t('aiRecommender.proTips')}