Problem/Motivation

Gemini seems really great on keeping the style also on translations. Rather use it.

Proposed resolution

Solution in merge code to follow.
Note: this integrates and solves #3502139: Gemini API error with empty stopSequences value
Gemini does not offer (yet) a specialized translateText method like DeepL does, so the chat method used by ai_translate can be used. Maybe this is superfluous, nonetheless it was a good exercise and Gemini can now be used with:

$translator = \Drupal::service('ai.provider')->createInstance('gemini');
$input = new TranslateTextInput($text, 'en', 'it');
/** @var \Drupal\ai\OperationType\TranslateText\TranslateTextOutput $translation */
$translation = $translator->translateText($input, 'models/gemini-1.5-pro', []);
return $translation->getNormalized();

or if set as default in AI settings with:

$providerConfig = $this->aiProviderManager->getDefaultProviderForOperationType('translate_text');
$provider = $this->aiProviderManager->createInstance($providerConfig['provider_id'], $providerConfig);
$translation = $provider->translateText(
  new TranslateTextInput($input_text, $langFrom?->getId(), $langTo->getId()),
  $providerConfig['model_id']
);

Remaining tasks

Add tests?

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

viappidu created an issue. See original summary.

viappidu’s picture

Status: Active » Needs review
StatusFileSize
new5.19 KB

Patch for composer

viappidu’s picture

StatusFileSize
new4.65 KB

Patch for composer

jibla’s picture

jibla’s picture

Status: Needs review » Closed (won't fix)

Closing as duplicate/won't fix.

After reviewing this issue against the current state of the module (1.x branch), this feature request is no longer needed.

1. The AI module's ai_translate submodule already provides translation support for all chat-capable providers, including Gemini.

2. The stopSequences fix (referenced issue #3502139: Gemini API error with empty stopSequences value) has already been resolved on the 1.x branch.

Thank you @viappidu for the contribution effort.

Now that this issue is closed, review the contribution record.

As a contributor, attribute any organization that helped you, or if you volunteered your own time.

Maintainers, credit people who helped resolve this issue.