Skip to content

Commit 257e7b5

Browse files
Release 1.2.10
1 parent 5b81ad9 commit 257e7b5

File tree

5 files changed

+40
-5
lines changed

5 files changed

+40
-5
lines changed

CHANGELOG.md

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

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

5+
## 1.2.10 - 2025-07-16
6+
### Fixed
7+
- Resolved an issue affecting the translation of `<img>` tags within CKEditor fields.
8+
- Fixed translation issues with Gaelic languages when using OpenAI.
9+
510
## 1.2.9 - 2025-06-17
611
### Fixed
712
- Resolved an issue where the bulk translation exclusions table was not created correctly on systems with `sql_require_primary_key` enabled.

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.9",
5+
"version": "1.2.10",
66
"keywords": [
77
"craftcms",
88
"content-buddy",

src/api/text/OpenAi.php

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,19 @@ public function sendRequest($prompt, $maxTokens, $temperature, $isTranslate = fa
4646
}
4747

4848
$choices = $json['choices'];
49+
$text = $this->getTextGenerationBasedOnModel( $model, $choices );
50+
51+
//check for repeated phrases
52+
if(in_array($lang,['gv','gd','ga'])) {
53+
$normalized = preg_replace('/[\p{P}]+/u', '', strtolower($text));
54+
$normalized = preg_replace('/\s+/', ' ', $normalized);
55+
if(preg_match_all('/(\b(?:\w+\s?){1,6})\s+(\1\s*){2,}/u', $normalized, $matches)) {
56+
Craft::info( 'OpenAI response contains repeated phrases: ' . implode(', ', $matches[0]), 'content-buddy');
57+
return $this->sendRequest($prompt, $maxTokens, $temperature, $isTranslate, $instructions, $lang);
58+
}
59+
}
4960

50-
return $this->getTextGenerationBasedOnModel( $model, $choices );
61+
return $text;
5162
}
5263

5364
private function buildTextGenerationRequestBody($model, $prompt, $maxTokensToGenerate, $temperature = 0.7, $isTranslate = false, $instructions = '') {

src/services/Request.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,8 @@ private function hasHtmlTags($text): bool {
5252

5353
private function getMinSentencesPerChunk($lang): int {
5454
return match ($lang) {
55-
'gv' => 3,
55+
'gv', 'gd', 'ga' => 3,
56+
'el' => 20,
5657
'nl-NL', 'nl', 'sl' => 100,
5758
default => 40,
5859
};

src/services/Translate.php

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -421,6 +421,7 @@ public function translateCategory(
421421
if ( $fieldType == 'craft\ckeditor\Field' ) {
422422
$fieldValue = $entry->getFieldValue( $fieldHandle );
423423
$entry_value = $fieldValue !== null ? $fieldValue->getRawContent() : $fieldValue;
424+
$entry_value = $this->fixAssets($entry_value);
424425
} else {
425426
$entry_value = $entry->getFieldValue( $fieldHandle );
426427
}
@@ -604,6 +605,7 @@ public function translateAsset(
604605
if ( $fieldType == 'craft\ckeditor\Field' ) {
605606
$fieldValue = $entry->getFieldValue( $fieldHandle );
606607
$entry_value = $fieldValue !== null ? $fieldValue->getRawContent() : $fieldValue;
608+
$entry_value = $this->fixAssets($entry_value);
607609
} else {
608610
$entry_value = $entry->getFieldValue( $fieldHandle );
609611
}
@@ -776,6 +778,7 @@ public function translateProduct(
776778
if ( $fieldType == 'craft\ckeditor\Field' ) {
777779
$fieldValue = $entry->getFieldValue( $fieldHandle );
778780
$entry_value = $fieldValue !== null ? $fieldValue->getRawContent() : $fieldValue;
781+
$entry_value = $this->fixAssets($entry_value);
779782
} else {
780783
$entry_value = $entry->getFieldValue( $fieldHandle );
781784
}
@@ -976,6 +979,7 @@ public function translateEntry(
976979
if ( $fieldType == 'craft\ckeditor\Field' ) {
977980
$fieldValue = $entry->getFieldValue( $fieldHandle );
978981
$entry_value = $fieldValue !== null ? $fieldValue->getRawContent() : $fieldValue;
982+
$entry_value = $this->fixAssets($entry_value);
979983
} else {
980984
$entry_value = $entry->getFieldValue( $fieldHandle );
981985
}
@@ -1150,7 +1154,7 @@ public function processMatrixFields( string $lang, Element $entry_from, int $tra
11501154
if ( in_array( $fieldType, static::$textFields ) && $processField && ! $or_entry ) {
11511155
if ( $fieldType == 'craft\ckeditor\Field' ) {
11521156
$fieldValue = $entry_from->getFieldValue( $field->handle );
1153-
$originalFieldValue = $field->serializeValue( $fieldValue !== null ? $fieldValue->getRawContent() : $fieldValue, $entry_from );
1157+
$originalFieldValue = $field->serializeValue( $fieldValue !== null ? $this->fixAssets($fieldValue->getRawContent()) : $fieldValue, $entry_from );
11541158
} else {
11551159
$originalFieldValue = $field->serializeValue( $entry_from->getFieldValue( $field->handle ), $entry_from );
11561160
}
@@ -1866,6 +1870,16 @@ private function getHtmlTags( $text ): array {
18661870
return array_unique( $matches[1] );
18671871
}
18681872

1873+
private function fixAssets($text): string {
1874+
return preg_replace_callback(
1875+
'/\{asset:\d+:url\|\|(.*?)\}/',
1876+
function($matches) {
1877+
return $matches[1];
1878+
},
1879+
$text
1880+
);
1881+
}
1882+
18691883
private function saveElement( $element ): bool {
18701884
/** @var SettingsModel $settings */
18711885
$settings = BuddyPlugin::getInstance()->getSettings();
@@ -1905,7 +1919,11 @@ public static function isCommerceInstalled(): bool {
19051919
}
19061920

19071921
public function saveExcludeBulkSites( $element ): void {
1908-
$params = Craft::$app->request->post();
1922+
$request = Craft::$app->getRequest();
1923+
if(!($request instanceof \craft\web\Request)) {
1924+
return;
1925+
}
1926+
$params = $request->post();
19091927
if(isset($params['elementId']) && $params['elementId'] == $element->id) {
19101928
Craft::info( 'saveExcludeBulkSites', 'content-buddy' );
19111929
Craft::info( $params, 'content-buddy' );

0 commit comments

Comments
 (0)