This commit is contained in:
2026-09-15 10:35:56 +08:00
commit 782f8ea7aa
4086 changed files with 631288 additions and 0 deletions
@@ -0,0 +1,44 @@
<?php
declare(strict_types=1);
namespace Esun\Translation\Plugin\Adminhtml;
use Esun\Translation\Model\Config;
use Magento\Cms\Ui\Component\Listing\Column\BlockActions;
use Magento\Framework\UrlInterface;
class AddCmsBlockRowTranslateAction
{
public function __construct(
private readonly Config $config,
private readonly UrlInterface $urlBuilder
) {
}
public function afterPrepareDataSource(BlockActions $subject, array $dataSource): array
{
if (!$this->config->isEnabled() || empty($dataSource['data']['items'])) {
return $dataSource;
}
$columnName = (string)$subject->getData('name');
foreach ($dataSource['data']['items'] as &$item) {
if (empty($item['block_id'])) {
continue;
}
$item[$columnName]['translate'] = [
'href' => $this->urlBuilder->getUrl(
'esun_translation/translate/index',
['entity_type' => 'cms_block', 'entity_id' => (int)$item['block_id']]
),
'ariaLabel' => __('Translate ') . ($item['title'] ?? ''),
'label' => __('Translate'),
'hidden' => false,
];
}
return $dataSource;
}
}
@@ -0,0 +1,44 @@
<?php
declare(strict_types=1);
namespace Esun\Translation\Plugin\Adminhtml;
use Esun\Translation\Model\Config;
use Magento\Cms\Ui\Component\Listing\Column\PageActions;
use Magento\Framework\UrlInterface;
class AddCmsPageRowTranslateAction
{
public function __construct(
private readonly Config $config,
private readonly UrlInterface $urlBuilder
) {
}
public function afterPrepareDataSource(PageActions $subject, array $dataSource): array
{
if (!$this->config->isEnabled() || empty($dataSource['data']['items'])) {
return $dataSource;
}
$columnName = (string)$subject->getData('name');
foreach ($dataSource['data']['items'] as &$item) {
if (empty($item['page_id'])) {
continue;
}
$item[$columnName]['translate'] = [
'href' => $this->urlBuilder->getUrl(
'esun_translation/translate/index',
['entity_type' => 'cms_page', 'entity_id' => (int)$item['page_id']]
),
'ariaLabel' => __('Translate ') . ($item['title'] ?? ''),
'label' => __('Translate'),
'hidden' => false,
];
}
return $dataSource;
}
}
@@ -0,0 +1,74 @@
<?php
declare(strict_types=1);
namespace Esun\Translation\Plugin\Adminhtml;
use Esun\Translation\Model\Config;
use Magento\Catalog\Block\Adminhtml\Product as ProductListBlock;
use Magento\Framework\View\LayoutInterface;
class AddProductListTranslateButton
{
public function __construct(private readonly Config $config)
{
}
public function beforeSetLayout(ProductListBlock $subject, LayoutInterface $layout): array
{
if (!$this->config->isEnabled()) {
return [$layout];
}
$url = $subject->getUrl('esun_translation/translate/index', ['entity_type' => 'product']);
$message = __('Select exactly one product to translate.');
$subject->addButton(
'Esun_Translation_translate',
[
'label' => __('Translate'),
'class' => 'action-secondary',
'onclick' => sprintf(
<<<'JS'
(function () {
require(['uiRegistry', 'Magento_Ui/js/modal/alert'], function (registry, alert) {
var selections = null;
registry.get(function (component) {
if (!selections
&& component
&& component.name
&& component.name.indexOf('product_listing') === 0
&& component.name.indexOf('.ids') !== -1
&& typeof component.selected === 'function'
) {
selections = component;
}
});
var selected = selections ? selections.selected() : [];
var excluded = selections && typeof selections.excluded === 'function' ? selections.excluded() : [];
if (excluded === false || selected.length !== 1) {
alert({
title: '%s',
content: '%s'
});
return;
}
setLocation('%sentity_id/' + selected[0] + '/');
});
}())
JS,
(string)__('Esun Translation'),
(string)$message,
$url
),
],
0,
35
);
return [$layout];
}
}
@@ -0,0 +1,44 @@
<?php
declare(strict_types=1);
namespace Esun\Translation\Plugin\Adminhtml;
use Esun\Translation\Model\Config;
use Magento\Catalog\Ui\Component\Listing\Columns\ProductActions;
use Magento\Framework\UrlInterface;
class AddProductRowTranslateAction
{
public function __construct(
private readonly Config $config,
private readonly UrlInterface $urlBuilder
) {
}
public function afterPrepareDataSource(ProductActions $subject, array $dataSource): array
{
if (!$this->config->isEnabled() || empty($dataSource['data']['items'])) {
return $dataSource;
}
$columnName = (string)$subject->getData('name');
foreach ($dataSource['data']['items'] as &$item) {
if (empty($item['entity_id'])) {
continue;
}
$item[$columnName]['translate'] = [
'href' => $this->urlBuilder->getUrl(
'esun_translation/translate/index',
['entity_type' => 'product', 'entity_id' => (int)$item['entity_id']]
),
'ariaLabel' => __('Translate ') . ($item['name'] ?? ''),
'label' => __('Translate'),
'hidden' => false,
];
}
return $dataSource;
}
}