[Problem/Question]
We are using SendBird for chat and VoIP calls, and to be more precise, we use the Group-channel.
Now, we are trying to implement auto-translation feature but we couldn’t find any documentation how to perform that exactly. For now, we are NOT implementing our chat list or adapter. We use this sdk as is out of the box.
Recently, we implemented CustomFragmen
t via CustomFragmentFactory
, in order to add the translation feature (or at least we were hoping this is the path we need).
This is what we use:
SendbirdUIKit.setUIKitFragmentFactory(CustomFragmentFactory(context))
SendbirdUIKit.setDefaultThemeMode(SendbirdUIKit.ThemeMode.Light)
Also, we use CustomMessageListComponent
.
There are two cases where we need to use translate feature:
- New message arrives - we need to translate it and display it in the chat (translated)
- Previous/existing messages to be translated as well
Most confusing part to us is that we don’t know how to update the UI with translated message, or messages. In the documentation all we can find is this comment: // Display translation in the UI.
This is from the documentation:
SendbirdChat.addChannelHandler(
UNIQUE_HANDLER_ID,
object : GroupChannelHandler() {
override fun onMessageReceived(channel: BaseChannel, message: BaseMessage) {
if (message is UserMessage) {
val map = message.translations
val esTranslatedMessage = map["es"] // Spanish
// Display translation in the UI.
}
}
}
)
It does not show how to update the UI.
Should we override the Adapter for messages?
How to access and update UI in the adapter?
Recently, we tried overriding the fragment, where we could load the messages list from LiveData, and try translating it on-demand, message by message. After that we would try calling adapter.setItems(…), with our list.
Of course, it does not work as expected.
P.S. For chat initialization, we use SendbirdUIKit.init().
These are the lib versions we use:
com.sendbird.sdk:uikit:3.2.0
com.sendbird.sdk:sendbird-chat:3.8.2