Translation
TranslationChatGPT Translation

ChatGPT Translation

Use ChatGPT as a translation provider into directive @strTranslate, to translate a field value to your desired language.

Description

Make ChatGPT'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 ChatGPT API:

{
  posts {
    title @strTranslate(
      from: "en",
      to: "fr",
      provider: chatgpt
    )
    
    content @strTranslate(
      from: "en",
      to: "fr",
      provider: chatgpt
    )
  }
}

OpenAI Authorization

In order to use ChatGPT, it is mandatory to provide your OpenAI API key, via tab "Plugin Management => ChatGPT Translation" on the Settings page.

Create the API key in your OpenAI'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 OpenAI's API key
Setting OpenAI's API key

In wp-config.php

Add constant GATOGRAPHQL_CHATGPT_TRANSLATION_SERVICES_OPENAI_API_KEY in wp-config.php:

define( 'GATOGRAPHQL_CHATGPT_TRANSLATION_SERVICES_OPENAI_API_KEY', '{your API key}' );

By environment variable

Define environment variable CHATGPT_TRANSLATION_SERVICES_OPENAI_API_KEY.

ChatGPT model

You can customize which OpenAI model to use to execute the translation.

The following models are supported:

  • gpt-40
  • gpt-40-mini

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 OpenAI model
Setting the OpenAI model

In wp-config.php

Add constant GATOGRAPHQL_CHATGPT_TRANSLATION_SERVICES_MODEL in wp-config.php:

define( 'GATOGRAPHQL_CHATGPT_TRANSLATION_SERVICES_MODEL', 'gpt-40-mini' );

By environment variable

Define environment variable CHATGPT_TRANSLATION_SERVICES_MODEL.

Translation prompt

You can customize the prompt to pass ChatGPT 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 ChatGPT
Setting the prompt for ChatGPT

In wp-config.php

Add constants GATOGRAPHQL_CHATGPT_TRANSLATION_SERVICES_SYSTEM_MESSAGE and GATOGRAPHQL_CHATGPT_TRANSLATION_SERVICES_PROMPT_TEMPLATE in wp-config.php:

define( 'GATOGRAPHQL_CHATGPT_TRANSLATION_SERVICES_SYSTEM_MESSAGE', 'You are a helpful translator' );
define( 'GATOGRAPHQL_CHATGPT_TRANSLATION_SERVICES_PROMPT_TEMPLATE', 'Please translate JSON {$encodedContentItems} from {$sourceLang} to {$targetLang}' );

By environment variable

Define environment variables CHATGPT_TRANSLATION_SERVICES_SYSTEM_MESSAGE and CHATGPT_TRANSLATION_SERVICES_PROMPT_TEMPLATE.