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,53 @@
<?php
declare(strict_types=1);
namespace Esun\MultiLocaleTranslation\Block\Adminhtml\Category\Edit\Button;
use Magento\Catalog\Block\Adminhtml\Category\AbstractCategory;
use Magento\Framework\View\Element\UiComponent\Control\ButtonProviderInterface;
class Translate extends AbstractCategory implements ButtonProviderInterface
{
private function getCurrentStoreFromRequest(): int
{
$store = (int)$this->getRequest()->getParam('store', 0);
if ($store <= 0) {
$store = (int)$this->getRequest()->getParam('store_id', 0);
}
return $store > 0 ? $store : 0;
}
public function getButtonData(): array
{
$category = $this->getCategory();
if (!$category || !$category->getId()) {
return [];
}
$config = [
'entityType' => 'category',
'entityId' => (int)$category->getId(),
'sourceStoreId' => $this->getCurrentStoreFromRequest(),
'storesUrl' => $this->getUrl('localetranslate/translation/stores'),
'fieldsUrl' => $this->getUrl('localetranslate/translation/fields'),
'applyUrl' => $this->getUrl('localetranslate/translation/apply'),
'autoTranslateUrl' => $this->getUrl('localetranslate/translation/autotranslate'),
];
$configJson = (string)json_encode(
$config,
JSON_HEX_TAG | JSON_HEX_AMP | JSON_HEX_APOS | JSON_HEX_QUOT
);
return [
'label' => __('Translate'),
'class' => 'action-secondary',
'on_click' => sprintf(
"require(['Esun_MultiLocaleTranslation/js/translate-modal'], function (openModal) { openModal(%s); });",
$configJson
),
'sort_order' => 35,
];
}
}
@@ -0,0 +1,51 @@
<?php
declare(strict_types=1);
namespace Esun\MultiLocaleTranslation\Block\Adminhtml\Cms\Block\Edit\Button;
use Magento\Framework\View\Element\UiComponent\Control\ButtonProviderInterface;
class Translate extends \Magento\Backend\Block\Widget\Container implements ButtonProviderInterface
{
private function getCurrentStoreFromRequest(): int
{
$store = (int)$this->getRequest()->getParam('store', 0);
if ($store <= 0) {
$store = (int)$this->getRequest()->getParam('store_id', 0);
}
return $store > 0 ? $store : 0;
}
public function getButtonData(): array
{
$blockId = (int)$this->getRequest()->getParam('block_id');
if ($blockId <= 0) {
return [];
}
$config = [
'entityType' => 'cms_block',
'entityId' => $blockId,
'sourceStoreId' => $this->getCurrentStoreFromRequest(),
'storesUrl' => $this->getUrl('localetranslate/translation/stores'),
'fieldsUrl' => $this->getUrl('localetranslate/translation/fields'),
'applyUrl' => $this->getUrl('localetranslate/translation/apply'),
'autoTranslateUrl' => $this->getUrl('localetranslate/translation/autotranslate'),
];
$configJson = (string)json_encode(
$config,
JSON_HEX_TAG | JSON_HEX_AMP | JSON_HEX_APOS | JSON_HEX_QUOT
);
return [
'label' => __('Translate'),
'class' => 'action-secondary',
'on_click' => sprintf(
"require(['Esun_MultiLocaleTranslation/js/translate-modal'], function (openModal) { openModal(%s); });",
$configJson
),
'sort_order' => 30,
];
}
}
@@ -0,0 +1,51 @@
<?php
declare(strict_types=1);
namespace Esun\MultiLocaleTranslation\Block\Adminhtml\Cms\Page\Edit\Button;
use Magento\Framework\View\Element\UiComponent\Control\ButtonProviderInterface;
class Translate extends \Magento\Backend\Block\Widget\Container implements ButtonProviderInterface
{
private function getCurrentStoreFromRequest(): int
{
$store = (int)$this->getRequest()->getParam('store', 0);
if ($store <= 0) {
$store = (int)$this->getRequest()->getParam('store_id', 0);
}
return $store > 0 ? $store : 0;
}
public function getButtonData(): array
{
$pageId = (int)$this->getRequest()->getParam('page_id');
if ($pageId <= 0) {
return [];
}
$config = [
'entityType' => 'cms_page',
'entityId' => $pageId,
'sourceStoreId' => $this->getCurrentStoreFromRequest(),
'storesUrl' => $this->getUrl('localetranslate/translation/stores'),
'fieldsUrl' => $this->getUrl('localetranslate/translation/fields'),
'applyUrl' => $this->getUrl('localetranslate/translation/apply'),
'autoTranslateUrl' => $this->getUrl('localetranslate/translation/autotranslate'),
];
$configJson = (string)json_encode(
$config,
JSON_HEX_TAG | JSON_HEX_AMP | JSON_HEX_APOS | JSON_HEX_QUOT
);
return [
'label' => __('Translate'),
'class' => 'action-secondary',
'on_click' => sprintf(
"require(['Esun_MultiLocaleTranslation/js/translate-modal'], function (openModal) { openModal(%s); });",
$configJson
),
'sort_order' => 30,
];
}
}
@@ -0,0 +1,33 @@
<?php
declare(strict_types=1);
namespace Esun\MultiLocaleTranslation\Block\Adminhtml\Log;
use Magento\Backend\Block\Widget\Context;
use Magento\Framework\View\Element\UiComponent\Control\ButtonProviderInterface;
class ClearAllButton implements ButtonProviderInterface
{
public function __construct(private readonly Context $context)
{
}
public function getButtonData(): array
{
$message = __('Clear all Translation API Log records? This action cannot be undone.');
$url = $this->context->getUrlBuilder()->getUrl('localetranslate/log/clearAll');
return [
'label' => __('Clear All Logs'),
'class' => 'delete',
'on_click' => 'deleteConfirm('
. json_encode((string)$message, JSON_HEX_APOS | JSON_HEX_QUOT)
. ', '
. json_encode($url, JSON_HEX_APOS | JSON_HEX_QUOT)
. ', {"data": {}})',
'sort_order' => 10,
'aclResource' => 'Esun_MultiLocaleTranslation::translation_log_delete',
];
}
}
@@ -0,0 +1,48 @@
<?php
declare(strict_types=1);
namespace Esun\MultiLocaleTranslation\Block\Adminhtml\Product\Edit\Button;
use Magento\Catalog\Block\Adminhtml\Product\Edit\Button\Generic;
class Translate extends Generic
{
private function getCurrentStoreFromRequest(): int
{
$store = (int)$this->context->getRequestParam('store', 0);
return $store > 0 ? $store : 0;
}
public function getButtonData(): array
{
$product = $this->getProduct();
if (!$product || !$product->getId()) {
return [];
}
$config = [
'entityType' => 'product',
'entityId' => (int)$product->getId(),
'sourceStoreId' => $this->getCurrentStoreFromRequest(),
'storesUrl' => $this->getUrl('localetranslate/translation/stores'),
'fieldsUrl' => $this->getUrl('localetranslate/translation/fields'),
'applyUrl' => $this->getUrl('localetranslate/translation/apply'),
'autoTranslateUrl' => $this->getUrl('localetranslate/translation/autotranslate'),
];
$configJson = (string)json_encode(
$config,
JSON_HEX_TAG | JSON_HEX_AMP | JSON_HEX_APOS | JSON_HEX_QUOT
);
return [
'label' => __('Translate'),
'class' => 'action-secondary',
'on_click' => sprintf(
"require(['Esun_MultiLocaleTranslation/js/translate-modal'], function (openModal) { openModal(%s); });",
$configJson
),
'sort_order' => 35,
];
}
}
@@ -0,0 +1,35 @@
<?php
declare(strict_types=1);
namespace Esun\MultiLocaleTranslation\Block\Adminhtml\Queue;
use Magento\Backend\Block\Widget\Context;
use Magento\Framework\View\Element\UiComponent\Control\ButtonProviderInterface;
class ClearAllButton implements ButtonProviderInterface
{
public function __construct(private readonly Context $context)
{
}
public function getButtonData(): array
{
$message = __(
'Clear all translation queue records? Pending jobs will be removed. A job already being processed may still finish and write its translation.'
);
$url = $this->context->getUrlBuilder()->getUrl('localetranslate/queue/clearAll');
return [
'label' => __('Clear All Queue'),
'class' => 'delete',
'on_click' => 'deleteConfirm('
. json_encode((string)$message, JSON_HEX_APOS | JSON_HEX_QUOT)
. ', '
. json_encode($url, JSON_HEX_APOS | JSON_HEX_QUOT)
. ', {"data": {}})',
'sort_order' => 10,
'aclResource' => 'Esun_MultiLocaleTranslation::queue_delete',
];
}
}
@@ -0,0 +1,66 @@
<?php
declare(strict_types=1);
namespace Esun\MultiLocaleTranslation\Block\Adminhtml\Queue;
use Esun\MultiLocaleTranslation\Model\ProviderConfig;
use Esun\MultiLocaleTranslation\Model\Queue\SelectionRegistry;
use Esun\MultiLocaleTranslation\Model\StoreViewProvider;
use Magento\Backend\Block\Template;
use Magento\Backend\Block\Template\Context;
use Magento\Framework\Data\Form\FormKey;
class Form extends Template
{
public function __construct(
Context $context,
private readonly StoreViewProvider $storeViewProvider,
private readonly ProviderConfig $providerConfig,
private readonly SelectionRegistry $selectionRegistry,
private readonly FormKey $formKeyService,
array $data = []
) {
parent::__construct($context, $data);
}
public function getSelection(): ?array
{
return $this->selectionRegistry->get($this->getToken());
}
public function getToken(): string
{
return (string)$this->getRequest()->getParam('token');
}
public function getStoreGroups(): array
{
return $this->storeViewProvider->getStoreViewGroups();
}
public function getProviders(): array
{
return $this->providerConfig->getEnabledOptions();
}
public function getDefaultProvider(): string
{
return $this->providerConfig->getDefaultProvider();
}
public function getSubmitUrl(): string
{
return $this->getUrl('localetranslate/queue/add');
}
public function getQueueUrl(): string
{
return $this->getUrl('localetranslate/queue/index');
}
public function getFormKeyValue(): string
{
return $this->formKeyService->getFormKey();
}
}
@@ -0,0 +1,75 @@
<?php
declare(strict_types=1);
namespace Esun\MultiLocaleTranslation\Block\Adminhtml\Translate;
use Esun\MultiLocaleTranslation\Model\StoreViewProvider;
use Magento\Backend\Block\Template;
use Magento\Backend\Block\Template\Context;
use Magento\Framework\Data\Form\FormKey;
class Index extends Template
{
public function __construct(
Context $context,
private readonly StoreViewProvider $storeViewProvider,
private readonly FormKey $formKeyProvider,
array $data = []
) {
parent::__construct($context, $data);
}
public function getEntityType(): string
{
return (string)$this->getRequest()->getParam('entity_type', 'product');
}
public function getEntityId(): int
{
return (int)$this->getRequest()->getParam('entity_id', 0);
}
public function getSourceStoreId(): int
{
$storeId = (int)$this->getRequest()->getParam('source_store_id', 0);
return $storeId > 0 ? $storeId : 0;
}
public function getSourceStoreIdName(): string
{
$sourceStoreId = $this->getSourceStoreId();
if ($sourceStoreId <= 0) {
return __('Default Store View')->render();
}
foreach ($this->getStoreOptions() as $storeOption) {
if ((int)$storeOption['store_id'] === $sourceStoreId) {
return (string)$storeOption['label'];
}
}
return __('Default Value (Store ID: %1)', $sourceStoreId)->render();
}
public function getStoreOptions(): array
{
return $this->storeViewProvider->getStoreViewOptions();
}
public function getFieldsUrl(): string
{
return $this->getUrl('localetranslate/translation/fields');
}
public function getApplyUrl(): string
{
return $this->getUrl('localetranslate/translation/apply');
}
public function getFormKeyValue(): string
{
return $this->formKeyProvider->getFormKey();
}
}