---
name: watsonx-code-assistant-wca-translate-code
title: Translating code from one language to another
description: '[watsonx Code Assistant]'
last-updated: 2025-06-11
---

> ## Documentation Index
> The table of contents for this documentation set is at https://cloud.ibm.com/docs/watsonx-code-assistant?format=markdown
> The index for all IBM Cloud docs is at: https://cloud.ibm.com/docs/llms.txt
> Use these files to discover more information as needed.

# Translating code from one language to another
{: #wca-translate-code}

[watsonx Code Assistant]{: tag-blue}

Use the `/translate` command in the chat window to translate code from one language to the other.

## Chat syntax for translating code
{: #wca-translate-code-syntax}

The chat syntax is:
`/translate [from <source_language>] to <target_language> (<code reference> | <code snippet>) [additional instructions]`

- Make sure to start the prompt with `/translate`, followed by the rest of the syntax.

- `[from <source_language>]` is optional and is automatically detected if not specified in the command. It is recommended to specify the source language if the quality of the translation response is not good enough.

- `<target_language>` is required. Provide complete language names without spaces, such as `TypeScript` instead of Type Script or `JavaScript` instead of Java Script.

- `(<code reference> | <code snippet>)`: Along with a target language, you can include either a code reference or a code snippet. Use one reference or snippet at a time.

   - `<code reference>`: Refer to a file, method, or class name from active workspace by using an `@` symbol. For example:

      ```text
      /translate to java @get_metric_type
      ```

      When you reference a method, watsonx Code Assistant supports certain code languages. Referencing a full file works for all languages. For more information, see [Language support when you work with methods](https://cloud.ibm.com/docs/watsonx-code-assistant?topic=watsonx-code-assistant-wca-reference-methods-language&format=markdown).

      **Known issue** If you are using the watsonx Code Assistant for Enterprise Java Applications extension, upon startup it might take a few seconds for the enhanced Java capabilities to be available from the CodeLens.
{: note}

   - `<code snippet>`: Use a code snippet from your editor or paste a code snippet.
      
      To use code snippet from your editor:
      1. Highlight the code in the editor.
      1. Right click to show the pop-up menu.
      1. Choose **watsonx Code Assistant**.
      1. Choose **Add selected code to chat** to insert the code into the chat where you are starting the `/translate` command.

      To paste a code snippet:
      1. Find the code you want to translate.
      1. Paste the code into the chat where you are starting the `/translate` command.

- `[additional instructions]` are optional. 

   For example: `/translate to java @get_user_list Copy the comments from this function to the translated code`