Components

This is a configuration section of Custom MT. Components are declared as objects within the configuration:

{
    "components": {
        "preTranslation": {},
        "postTranslation": {},
        "contextMemory": {},
        "usageChecker": {},
        "interceptorRequest": {}
    }
}

preTranslation

Processes the source text before sending it to the translation service.

  • allowLineBreaks: boolean

  • excludeStrings: string

  • regexpMatch: string

  • regexpReplace: string

{
    "components": {
        "preTranslation":{
            "allowLineBreaks": true,
            "regexpReplace": "[\"\\n\", \"g\", \"\\\\n \"]"
        }
    }
}

postTranslation

Processes the translated text after receiving it from the translation service.

  • regexpMatch: string

  • regexpReplace: string

{
    "components": {
        "postTranslation": {
            "regexpReplace": "[\"\\\\\\\\n\", \"g\", \"\\n\"]"
        }
    }
}

contextMemory

Maintains context history for AI/LLM translations, allowing the model to reference previous dialogue for improved coherence and accuracy.

Required Parameters

  • schema: Array of objects <{type: string, name: string, default: string|number|bool}>

  • formBuilder: Array of objects <{type: string, form: string, name: string, default: string|number}>

  • components: object - Component reference to schema name <schema:string>

{
    "schema": {
        { "type": "boolean", "name": "contextMemory.status", "default": true },
        { "type": "string", "name": "contextMemory.initial_prompt", "default": "" },
        { "type": "string", "name": "contextMemory.system_template", "default": "" },
        { "type": "string", "name": "contextMemory.user_template", "default": "[{ \"role\": \"user\", \"parts\":[{\"text\":\"$SOURCE_TEXT\"}] }]" },
        { "type": "string", "name": "contextMemory.assistant_template", "default": "[{ \"role\": \"model\", \"parts\":[{\"text\":\"$TRANSLATED_TEXT\"}] }]" },
        { "type": "string", "name": "contextMemory.data_source", "default": "new_translation" },
        { "type": "number", "name": "contextMemory.max_entries", "default": "1" },
    },
    "formBuilder": {
        { "type": "string", "form": "textarea", "width": "450", "name": "contextMemory.user_template", "default": "", "title": "User Template" },
        { "type": "string", "form": "textarea", "width": "450", "name": "contextMemory.assistant_template", "default": "", "title": "Assistant Template" },
        { "type": "string", "form": "select", "name": "contextMemory.data_source", "title": "Context Source", "default": "TM",
            "options": [
                { "name": "New Translation History", "value": "new_translation" },
                { "name": "Translation Memory", "value": "TM" }                
            ]
        },
        { "type": "number", "form": "range", "name": "contextMemory.max_entries", "title": "Max Context Entries", "default": "1", "min": "1", "max": "256", "step": "1" }

    },
    "components": {
        "contextMemory": {
            "schema": "contextMemory"
        }
    }
}

usageChecker

  • interval: number - Interval in milliseconds between usage checks

  • format: string - Display format for usage information

  • request: object - Request configuration for checking usage:

    • method: string - HTTP method ("http_get", "http_post")

    • url: string - API endpoint URL for usage information

    • body: object (optional) - Request body for POST requests

    • options: object (optional) - Additional request options:

      • headers: object - Custom request headers

    • responseCountQuery: string - JSON path to extract current usage count

    • responseLimitQuery: string - JSON path to extract usage limit

{
    "components": {
        "usageChecker": {
            "interval": 60000,
            "format": "( $COUNT / $LIMIT )",
            "request": {
                "method": "http_get",
                "url": "https://api.deepl.com/v2/usage?auth_key=$API_KEY",
                "responseCountQuery": "character_count",
                "responseLimitQuery": "character_limit"
            }        
        }
    }
}

interceptorRequest

Modifies the source text before sending it to the translation service.

  • prependSourceText: object - Adds text before the source text:

    • status: boolean - Enable or disable prepending

    • value: string - Text to prepend

  • appendSourceText: object - Adds text after the source text:

    • status: boolean - Enable or disable appending

    • value: string - Text to append

  • replaceSourceText: object - Replaces the entire source text

{
    "schema": {
        { "type": "boolean", "name": "interceptorRequest.prependSourceText", "default": false },
        { "type": "string", "name": "prompt", "default": "Translate the following text from $SOURCE_LANG to $TARGET_LANG: " }
    },
    "components": {
        "interceptorRequest":{
            "prependSourceText": {
                "status": false,
                "value": "$PROMPT"
            }         
        }
    }
}