← Back to Cookbook

Content Translator

Translates content into multiple languages with tone preservation.

ai

Source

/**
 * Translates content into multiple languages using AI.
 */

form translate_form {
  label: "Translate Content"
  schema: @json {
    {
      "type": "object",
      "required": ["content", "target_language"],
      "properties": {
        "content": { "type": "string", "title": "Content to Translate" },
        "target_language": {
          "type": "string",
          "title": "Target Language",
          "enum": ["Spanish", "French", "German", "Japanese", "Portuguese", "Chinese"]
        },
        "tone": {
          "type": "string",
          "title": "Tone",
          "enum": ["formal", "casual", "technical"],
          "default": "formal"
        }
      }
    }
  }
}

graph translate_content {
  label: "Translate Content"

  root {
    type: code
    label: "Extract request"
    code: @ts { return context.nodes.root.input }
    outputSchema: @json {
      {
        "type": "object",
        "properties": {
          "content": { "type": "string" },
          "target_language": { "type": "string" },
          "tone": { "type": "string" }
        }
      }
    }
  }

  node translate {
    type: ai
    label: "Translate"
    kind: object
    model: "google/gemini-2.5-flash"
    prompt: @ts {
      const req = context.nodes.root.output
      return "Translate the following content into " + req.target_language + " using a " + (req.tone || "formal") + " tone. Preserve formatting.\n\nContent:\n" + req.content
    }
    schema: @json {
      {
        "type": "object",
        "required": ["translation", "source_language"],
        "properties": {
          "translation": { "type": "string" },
          "source_language": { "type": "string" },
          "notes": { "type": "string" }
        }
      }
    }
  }

  node format_result {
    type: code
    label: "Format result"
    code: @ts {
      const req = context.nodes.root.output
      const result = context.nodes.translate.output
      return {
        original: req.content,
        translated: result.translation,
        from: result.source_language,
        to: req.target_language,
        notes: result.notes || ""
      }
    }
  }

  flow {
    root -> translate
    translate -> format_result
  }
}

trigger on_translate {
  form:translate_form -> translate_content
  enabled: true
}

Flow

Trigger → graph

Graph nodes