-
Notifications
You must be signed in to change notification settings - Fork 40
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This widget shows the current character limit of the DeeoL Translate function, as a TYPO3 dashboard widget.
- Loading branch information
Showing
7 changed files
with
174 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace WebVision\WvDeepltranslate\Widgets; | ||
|
||
use TYPO3\CMS\Core\Localization\LanguageService; | ||
use TYPO3\CMS\Core\Utility\GeneralUtility; | ||
use TYPO3\CMS\Dashboard\Widgets\WidgetConfigurationInterface; | ||
use TYPO3\CMS\Dashboard\Widgets\WidgetInterface; | ||
use TYPO3\CMS\Fluid\View\StandaloneView; | ||
use WebVision\WvDeepltranslate\Service\UsageService; | ||
|
||
class UsageWidget implements WidgetInterface | ||
{ | ||
private WidgetConfigurationInterface $configuration; | ||
|
||
private StandaloneView $view; | ||
|
||
/** | ||
* @var array<string, mixed> | ||
*/ | ||
private array $options; | ||
|
||
/** | ||
* @param array<string, mixed> $options | ||
*/ | ||
public function __construct( | ||
WidgetConfigurationInterface $configuration, | ||
StandaloneView $view, | ||
array $options = [] | ||
) { | ||
$this->configuration = $configuration; | ||
$this->view = $view; | ||
$this->options = $options; | ||
} | ||
|
||
public function renderWidgetContent(): string | ||
{ | ||
/** @var UsageService $usageService */ | ||
$usageService = GeneralUtility::makeInstance(UsageService::class); | ||
|
||
// Workaround to make the widget template available in two TYPO3 versions | ||
$templateRootPaths = $this->view->getTemplateRootPaths(); | ||
$templateRootPaths[1718368476557] = 'EXT:wv_deepltranslate/Resources/Private/Backend/Templates/'; | ||
$this->view->setTemplateRootPaths($templateRootPaths); | ||
|
||
$currentUsage = $usageService->getCurrentUsage(); | ||
|
||
$this->view->assignMultiple([ | ||
'usages' => [ | ||
[ | ||
'label' => $this->getLanguageService()->sL('LLL:EXT:wv_deepltranslate/Resources/Private/Language/locallang.xlf:widgets.deepltranslate.widget.useswidget.character'), | ||
'usage' => $currentUsage !== null ? $currentUsage->character : [], | ||
], | ||
], | ||
'options' => $this->options, | ||
'configuration' => $this->configuration, | ||
]); | ||
|
||
return $this->view->render('Widget/UsageWidget'); | ||
} | ||
|
||
/** | ||
* @return array<string, mixed> | ||
*/ | ||
public function getOptions(): array | ||
{ | ||
return $this->options; | ||
} | ||
|
||
protected function getLanguageService(): LanguageService | ||
{ | ||
return $GLOBALS['LANG']; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
<?php | ||
|
||
return (static function () { | ||
if (\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::isLoaded('dashboard')) { | ||
return [ | ||
'deepl' => [ | ||
'title' => 'DeepL Widget', | ||
], | ||
]; | ||
} | ||
|
||
return []; | ||
})(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
28 changes: 28 additions & 0 deletions
28
Resources/Private/Backend/Templates/Widget/UsageWidget.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
<html | ||
data-namespace-typo3-fluid="true" | ||
xmlns:f="http://typo3.org/ns/TYPO3/CMS/Fluid/ViewHelpers" | ||
> | ||
<f:layout name="Widget/Widget" /> | ||
|
||
<f:section name="main"> | ||
<f:for as="item" each="{usages}" > | ||
<div class="mb-3"> | ||
<h4>{item.label}</h4> | ||
<p> | ||
<b>{f:translate(key: 'LLL:EXT:wv_deepltranslate/Resources/Private/Language/locallang.xlf:widgets.deepltranslate.widget.useswidget.count')}</b>: {item.usage.count -> f:format.number(thousandsSeparator: '.', decimalSeparator: '', decimals: 0)} | ||
<br> | ||
<b>{f:translate(key: 'LLL:EXT:wv_deepltranslate/Resources/Private/Language/locallang.xlf:widgets.deepltranslate.widget.useswidget.limit')}</b>: {item.usage.limit -> f:format.number(thousandsSeparator: '.', decimalSeparator: '', decimals: 0)} | ||
</p> | ||
<f:variable name="procss">{item.usage.count / item.usage.limit * 100}</f:variable> | ||
<div class="progress" role="progressbar" aria-label="Usage" aria-valuenow="{procss}" aria-valuemin="0" aria-valuemax="100" style="height: 50%"> | ||
<div class="progress-bar" style="width: {procss}%">{item.usage.count -> f:format.number(thousandsSeparator: '.', decimalSeparator: '', decimals: 0)}</div> | ||
</div> | ||
</div> | ||
</f:for> | ||
</f:section> | ||
|
||
<f:section name="footer"> | ||
<f:render partial="Widget/Button" arguments="{button: button}"/> | ||
</f:section> | ||
|
||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters