Claude Translation
Use Claude as a translation provider into directive @strTranslate
, to translate a field value to your desired language.
Description
Make Claude's API available as a translation provider in directive @strTranslate
.
Add directive @strTranslate
to any field of type String
, to translate it to the desired language.
For instance, this query translates the post's title
and content
fields from English to French using the Claude API:
{
posts {
title @strTranslate(
from: "en",
to: "fr",
provider: claude
)
content @strTranslate(
from: "en",
to: "fr",
provider: claude
)
}
}
Limitations
Claude is not meant to be used for long translations: Each string to translate cannot be longer than 8000. (Otherwise, it would surpass the 8192
limit of max tokens for the supported models.)
In addition, the rate limits in Anthropic are (by default) restrictive. When translating multiple strings in a limited span of time, the request may return a 429 Too Many Requests
rate limit error, with message:
This request would exceed your organization’s rate limit of 10,000 output tokens per minute. For details, refer to: https://docs.anthropic.com/en/api/rate-limits; see the response headers for current usage. Please reduce the prompt length or the maximum tokens requested, or try again later. You may also contact sales at https://www.anthropic.com/contact-sales to discuss your options for a rate limit increase.
Anthropic Authorization
In order to use Claude, it is mandatory to provide your Anthropic API key, via tab "Plugin Management => Claude Translation" on the Settings page.
Create the API key in your Anthropic's account.
Then follow one of the methods below to input the value.
By Settings
Input the API key in the corresponding inputs in the Settings page, and click on "Save Changes (All)":

wp-config.php
In
Add constant GATOGRAPHQL_CLAUDE_TRANSLATION_SERVICES_ANTHROPIC_API_KEY
in wp-config.php
:
define( 'GATOGRAPHQL_CLAUDE_TRANSLATION_SERVICES_ANTHROPIC_API_KEY', '{your API key}' );
By environment variable
Define environment variable CLAUDE_TRANSLATION_SERVICES_ANTHROPIC_API_KEY
.
Claude model
You can customize which Claude model to use to execute the translation.
The following models are supported:
claude-3-5-sonnet-latest
claude-3-5-haiku-latest
Follow one of the methods below to input the value.
By Settings
Input the model in the corresponding input in the Settings page, and click on "Save Changes (All)":

wp-config.php
In
Add constant GATOGRAPHQL_CLAUDE_TRANSLATION_SERVICES_MODEL
in wp-config.php
:
define( 'GATOGRAPHQL_CLAUDE_TRANSLATION_SERVICES_MODEL', 'claude-3-5-haiku-latest' );
By environment variable
Define environment variable CLAUDE_TRANSLATION_SERVICES_MODEL
.
Translation prompt
You can customize the prompt to pass Claude to execute the translation.
Follow one of the methods below to input the value.
By Settings
Input the "System message" and "Prompt template" in the corresponding inputs in the Settings page, and click on "Save Changes (All)":

wp-config.php
In
Add constant GATOGRAPHQL_CLAUDE_TRANSLATION_SERVICES_PROMPT_TEMPLATE
in wp-config.php
:
define( 'GATOGRAPHQL_CLAUDE_TRANSLATION_SERVICES_PROMPT_TEMPLATE', 'Please translate JSON {$encodedContentItems} from {$sourceLang} to {$targetLang}' );
By environment variable
Define environment variable CLAUDE_TRANSLATION_SERVICES_PROMPT_TEMPLATE
.