Hello and thanks for the efforts with this module!

I'm using the dev version of the module and after the changes made in this issue https://www.drupal.org/project/ai_provider_deepl/issues/3553315 I'm getting an error when trying to translate any text with DeepL.

The translation failed and the service returned the following error: DeepL\LanguageCode::removeRegionalVariant(): Argument #1 ($langCode) must be of type string, null given, called in /var/www/html/web/modules/contrib/ai_provider_deepl/src/Plugin/AiProvider/DeepLProvider.php on line 135 

I don't know why, but sometimes the source language can be null, and it causes the problem here:
$sourceLanguage = LanguageCode::removeRegionalVariant($input->getSourceLanguage());

removeRegionalVariant() method seems to come from DeepL php library so I don't think we can change it. But maybe we could add some checking in translateText() of ai_provider_deepl module instead?

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

hartsak created an issue. See original summary.

hartsak’s picture

Status: Active » Needs review

I tried to add some kind of solution in my merge request in branch 3557140-error-when-source-langcode-is-null. Please have a look at it! Thanks!

(And sorry, I think I accidentally somehow created another branch 3557140-error-translating-when but I couldn't delete it. So I think it can be ignored...)

hartsak changed the visibility of the branch 3557140-error-translating-when to hidden.

jhuhta’s picture

Looks good, merging. Thanks!

  • d2c37518 committed on 1.0.x
    Issue #3557140 Avoid errors when source language is null
    
jhuhta’s picture

Status: Needs review » Fixed

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.

hartsak’s picture

That was fast, thanks a lot @jhuhta!

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.