Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
@@ -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": [
Expand Down
48 changes: 48 additions & 0 deletions inc/Smartling/ContentTypes/Elementor/Elements/Posts.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
<?php

namespace Smartling\ContentTypes\Elementor\Elements;

use Smartling\ContentTypes\ContentTypeHelper;
use Smartling\Models\Content;
use Smartling\Models\RelatedContentInfo;

class Posts extends Unknown
{
public function getType(): string
{
return 'posts';
}

public function getRelated(): RelatedContentInfo
{
$return = parent::getRelated();
$key = 'custom_skin_template';
$id = $this->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',
])];
}
}
5 changes: 4 additions & 1 deletion readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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
Comment on lines +65 to +66
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds like 5.4.0 - new functionality with no breaking bc.


= 5.3.5 =
* Added support for Elementor shortcode widget

Expand Down
2 changes: 1 addition & 1 deletion smartling-connector.php
Original file line number Diff line number Diff line change
Expand Up @@ -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+
Expand Down
128 changes: 128 additions & 0 deletions tests/Smartling/ContentTypes/Elementor/PostsTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
<?php

namespace Smartling\ContentTypes\Elementor;

use PHPUnit\Framework\TestCase;
use Smartling\ContentTypes\ContentTypeHelper;
use Smartling\ContentTypes\Elementor\Elements\Posts;
use Smartling\ContentTypes\ExternalContentElementor;
use Smartling\Models\RelatedContentInfo;
use Smartling\Submissions\SubmissionEntity;

class PostsTest extends TestCase
{
private function makeWidget(array $settings = []): Posts
{
return new Posts([
'id' => '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']);
}
}
16 changes: 15 additions & 1 deletion tests/Smartling/ContentTypes/ExternalContentElementorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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]],
],
];
}

Expand Down
Loading