From 662edaace698f5a58795ad978b0f80da9e72afd0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sedat=20=C3=96zt=C3=BCrk?= Date: Wed, 17 Jun 2026 22:19:19 +0300 Subject: [PATCH] MessengerWidget translate LanguageKey --- .../Seeds/LanguagesData.json | 168 ++++++++++++ .../components/template/MessengerWidget.tsx | 256 ++++++++++++------ 2 files changed, 341 insertions(+), 83 deletions(-) diff --git a/api/src/Sozsoft.Platform.DbMigrator/Seeds/LanguagesData.json b/api/src/Sozsoft.Platform.DbMigrator/Seeds/LanguagesData.json index ed9ff49..e258bc9 100644 --- a/api/src/Sozsoft.Platform.DbMigrator/Seeds/LanguagesData.json +++ b/api/src/Sozsoft.Platform.DbMigrator/Seeds/LanguagesData.json @@ -19465,6 +19465,174 @@ "key": "ListForms.ListForm.Workflow.UndefinedUser", "en": "Undefined", "tr": "Tanımsız" + }, + { + "resourceName": "Platform", + "key": "MessengerWidget.Title", + "en": "Messenger", + "tr": "Messenger" + }, + { + "resourceName": "Platform", + "key": "MessengerWidget.Connected", + "en": "Connected", + "tr": "Bağlı" + }, + { + "resourceName": "Platform", + "key": "MessengerWidget.Connecting", + "en": "Connecting", + "tr": "Bağlanıyor" + }, + { + "resourceName": "Platform", + "key": "MessengerWidget.Minimize", + "en": "Minimize", + "tr": "Küçült" + }, + { + "resourceName": "Platform", + "key": "MessengerWidget.Maximize", + "en": "Maximize", + "tr": "Büyüt" + }, + { + "resourceName": "Platform", + "key": "MessengerWidget.SearchPerson", + "en": "Search person", + "tr": "Kişi ara" + }, + { + "resourceName": "Platform", + "key": "MessengerWidget.MultiSelect", + "en": "Multi-select", + "tr": "Çoklu seçim" + }, + { + "resourceName": "Platform", + "key": "MessengerWidget.MultiSelectEnabled", + "en": "Multi-select enabled", + "tr": "Çoklu seçim açık" + }, + { + "resourceName": "Platform", + "key": "MessengerWidget.Online", + "en": "Online", + "tr": "Online" + }, + { + "resourceName": "Platform", + "key": "MessengerWidget.Offline", + "en": "Offline", + "tr": "Offline" + }, + { + "resourceName": "Platform", + "key": "MessengerWidget.PeopleSelected", + "en": "people selected", + "tr": "kişi seçildi" + }, + { + "resourceName": "Platform", + "key": "MessengerWidget.Chat", + "en": "Chat", + "tr": "Sohbet" + }, + { + "resourceName": "Platform", + "key": "MessengerWidget.GroupMessage", + "en": "Group message", + "tr": "Toplu mesaj" + }, + { + "resourceName": "Platform", + "key": "MessengerWidget.OfflineUserSelected", + "en": "Offline user selected", + "tr": "Offline kullanıcı seçili" + }, + { + "resourceName": "Platform", + "key": "MessengerWidget.SelectPersonToSendMessage", + "en": "Select a person to send a message", + "tr": "Mesaj göndermek için kişi seçin" + }, + { + "resourceName": "Platform", + "key": "MessengerWidget.NoMessagesYet", + "en": "No messages yet", + "tr": "Henüz mesaj yok" + }, + { + "resourceName": "Platform", + "key": "MessengerWidget.Me", + "en": "Me", + "tr": "Ben" + }, + { + "resourceName": "Platform", + "key": "MessengerWidget.DeleteMessage", + "en": "Delete message", + "tr": "Mesajı sil" + }, + { + "resourceName": "Platform", + "key": "MessengerWidget.AddFile", + "en": "Add file", + "tr": "Dosya ekle" + }, + { + "resourceName": "Platform", + "key": "MessengerWidget.Emoji", + "en": "Emoji", + "tr": "Emoji" + }, + { + "resourceName": "Platform", + "key": "MessengerWidget.WriteMessage", + "en": "Write a message", + "tr": "Mesaj yazın" + }, + { + "resourceName": "Platform", + "key": "MessengerWidget.OfflineUsersCannotReceiveMessages", + "en": "Messages cannot be sent to offline users", + "tr": "Offline kullanıcılara mesaj gönderilemez" + }, + { + "resourceName": "Platform", + "key": "MessengerWidget.FileSizeLimitExceeded", + "en": "File cannot exceed the 10 MB limit", + "tr": "Dosya 10 MB sınırını aşamaz" + }, + { + "resourceName": "Platform", + "key": "MessengerWidget.FileUploadFailed", + "en": "File could not be uploaded", + "tr": "Dosya yüklenemedi" + }, + { + "resourceName": "Platform", + "key": "MessengerWidget.OnlyOnlineUsersCanReceiveMessages", + "en": "You can only send messages to online users", + "tr": "Sadece online kullanıcılara mesaj gönderebilirsiniz" + }, + { + "resourceName": "Platform", + "key": "MessengerWidget.MessageSendFailed", + "en": "Message could not be sent", + "tr": "Mesaj gönderilemedi" + }, + { + "resourceName": "Platform", + "key": "MessengerWidget.DeleteMessageConfirmation", + "en": "Delete message?", + "tr": "Mesaj silinsin mi?" + }, + { + "resourceName": "Platform", + "key": "MessengerWidget.MessageDeleteFailed", + "en": "Message could not be deleted", + "tr": "Mesaj silinemedi" } ] } diff --git a/ui/src/components/template/MessengerWidget.tsx b/ui/src/components/template/MessengerWidget.tsx index 5a2c838..e07a331 100644 --- a/ui/src/components/template/MessengerWidget.tsx +++ b/ui/src/components/template/MessengerWidget.tsx @@ -29,6 +29,7 @@ import { FaTrash, } from 'react-icons/fa' import { IoCheckmarkDone, IoChatbubbleEllipsesOutline, IoSend } from 'react-icons/io5' +import { useLocalization } from '@/utils/hooks/useLocalization' const MAX_UPLOAD_SIZE = 10 * 1024 * 1024 const CONTACT_REFRESH_INTERVAL = 30000 @@ -47,6 +48,7 @@ const MessengerWidget = () => { const fileInputRef = useRef(null) const messageInputRef = useRef(null) const messagesEndRef = useRef(null) + const { translate } = useLocalization() const [open, setOpen] = useState(false) const [contacts, setContacts] = useState([]) @@ -71,7 +73,9 @@ const MessengerWidget = () => { if (!auth.session.signedIn) return const unsubscribeMessage = messengerSignalR.onMessage((message) => { - setMessages((prev) => (prev.some((item) => item.id === message.id) ? prev : [...prev, message])) + setMessages((prev) => + prev.some((item) => item.id === message.id) ? prev : [...prev, message], + ) if (message.senderId !== auth.user.id && (!open || !selectedIds.includes(message.senderId))) { setUnreadByContact((current) => ({ ...current, @@ -161,16 +165,25 @@ const MessengerWidget = () => { return messages.filter((message) => { const isOwn = message.senderId === auth.user.id const participants = new Set([message.senderId, ...message.recipientIds]) - return selectedIds.some((id) => participants.has(id)) && (isOwn || selectedIds.includes(message.senderId)) + return ( + selectedIds.some((id) => participants.has(id)) && + (isOwn || selectedIds.includes(message.senderId)) + ) }) }, [auth.user.id, messages, selectedIds]) const toggleContact = (id: string) => { const contact = contacts.find((item) => item.id === id) if (!contact?.isOnline) { - toast.push(, { - placement: 'top-end', - }) + toast.push( + , + { + placement: 'top-end', + }, + ) return } @@ -187,7 +200,9 @@ const MessengerWidget = () => { return } - setSelectedIds((prev) => (prev.includes(id) ? prev.filter((item) => item !== id) : [...prev, id])) + setSelectedIds((prev) => + prev.includes(id) ? prev.filter((item) => item !== id) : [...prev, id], + ) } const toggleMultiSelect = () => { @@ -215,9 +230,15 @@ const MessengerWidget = () => { const nextFiles = Array.from(files) const tooLarge = nextFiles.find((file) => file.size > MAX_UPLOAD_SIZE) if (tooLarge) { - toast.push(, { - placement: 'top-end', - }) + toast.push( + , + { + placement: 'top-end', + }, + ) return } @@ -228,7 +249,10 @@ const MessengerWidget = () => { ) setAttachments((prev) => [...prev, ...uploaded]) } catch { - toast.push(, { placement: 'top-end' }) + toast.push( + , + { placement: 'top-end' }, + ) } finally { setUploading(false) if (fileInputRef.current) fileInputRef.current.value = '' @@ -239,9 +263,15 @@ const MessengerWidget = () => { const trimmedText = text.trim() if (selectedIds.length === 0 || (!trimmedText && attachments.length === 0)) return if (!canSendToSelectedContacts) { - toast.push(, { - placement: 'top-end', - }) + toast.push( + , + { + placement: 'top-end', + }, + ) return } @@ -258,17 +288,23 @@ const MessengerWidget = () => { messageInputRef.current?.focus() }, 0) } catch { - toast.push(, { placement: 'top-end' }) + toast.push( + , + { placement: 'top-end' }, + ) } } const deleteMessage = async (messageId: string) => { - if (!window.confirm('Mesaj silinsin mi?')) return + if (!window.confirm(translate('::MessengerWidget.DeleteMessageConfirmation'))) return try { await messengerSignalR.deleteMessage(messageId) } catch { - toast.push(, { placement: 'top-end' }) + toast.push( + , + { placement: 'top-end' }, + ) } } @@ -294,19 +330,33 @@ const MessengerWidget = () => { >
- +
- {auth.user.name || auth.user.userName || 'Messenger'} + {auth.user.name || auth.user.userName || translate('::MessengerWidget.Title')}
- - {connected ? 'Bağlı' : 'Bağlanıyor'} + + {connected + ? translate('::MessengerWidget.Connected') + : translate('::MessengerWidget.Connecting')}
- +
@@ -354,9 +406,15 @@ const MessengerWidget = () => { : 'cursor-not-allowed opacity-60' }`} > - + - {contact.fullName} + + {contact.fullName} + { contact.isOnline ? 'bg-emerald-500' : 'bg-red-500' }`} /> - {contact.isOnline ? 'Online' : 'Offline'} + {contact.isOnline + ? translate('::MessengerWidget.Online') + : translate('::MessengerWidget.Offline')} {contactUnread > 0 && ( @@ -375,7 +435,9 @@ const MessengerWidget = () => { {contactUnread > 99 ? '99+' : contactUnread} )} - {active && contactUnread === 0 && } + {active && contactUnread === 0 && ( + + )} ) })} @@ -400,7 +462,10 @@ const MessengerWidget = () => { )} {selectedContacts.length > 1 && ( @@ -413,24 +478,30 @@ const MessengerWidget = () => { {selectedContacts.length === 1 ? selectedContacts[0].fullName : selectedContacts.length > 1 - ? `${selectedContacts.length} kişi seçildi` - : 'Sohbet'} + ? `${selectedContacts.length} ${translate('::MessengerWidget.PeopleSelected')}` + : translate('::MessengerWidget.Chat')}
{selectedContacts.length === 1 - ? `${selectedContacts[0].isOnline ? 'Online' : 'Offline'} - ${ + ? `${selectedContacts[0].isOnline ? translate('::MessengerWidget.Online') : translate('::MessengerWidget.Offline')} - ${ selectedContacts[0].email || selectedContacts[0].userName }` : selectedContacts.length > 1 ? canSendToSelectedContacts - ? 'Toplu mesaj' - : 'Offline kullanici secili' - : 'Mesaj göndermek için kişi seçin'} + ? translate('::MessengerWidget.GroupMessage') + : translate('::MessengerWidget.OfflineUserSelected') + : translate('::MessengerWidget.SelectPersonToSendMessage')}
- +