Translation
TranslationOpenRouter Translation

OpenRouter Translation

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

Description

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

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

OpenRouter Authorization

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

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

In wp-config.php

Add constant GATOGRAPHQL_OPENROUTER_SERVICES_OPENROUTER_API_KEY in wp-config.php:

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

By environment variable

Define environment variable OPENROUTER_SERVICES_OPENROUTER_API_KEY.

OpenRouter model

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

Models are fetched dynamically from the OpenRouter API, and updated daily.

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

In wp-config.php

Add constant GATOGRAPHQL_OPENROUTER_TRANSLATION_SERVICES_MODEL in wp-config.php:

define( 'GATOGRAPHQL_OPENROUTER_TRANSLATION_SERVICES_MODEL', 'codestral-latest' );

By environment variable

Define environment variable OPENROUTER_TRANSLATION_SERVICES_MODEL.

Translation prompt

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

In wp-config.php

Add constants GATOGRAPHQL_OPENROUTER_TRANSLATION_SERVICES_SYSTEM_MESSAGE and GATOGRAPHQL_OPENROUTER_TRANSLATION_SERVICES_PROMPT_TEMPLATE in wp-config.php:

define( 'GATOGRAPHQL_OPENROUTER_TRANSLATION_SERVICES_SYSTEM_MESSAGE', 'You are a helpful translator' );
define( 'GATOGRAPHQL_OPENROUTER_TRANSLATION_SERVICES_PROMPT_TEMPLATE', 'Please translate strings from {$sourceLang} to {$targetLang}' );

By environment variable

Define environment variables OPENROUTER_TRANSLATION_SERVICES_SYSTEM_MESSAGE and OPENROUTER_TRANSLATION_SERVICES_PROMPT_TEMPLATE.