Class TranslateModule
-
- All Implemented Interfaces:
public final class TranslateModuleTranslation 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 -> // ... }
-
-
Method Summary
Modifier and Type Method Description final UnittranslateMessages(TranslateMessagesParams params, ErrorHandler handler)Translates messages. final UnittranslateTexts(TranslateTextsParams params, ErrorHandler handler)Translates text. final UnitsetTranslationLanguage(String language, ErrorHandler handler)Sets the user-level target translation language. final UnitgetTranslationLanguage(OperationHandler<String> handler)Gets the current user-level target translation language. final UnitgetAutoTranslateEnabled(OperationHandler<Boolean> handler)Gets the current auto-translation enabled status. final UnitsetAutoTranslateEnabled(Boolean isEnabled, ErrorHandler handler)Enables or disables auto-translation. final UnitsetTranslateStrategy(List<ChannelIdentifier> identifiers, TranslateStrategy strategy, ErrorHandler handler)Sets the translation strategy for specified channels. -
-
Method Detail
-
translateMessages
final Unit translateMessages(TranslateMessagesParams params, ErrorHandler handler)
Translates messages.
Sends a message translation request. The translation result is delivered asynchronously via ai.nexconn.chat.handler.TranslateHandler.onTranslationCompleted.
- Parameters:
params- Translation message parametershandler- Operation result callback; error is null on success
-
translateTexts
final Unit translateTexts(TranslateTextsParams params, ErrorHandler handler)
Translates text.
Sends a text translation request. The translation result is delivered asynchronously via ai.nexconn.chat.handler.TranslateHandler.onTranslationCompleted.
- Parameters:
params- Translation text parametershandler- Operation result callback; error is null on success
-
setTranslationLanguage
final Unit setTranslationLanguage(String language, ErrorHandler handler)
Sets the user-level target translation language.
The SDK does not validate the language string.
- Parameters:
language- Target translation language code (e.g.handler- Operation result callback; error is null on success
-
getTranslationLanguage
final Unit getTranslationLanguage(OperationHandler<String> handler)
Gets the current user-level target translation language.
- Parameters:
handler- Query result callback; returns the translation language on success
-
getAutoTranslateEnabled
final Unit getAutoTranslateEnabled(OperationHandler<Boolean> handler)
Gets the current auto-translation enabled status.
- Parameters:
handler- Query result callback; returns whether auto-translation is enabled
-
setAutoTranslateEnabled
final Unit setAutoTranslateEnabled(Boolean isEnabled, ErrorHandler handler)
Enables or disables auto-translation.
When enabled, messages will be automatically translated to the target language.
- Parameters:
isEnabled- Whether to enable auto-translationhandler- Operation result callback; error is null on success
-
setTranslateStrategy
final Unit setTranslateStrategy(List<ChannelIdentifier> identifiers, TranslateStrategy strategy, ErrorHandler handler)
Sets the translation strategy for specified channels.
Supports three modes: follow user-level configuration, enable auto-translation, and manual translation.
val identifiers = listOf( ChannelIdentifier(ChannelType.DIRECT, "userId1"), ChannelIdentifier(ChannelType.GROUP, "groupId1"), ) NCEngine.translateModule.setTranslateStrategy(identifiers, TranslateStrategy.AUTO_ON) { error -> if (error == null) { // Successfully set } }- Parameters:
identifiers- List of channel identifiersstrategy- Translation strategy to applyhandler- Operation result callback; error is null on success
-
-
-
-