Translate Module
Translation feature module.
Provides translation-related features including message translation, text translation, translation language management, auto-translation toggle, and channel translation strategy configuration.
This class is a singleton, accessible via ai.nexconn.chat.NCEngine.translateModule. No internal dependencies are exposed externally.
// Translate messages
val params = TranslateMessagesParams(
listOf(
TranslateMessageParam("messageId1"),
TranslateMessageParam("messageId2").apply {
targetLanguage = "en"
}
)
)
NCEngine.translateModule.translateMessages(params) { error ->
if (error == null) {
// Translation request sent successfully
}
}
// Translate text
val textParams = TranslateTextsParams(
listOf(TranslateTextParam("Hello, world!"))
)
NCEngine.translateModule.translateTexts(textParams) { error ->
// ...
}
// Set translation language
NCEngine.translateModule.setTranslationLanguage("en") { error ->
// ...
}
// Get translation language
NCEngine.translateModule.getTranslationLanguage { language, error ->
if (error == null && language != null) {
println("Current translation language: $language")
}
}
// Set auto-translation toggle
NCEngine.translateModule.setAutoTranslateEnabled(true) { error ->
// ...
}
// Get auto-translation status
NCEngine.translateModule.getAutoTranslateEnabled { isEnabled, error ->
if (error == null && isEnabled != null) {
println("Auto-translation enabled: $isEnabled")
}
}
// Set channel translation strategy
val identifiers = listOf(
ChannelIdentifier(ChannelType.DIRECT, "userId1"),
ChannelIdentifier(ChannelType.GROUP, "groupId1"),
)
NCEngine.translateModule.setTranslateStrategy(identifiers, TranslateStrategy.AUTO_ON) { error ->
// ...
}Content copied to clipboard
Functions
Link copied to clipboard
Gets the current auto-translation enabled status.
Link copied to clipboard
Gets the current user-level target translation language.
Link copied to clipboard
Enables or disables auto-translation.
Link copied to clipboard
public final Unit setTranslateStrategy(List<ChannelIdentifier> identifiers, TranslateStrategy strategy, ErrorHandler handler)
Sets the translation strategy for specified channels.
Link copied to clipboard
Sets the user-level target translation language.
Link copied to clipboard
Translates messages.
Link copied to clipboard
Translates text.