diff --git a/composer.json b/composer.json index 79b00bce..f71d6cbc 100644 --- a/composer.json +++ b/composer.json @@ -1,7 +1,7 @@ { "name": "smartling/wordpress-connector", "license": "GPL-2.0-or-later", - "version": "5.3.5", + "version": "5.3.6", "description": "", "type": "wordpress-plugin", "repositories": [ diff --git a/inc/Smartling/ContentTypes/Elementor/Elements/Posts.php b/inc/Smartling/ContentTypes/Elementor/Elements/Posts.php new file mode 100644 index 00000000..5731dc69 --- /dev/null +++ b/inc/Smartling/ContentTypes/Elementor/Elements/Posts.php @@ -0,0 +1,48 @@ +getIntSettingByKey($key, $this->settings); + if ($id !== null) { + $return->addContent(new Content($id, ContentTypeHelper::CONTENT_TYPE_UNKNOWN), $this->id, "settings/$key"); + } + + $key = 'posts_include_term_ids'; + foreach ($this->settings[$key] ?? [] as $index => $termId) { + if (is_numeric($termId)) { + $return->addContent(new Content((int)$termId, ContentTypeHelper::CONTENT_TYPE_TAXONOMY), $this->id, "settings/$key/$index"); + } + } + + return $return; + } + + public function getTranslatableStrings(): array + { + return [$this->id => $this->getTranslatableStringsByKeys([ + 'classic_read_more_text', + 'cards_read_more_text', + 'pagination_prev_label', + 'pagination_next_label', + 'text', + 'load_more_no_posts_custom_message', + 'loadmore_text', + 'loadmore_loading_text', + ])]; + } +} diff --git a/readme.txt b/readme.txt index f1249c80..985aa757 100755 --- a/readme.txt +++ b/readme.txt @@ -4,7 +4,7 @@ Tags: translation, localization, multilingual, internationalization, smartling Requires at least: 5.5 Tested up to: 6.9 Requires PHP: 8.0 -Stable tag: 5.3.5 +Stable tag: 5.3.6 License: GPLv2 or later Translate content in WordPress quickly and seamlessly with Smartling, the industry-leading Translation Management System. @@ -62,6 +62,9 @@ Additional information on the Smartling Connector for WordPress can be found [he 3. Track translation status within WordPress from the Submissions Board. View overall progress of submitted translation requests as well as resend updated content. == Changelog == += 5.3.6 = +* Added support for Elementor posts widget + = 5.3.5 = * Added support for Elementor shortcode widget diff --git a/smartling-connector.php b/smartling-connector.php index 7901779a..5821dd48 100755 --- a/smartling-connector.php +++ b/smartling-connector.php @@ -11,7 +11,7 @@ * Plugin Name: Smartling Connector * Plugin URI: https://www.smartling.com/products/automate/integrations/wordpress/ * Description: Integrate your WordPress site with Smartling to upload your content and download translations. - * Version: 5.3.5 + * Version: 5.3.6 * Author: Smartling * Author URI: https://www.smartling.com * License: GPL-2.0+ diff --git a/tests/Smartling/ContentTypes/Elementor/PostsTest.php b/tests/Smartling/ContentTypes/Elementor/PostsTest.php new file mode 100644 index 00000000..a0825f8d --- /dev/null +++ b/tests/Smartling/ContentTypes/Elementor/PostsTest.php @@ -0,0 +1,128 @@ + 'abc123', + 'elType' => 'widget', + 'widgetType' => 'posts', + 'settings' => $settings, + 'elements' => [], + ]); + } + + public function testGetType(): void + { + $this->assertEquals('posts', $this->makeWidget()->getType()); + } + + public function testGetTranslatableStrings(): void + { + $strings = $this->makeWidget([ + 'classic_read_more_text' => 'Read More »', + 'cards_read_more_text' => 'Read More »', + 'pagination_prev_label' => '« Previous', + 'pagination_next_label' => 'Next »', + 'text' => 'Load More', + 'load_more_no_posts_custom_message' => 'No more posts to show', + 'loadmore_text' => 'Load More', + 'loadmore_loading_text' => 'Loading...', + ])->getTranslatableStrings(); + + $this->assertEquals([ + 'classic_read_more_text' => 'Read More »', + 'cards_read_more_text' => 'Read More »', + 'pagination_prev_label' => '« Previous', + 'pagination_next_label' => 'Next »', + 'text' => 'Load More', + 'load_more_no_posts_custom_message' => 'No more posts to show', + 'loadmore_text' => 'Load More', + 'loadmore_loading_text' => 'Loading...', + ], $strings['abc123']); + } + + public function testGetTranslatableStringsEmpty(): void + { + $this->assertEquals([], $this->makeWidget()->getTranslatableStrings()['abc123']); + } + + public function testGetRelatedReturnsTemplateId(): void + { + $related = $this->makeWidget(['custom_skin_template' => '9165'])->getRelated(); + + $this->assertEquals( + [ContentTypeHelper::CONTENT_TYPE_UNKNOWN => [9165]], + $related->getRelatedContentList() + ); + } + + public function testGetRelatedNoTemplateReturnsEmpty(): void + { + $related = $this->makeWidget()->getRelated(); + + $this->assertEquals([], $related->getRelatedContentList()); + } + + public function testGetRelatedReturnsTermIds(): void + { + $related = $this->makeWidget(['posts_include_term_ids' => [42, 99]])->getRelated(); + + $this->assertEquals( + [ContentTypeHelper::CONTENT_TYPE_TAXONOMY => [42, 99]], + $related->getRelatedContentList() + ); + } + + public function testGetRelatedSkipsNonNumericTermIds(): void + { + $related = $this->makeWidget(['posts_include_term_ids' => ['invalid', 42]])->getRelated(); + + $this->assertEquals( + [ContentTypeHelper::CONTENT_TYPE_TAXONOMY => [42]], + $related->getRelatedContentList() + ); + } + + public function testGetRelatedReturnsBothTemplateAndTermIds(): void + { + $related = $this->makeWidget([ + 'custom_skin_template' => '9165', + 'posts_include_term_ids' => ["42", 99], + ])->getRelated(); + + $this->assertEquals( + [ + ContentTypeHelper::CONTENT_TYPE_UNKNOWN => [9165], + ContentTypeHelper::CONTENT_TYPE_TAXONOMY => [42, 99], + ], + $related->getRelatedContentList() + ); + } + + public function testSetTargetContent(): void + { + $result = $this->makeWidget([ + 'text' => 'Load More', + 'loadmore_loading_text' => 'Loading...', + ])->setTargetContent( + $this->createMock(ExternalContentElementor::class), + new RelatedContentInfo([]), + ['abc123' => ['text' => 'Cargar más', 'loadmore_loading_text' => 'Cargando...']], + $this->createMock(SubmissionEntity::class), + )->toArray(); + + $this->assertEquals('Cargar más', $result['settings']['text']); + $this->assertEquals('Cargando...', $result['settings']['loadmore_loading_text']); + } +} diff --git a/tests/Smartling/ContentTypes/ExternalContentElementorTest.php b/tests/Smartling/ContentTypes/ExternalContentElementorTest.php index e886da55..e091064f 100644 --- a/tests/Smartling/ContentTypes/ExternalContentElementorTest.php +++ b/tests/Smartling/ContentTypes/ExternalContentElementorTest.php @@ -354,7 +354,21 @@ public function extractElementorDataProvider(): array 13574, ] ], - ] + ], + 'posts widget' => [ + '[{"id":"7a0e323","elType":"widget","settings":{"_skin":"custom","classic_read_more_text":"Read More »","cards_read_more_text":"Read More »","custom_skin_template":"9165","pagination_prev_label":"« Previous","pagination_next_label":"Next »","text":"Load More","load_more_no_posts_custom_message":"No more posts to show","loadmore_text":"Load More","loadmore_loading_text":"Loading..."},"elements":[],"widgetType":"posts"}]', + [ + '7a0e323/classic_read_more_text' => 'Read More »', + '7a0e323/cards_read_more_text' => 'Read More »', + '7a0e323/pagination_prev_label' => '« Previous', + '7a0e323/pagination_next_label' => 'Next »', + '7a0e323/text' => 'Load More', + '7a0e323/load_more_no_posts_custom_message' => 'No more posts to show', + '7a0e323/loadmore_text' => 'Load More', + '7a0e323/loadmore_loading_text' => 'Loading...', + ], + [ContentTypeHelper::CONTENT_TYPE_UNKNOWN => [9165]], + ], ]; }