Translation
TranslationClaude Translation

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
    )
  }
}

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)":

Setting Anthropic's API key
Setting Anthropic's API key

In wp-config.php

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)":

Setting the Claude model
Setting the Claude model

In wp-config.php

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)":

Setting the prompt for Claude
Setting the prompt for Claude

In wp-config.php

Add constant GATOGRAPHQL_CLAUDE_TRANSLATION_SERVICES_PROMPT_TEMPLATE in wp-config.php:

define( 'GATOGRAPHQL_CLAUDE_TRANSLATION_SERVICES_PROMPT_TEMPLATE', 'Please translate strings from {$sourceLang} to {$targetLang}' );

By environment variable

Define environment variable CLAUDE_TRANSLATION_SERVICES_PROMPT_TEMPLATE.