| copyright |
|
||
|---|---|---|---|
| lastupdated | 2025-06-11 | ||
| keywords | |||
| subcollection | watsonx-code-assistant |
{{site.data.keyword.attribute-definition-list}}
{: #wca-translate-code}
[{{site.data.keyword.wca_short}}]{: tag-blue}
Use the /translate command in the chat window to translate code from one language to the other.
{: #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 asTypeScriptinstead of Type Script orJavaScriptinstead 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:/translate to java @get_metric_typeWhen you reference a method, {{site.data.keyword.wca_short}} supports certain code languages. Referencing a full file works for all languages. For more information, see Language support when you work with methods.
{{site.data.content.reference-file-size-limit}}
-
<code snippet>: Use a code snippet from your editor or paste a code snippet.To use code snippet from your editor:
- Highlight the code in the editor.
- Right click to show the pop-up menu.
- Choose {{site.data.keyword.wca_short}}.
- Choose Add selected code to chat to insert the code into the chat where you are starting the
/translatecommand.
To paste a code snippet:
- Find the code you want to translate.
- Paste the code into the chat where you are starting the
/translatecommand.
-
-
[additional instructions]are optional.For example:
/translate to java @get_user_list Copy the comments from this function to the translated code