Class TranslateModule

  • All Implemented Interfaces:

    
    public final class TranslateModule
    
                        

    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 ->
        // ...
    }
    • Constructor Detail

    • Method Detail

      • 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-translation
        handler - 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 identifiers
        strategy - Translation strategy to apply
        handler - Operation result callback; error is null on success