Skip to content

Commit 76a34e6

Browse files
Release 1.2.4
1 parent b25ae2e commit 76a34e6

File tree

7 files changed

+63
-20
lines changed

7 files changed

+63
-20
lines changed

CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,13 @@
22

33
All notable changes to this project will be documented in this file.
44

5+
## 1.2.4 - 2025-03-19
6+
### Changed
7+
- Allow selecting different API versions for DeepL.
8+
9+
### Fixed
10+
- Fixed an issue with translating nested entries in CKEditor fields.
11+
512
## 1.2.3 - 2025-03-18
613
### Fixed
714
- Fixed an issue with DeepL Pro API keys.

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "convergine/craft-content-buddy",
33
"description": "Content Buddy is an AI-driven CraftCMS plugin that leverages the ChatGPT API to automatically generate and manage multi-language content, including text and images, with customizable settings and features for precise control and enhanced content creation.",
44
"type": "craft-plugin",
5-
"version": "1.2.3",
5+
"version": "1.2.4",
66
"keywords": [
77
"craftcms",
88
"content-buddy",

src/api/text/DeepL.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,12 @@ public function sendRequest($prompt, $maxTokens, $temperature, $isTranslate = fa
5858

5959
private function getEndpoint() : string {
6060
$api_key = $this->settings->getDeepLApiKey();
61-
return str_ends_with($api_key,':fx') ? "https://api-free.deepl.com/v2/translate" : "https://api.deepl.com/v2/translate";
61+
$api_version = $this->settings->getDeepLApiVersion();
62+
if($api_version == 'v1') {
63+
return "https://api.deepl.com/v1/translate";
64+
} else {
65+
return str_ends_with($api_key,':fx') ? "https://api-free.deepl.com/".$api_version."/translate" : "https://api.deepl.com/".$api_version."/translate";
66+
}
6267
}
6368

6469
private function _getTextGeneration($result) : string {

src/models/SettingsModel.php

Lines changed: 23 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,16 @@ class SettingsModel extends Model
3333
*/
3434
public string $preferredTranslationModel = 'gpt-3.5-turbo';
3535

36-
/**
37-
* @var string
38-
*/
39-
public string $deepLApiKey = '';
36+
/**
37+
* @var string
38+
*/
39+
public string $deepLApiKey = '';
40+
41+
/**
42+
* @var string
43+
*/
44+
public string $deepLApiVersion = 'v2';
45+
4046
/**
4147
* @var string
4248
*/
@@ -156,12 +162,19 @@ public function getXAiApiKey(): string {
156162
return App::parseEnv($this->xAiApiKey);
157163
}
158164

159-
/**
160-
* @return string
161-
*/
162-
public function getDeepLApiKey(): string {
163-
return App::parseEnv($this->deepLApiKey);
164-
}
165+
/**
166+
* @return string
167+
*/
168+
public function getDeepLApiKey(): string {
169+
return App::parseEnv($this->deepLApiKey);
170+
}
171+
172+
/**
173+
* @return string
174+
*/
175+
public function getDeepLApiVersion(): string {
176+
return $this->deepLApiVersion;
177+
}
165178

166179
/**
167180
* @return string

src/services/Translate.php

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -702,11 +702,19 @@ public function translateEntry(
702702
}
703703

704704
if ( $_entry ) {
705-
$prompt = "Translate to {$lang}";
706-
if ( $instructions ) {
707-
$prompt .= ", {$instructions},";
705+
706+
$prompt = "Translate to $lang";
707+
if($instructions) {
708+
$prompt .= ", $instructions,";
708709
}
709710
$prompt .= " following text";
711+
712+
$prompt_ckeditor = "Translate to $lang. Do not translate or remove any <craft-entry> tags";
713+
if($instructions) {
714+
$prompt_ckeditor .= ", $instructions,";
715+
}
716+
$prompt_ckeditor .= " following text";
717+
710718
try {
711719
$translated_text = BuddyPlugin::getInstance()->request
712720
->send( $prompt . ": {$entry->title}", 30000, 0.7, true,$lang );
@@ -751,17 +759,16 @@ public function translateEntry(
751759
}
752760

753761
try {
754-
$translated_text = BuddyPlugin::getInstance()
755-
->request->send( $prompt . ": {$entry_value}", 30000, 0.7, true,$lang );
762+
$translated_text = BuddyPlugin::getInstance()->request->send( ($fieldType == 'craft\ckeditor\Field' ? $prompt_ckeditor : $prompt) . ": {$entry_value}", 30000, 0.7, true, $lang);
756763

757-
Craft::info( $prompt . ": {$entry_value}", 'content-buddy' );
758-
Craft::info( $fieldHandle, 'content-buddy' );
764+
Craft::info( ($fieldType == 'craft\ckeditor\Field' ? $prompt_ckeditor : $prompt) . ": {$entry_value}", 'content-buddy' );
765+
Craft::info( $fieldHandle . '(' . $fieldType . ')', 'content-buddy' );
759766
Craft::info( $translated_text, 'content-buddy' );
760767
$translated_text = trim( $translated_text, '```html' );
761768
$translated_text = rtrim( $translated_text, '```' );
762769

763770
if($fieldType == 'craft\ckeditor\Field') {
764-
$translated_text = $this->translateEntriesInCKEditorField($translated_text,$translate_to_site,$prompt);
771+
$translated_text = $this->translateEntriesInCKEditorField($translated_text,$translate_to_site,$prompt_ckeditor);
765772
Craft::info('New CKEditor translated text: '.$translated_text, 'content-buddy');
766773
}
767774

src/templates/settings/_translation.twig

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,16 @@
7474
</div>
7575

7676
<div id="deepl" class="{% if settings.translationAi != 'deepl' %}hidden{% endif %}">
77+
{{ forms.selectField({
78+
label: 'DeepL API Version'|t('convergine-contentbuddy'),
79+
name: 'deepLApiVersion',
80+
value: settings.deepLApiVersion,
81+
instructions: 'deepLApiVersionDescription'|t('convergine-contentbuddy'),
82+
options: {
83+
"v2": "v2",
84+
"v1": "v1",
85+
}
86+
}) }}
7787

7888
{{ forms.autosuggestField({
7989
label: 'DeepL API Key'|t('convergine-contentbuddy'),

src/translations/en/convergine-contentbuddy.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
'delaySectionDescription' => 'During bulk translations, the plugin will add a delay of this amount of seconds for every extra section.',
2626
'maxAttemptsDescription' => 'The maximum number of attempts to try when saving an entry during translation. This is only an issue if another task or user is editing the same entry at the same time.',
2727
'ttrDescription' => 'The maximum time a translation task should wait around for the job to be handled before assuming it failed.',
28+
'deepLApiVersionDescription' => 'API version to use. For more information, see https://developers.deepl.com/docs/getting-started/auth#api-versions',
2829

2930
/* Settings -> Api Page */
3031
'API: Access Token'=>'API: Access Token',

0 commit comments

Comments
 (0)