Chat
Quetzal React SDK
This SDK enables automatic, real-time translation of chat messages in your React application.
Make sure your project already includes react
and react-dom
.
⚙️ Setup
1. Wrap your app in the provider
🛠️ Backend: Create a new chat
Before users can chat, create a new Quetzal chat on the backend:
🔄 Frontend: Setting up the chat
Use the useQuetzalChat
hook in your component:
Initialize the chat on load
This will call getChatMetadata
under the hood and store the quetzalChatId
and participants in context.
✉️ Fetching + Translating Messages
1. Fetch messages from your backend
2. Fetch existing translations
3. Request translations if missing
4. Construct final message objects
🌐 Updating Participant Locale
If a participant changes their language in your app:
👁️ Managing Message Display State
The SDK tracks whether a message is showing the translated or original version:
Set display state:
Get current state:
You can use this to implement “Show original” / “Show translation” toggles.
🧠 Full Integration Flow
Step | Description |
---|---|
1️⃣ | Backend calls /chat/new with participants and internal chat ID |
2️⃣ | Frontend calls setUpChat(externalChatId) |
3️⃣ | Call setCurrentParticipantId(participantId) |
4️⃣ | Fetch your app’s chat messages |
5️⃣ | Call fetchTranslationsByExternalIdAndStore(messageIds) |
6️⃣ | Use translateBatchMessagesAndStore() if needed |
7️⃣ | Use getTranslationForCurrentParticipant(msg.id) for each message |
8️⃣ | Use setTranslatedMessageDisplayState() to control toggle UI |
9️⃣ | On language change, call maybeUpdateChat() |
🧪 Example UI Toggle
🔌 Additional Resources
Hosted Demo: http://chatdemo.getquetzal.com/
Demo Project Repo: https://github.com/mubtAAhij/thumbtack-quetzal-demo
Start translating conversations effortlessly with Quetzal.