> ## Documentation Index
> Fetch the complete documentation index at: https://docs.case.dev/llms.txt
> Use this file to discover all available pages before exploring further.

# Translate Text

> Translate text between languages

Translate text to any of 100+ supported languages using neural machine translation.

```bash title="Endpoint" theme={"theme":{"light":"github-light","dark":"one-dark-pro"}}
POST /translate/v1/translate
```

<CodeGroup>
  ```bash title="cURL" theme={"theme":{"light":"github-light","dark":"one-dark-pro"}}
  curl -X POST https://api.case.dev/translate/v1/translate \
    -H "Authorization: Bearer sk_case_YOUR_API_KEY" \
    -H "Content-Type: application/json" \
    -d '{
      "q": "The plaintiff filed a motion for summary judgment.",
      "target": "es"
    }'
  ```

  ```bash title="CLI" theme={"theme":{"light":"github-light","dark":"one-dark-pro"}}
  casedev translate:v1 translate \
    --q "The deposition will be held on Monday." \
    --target es
  ```

  ```typescript title="Typescript" theme={"theme":{"light":"github-light","dark":"one-dark-pro"}}
  import Casedev from 'casedev';

  const client = new Casedev({ apiKey: 'sk_case_YOUR_API_KEY' });

  const result = await client.translate.v1.translate({
    q: 'The plaintiff filed a motion for summary judgment.',
    target: 'es'
  });

  console.log(result.data.translations[0].translatedText);
  // "El demandante presentó una moción de juicio sumario."
  ```

  ```python title="Python" theme={"theme":{"light":"github-light","dark":"one-dark-pro"}}
  import casedev

  client = casedev.Casedev(api_key='sk_case_YOUR_API_KEY')

  result = client.translate.v1.translate(
      q='The plaintiff filed a motion for summary judgment.',
      target='es'
  )

  print(result.data.translations[0].translated_text)
  # "El demandante presentó una moción de juicio sumario."
  ```

  ```go title="Go" theme={"theme":{"light":"github-light","dark":"one-dark-pro"}}
  result, _ := client.Translate.V1.Translate(ctx, casedev.TranslateV1TranslateParams{
  	Q:      casedev.F("The deposition will be held on Monday at 10:00 AM."),
  	Target: casedev.F("es"),
  })
  fmt.Println(result.Data.Translations[0].TranslatedText)
  ```
</CodeGroup>

```json title="Response" theme={"theme":{"light":"github-light","dark":"one-dark-pro"}}
{
  "data": {
    "translations": [
      {
        "translatedText": "El demandante presentó una moción de juicio sumario.",
        "detectedSourceLanguage": "en"
      }
    ]
  }
}
```

## Parameters

### Required

| Parameter | Type                | Description                                                               |
| --------- | ------------------- | ------------------------------------------------------------------------- |
| `q`       | string or string\[] | Text to translate. Can be a single string or array for batch translation. |
| `target`  | string              | Target language code (ISO 639-1), e.g., `es`, `fr`, `de`, `zh`            |

### Optional

| Parameter | Type   | Default     | Description                                                           |
| --------- | ------ | ----------- | --------------------------------------------------------------------- |
| `source`  | string | auto-detect | Source language code. If omitted, language is automatically detected. |
| `format`  | string | `text`      | Format of source text: `text` or `html`                               |
| `model`   | string | `nmt`       | Translation model: `nmt` (neural) or `base`                           |

## Batch translation

Translate multiple strings in a single request:

<CodeGroup>
  ```bash title="CLI" theme={"theme":{"light":"github-light","dark":"one-dark-pro"}}
  casedev translate:v1 translate \
    --q "The deposition will be held on Monday." \
    --target es
  ```

  ```typescript title="Typescript" theme={"theme":{"light":"github-light","dark":"one-dark-pro"}}
  const result = await client.translate.v1.translate({
    q: [
      'Hello',
      'Goodbye',
      'Thank you',
      'Please sign here'
    ],
    target: 'fr',
    source: 'en'
  });

  result.data.translations.forEach((t, i) => {
    console.log(t.translatedText);
  });
  // "Bonjour"
  // "Au revoir"
  // "Merci"
  // "Veuillez signer ici"
  ```

  ```python title="Python" theme={"theme":{"light":"github-light","dark":"one-dark-pro"}}
  result = client.translate.v1.translate(
      q=[
          'Hello',
          'Goodbye',
          'Thank you',
          'Please sign here'
      ],
      target='fr',
      source='en'
  )

  for t in result.data.translations:
      print(t.translated_text)
  # "Bonjour"
  # "Au revoir"
  # "Merci"
  # "Veuillez signer ici"
  ```

  ```go title="Go" theme={"theme":{"light":"github-light","dark":"one-dark-pro"}}
  result, _ := client.Translate.V1.Translate(ctx, casedev.TranslateV1TranslateParams{
  	Q:      casedev.F("The deposition will be held on Monday at 10:00 AM."),
  	Target: casedev.F("es"),
  })
  fmt.Println(result.Data.Translations[0].TranslatedText)
  ```
</CodeGroup>

## HTML preservation

Preserve HTML tags during translation with `format: 'html'`:

<CodeGroup>
  ```bash title="cURL" theme={"theme":{"light":"github-light","dark":"one-dark-pro"}}
  curl -X POST https://api.case.dev/translate/v1/translate \
    -H "Authorization: Bearer sk_case_YOUR_API_KEY" \
    -H "Content-Type: application/json" \
    -d '{
      "q": "<p>The <strong>defendant</strong> denies all allegations.</p>",
      "target": "de",
      "format": "html"
    }'
  ```

  ```bash title="CLI" theme={"theme":{"light":"github-light","dark":"one-dark-pro"}}
  casedev translate:v1 translate \
    --q "The deposition will be held on Monday." \
    --target es
  ```

  ```typescript title="Typescript" theme={"theme":{"light":"github-light","dark":"one-dark-pro"}}
  const result = await client.translate.v1.translate({
    q: '<p>The <strong>defendant</strong> denies all allegations.</p>',
    target: 'de',
    format: 'html'
  });

  console.log(result.data.translations[0].translatedText);
  // "<p>Der <strong>Beklagte</strong> bestreitet alle Anschuldigungen.</p>"
  ```

  ```python title="Python" theme={"theme":{"light":"github-light","dark":"one-dark-pro"}}
  result = client.translate.v1.translate(
      q="<p>The <strong>defendant</strong> denies all allegations.</p>",
      target="de",
      format="html"
  )

  print(result.data.translations[0].translated_text)
  # "<p>Der <strong>Beklagte</strong> bestreitet alle Anschuldigungen.</p>"
  ```

  ```go title="Go" theme={"theme":{"light":"github-light","dark":"one-dark-pro"}}
  result, _ := client.Translate.V1.Translate(ctx, casedev.TranslateV1TranslateParams{
  	Q:      casedev.F("<p>The <strong>defendant</strong> denies all allegations.</p>"),
  	Target: casedev.F("de"),
  	Format: casedev.F("html"),
  })
  fmt.Println(result.Data.Translations[0].TranslatedText)
  ```
</CodeGroup>

## Common language codes

| Language              | Code    |
| --------------------- | ------- |
| English               | `en`    |
| Spanish               | `es`    |
| French                | `fr`    |
| German                | `de`    |
| Chinese (Simplified)  | `zh`    |
| Chinese (Traditional) | `zh-TW` |
| Japanese              | `ja`    |
| Korean                | `ko`    |
| Arabic                | `ar`    |
| Portuguese            | `pt`    |
| Russian               | `ru`    |
| Italian               | `it`    |

<Info>
  See the [Supported Languages](/translation/languages) endpoint for a complete list.
</Info>

## Examples

### Translate a legal document

<CodeGroup>
  ```bash title="CLI" theme={"theme":{"light":"github-light","dark":"one-dark-pro"}}
  casedev translate:v1 translate \
    --q "NOTICE OF MOTION - PLEASE TAKE NOTICE that the undersigned..." \
    --target es
  ```

  ```typescript title="Typescript" theme={"theme":{"light":"github-light","dark":"one-dark-pro"}}
  const document = `
  NOTICE OF MOTION

  PLEASE TAKE NOTICE that the undersigned will move this Court
  at the Courthouse located at 100 Centre Street, New York, NY
  on the 15th day of January, 2025, at 9:30 a.m., for an order...
  `;

  const result = await client.translate.v1.translate({
    q: document,
    target: 'es'
  });
  ```

  ```python title="Python" theme={"theme":{"light":"github-light","dark":"one-dark-pro"}}
  document = """
  NOTICE OF MOTION

  PLEASE TAKE NOTICE that the undersigned will move this Court
  at the Courthouse located at 100 Centre Street, New York, NY
  on the 15th day of January, 2025, at 9:30 a.m., for an order...
  """

  result = client.translate.v1.translate(q=document, target='es')
  ```

  ```go title="Go" theme={"theme":{"light":"github-light","dark":"one-dark-pro"}}
  document := `
  NOTICE OF MOTION

  PLEASE TAKE NOTICE that the undersigned will move this Court
  at the Courthouse located at 100 Centre Street, New York, NY
  on the 15th day of January, 2025, at 9:30 a.m., for an order...
  `

  result, _ := client.Translate.V1.Translate(ctx, casedev.TranslateV1TranslateParams{
  	Q:      casedev.F(document),
  	Target: casedev.F("es"),
  })
  ```
</CodeGroup>

### Auto-detect source language

<CodeGroup>
  ```bash title="CLI" theme={"theme":{"light":"github-light","dark":"one-dark-pro"}}
  casedev translate:v1 translate \
    --q "Bonjour, comment puis-je vous aider?" \
    --target en
  ```

  ```typescript title="Typescript" theme={"theme":{"light":"github-light","dark":"one-dark-pro"}}
  // Source language is detected automatically
  const result = await client.translate.v1.translate({
    q: 'Bonjour, comment puis-je vous aider?',
    target: 'en'
  });

  console.log(result.data.translations[0].detectedSourceLanguage); // "fr"
  console.log(result.data.translations[0].translatedText); // "Hello, how can I help you?"
  ```

  ```python title="Python" theme={"theme":{"light":"github-light","dark":"one-dark-pro"}}
  # Source language is detected automatically
  result = client.translate.v1.translate(
      q='Bonjour, comment puis-je vous aider?',
      target='en'
  )

  print(result.data.translations[0].detected_source_language)  # "fr"
  print(result.data.translations[0].translated_text)  # "Hello, how can I help you?"
  ```

  ```go title="Go" theme={"theme":{"light":"github-light","dark":"one-dark-pro"}}
  // Source language is detected automatically
  result, _ := client.Translate.V1.Translate(ctx, casedev.TranslateV1TranslateParams{
  	Q:      casedev.F("Bonjour, comment puis-je vous aider?"),
  	Target: casedev.F("en"),
  })

  fmt.Println(result.Data.Translations[0].DetectedSourceLanguage) // "fr"
  fmt.Println(result.Data.Translations[0].TranslatedText)         // "Hello, how can I help you?"
  ```
</CodeGroup>

<Info>
  **Pricing:** \$0.05 per 1,000 characters. A 50,000 character document costs \$2.50.
</Info>
