Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve usage readability #357

Closed
Closed
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
29 changes: 23 additions & 6 deletions Classes/Event/Listener/UsageToolBarEventListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use Psr\Log\LoggerAwareInterface;
use Psr\Log\LoggerAwareTrait;
use TYPO3\CMS\Backend\Backend\Event\SystemInformationToolbarCollectorEvent;
use TYPO3\CMS\Backend\Toolbar\Enumeration\InformationStatus;
use TYPO3\CMS\Core\Localization\LanguageService;
use WebVision\WvDeepltranslate\Exception\ApiKeyNotSetException;
use WebVision\WvDeepltranslate\Service\UsageService;
Expand Down Expand Up @@ -40,19 +41,35 @@ public function __invoke(SystemInformationToolbarCollectorEvent $systemInformati
}
return;
}

$title = $this->getLanguageService()->sL(
'LLL:EXT:wv_deepltranslate/Resources/Private/Language/locallang.xlf:usages.toolbar-label'
);
$message = $this->getLanguageService()->sL(
'LLL:EXT:wv_deepltranslate/Resources/Private/Language/locallang.xlf:usages.toolbar.message'
);

$systemInformation->getToolbarItem()->addSystemInformation(
$this->getLanguageService()->sL('LLL:EXT:wv_deepltranslate/Resources/Private/Language/locallang.xlf:usages.toolbar-label'),
sprintf(
'%d / %d',
$usage->character->count,
$usage->character->limit
),
$title,
sprintf($message, $this->formatNumber($usage->character->count), $this->formatNumber($usage->character->limit)),
'actions-localize-deepl',
InformationStatus::STATUS_NOTICE,
);
}

private function getLanguageService(): LanguageService
{
return $GLOBALS['LANG'];
}

/**
* Make large API limits easier to read
*
* @param int $number Any large integer - 5000000
* @return string Formated, better readable string variant of the integer - 5.000.000
*/
private function formatNumber(int $number): string
{
return number_format($number, 0, ',', '.');
}
}
18 changes: 13 additions & 5 deletions Classes/Hooks/UsageProcessAfterFinishHook.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,22 +39,25 @@ public function processCmdmap_afterFinish(DataHandler $dataHandler): void
return;
}

$label = $this->getLanguageService()->sL(
$title = $this->getLanguageService()->sL(
'LLL:EXT:wv_deepltranslate/Resources/Private/Language/locallang.xlf:usages.flashmassage.title'
);
$message = $this->getLanguageService()->sL(
'LLL:EXT:wv_deepltranslate/Resources/Private/Language/locallang.xlf:usages.flashmassage.limit.description'
);

$flashMessageService = GeneralUtility::makeInstance(FlashMessageService::class);
$notificationQueue = $flashMessageService->getMessageQueueByIdentifier();

$severity = -1; // Info
$severity = FlashMessage::INFO;
if ($this->usageService->isTranslateLimitExceeded()) {
$severity = 1; // Warning
$severity = FlashMessage::WARNING;
}

$flashMessage = GeneralUtility::makeInstance(
FlashMessage::class,
sprintf($label, $usage->character->count, $usage->character->limit),
'Deepl Usage',
sprintf($message, $this->formatNumber($usage->character->count), $this->formatNumber($usage->character->limit)),
$title,
$severity,
true
);
Expand All @@ -66,4 +69,9 @@ private function getLanguageService(): LanguageService
{
return $GLOBALS['LANG'];
}

private function formatNumber(int $number): string
{
return number_format($number, 0, ',', '.');
}
}
14 changes: 13 additions & 1 deletion Resources/Private/Language/de.locallang.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -199,13 +199,25 @@
</trans-unit>

<trans-unit id="usages.toolbar-label">
<source>DeepL Translate Limit</source>
<source>DeepL Translate Quota</source>
<target>DeepL Übersetzung Limit</target>
</trans-unit>
<trans-unit id="usages.toolbar.message">
<source>%s / %s</source>
<target>%s / %s</target>
</trans-unit>
<trans-unit id="usages.toolbar-information">
<source>Information not available</source>
<target>Information nicht verfügbar</target>
</trans-unit>
<trans-unit id="usages.flashmassage.title">
<source>DeepL usage and quota</source>
<target>DeepL Nutzung und Limits</target>
</trans-unit>
<trans-unit id="usages.flashmassage.limit.description">
<source>DeepL translations for current billing period: %s of %s characters</source>
<target>DeepL Übersetzungen für den aktuellen Abrechnungszeitraum: %s von %s Zeichen</target>
</trans-unit>

<!-- Widget -->
<trans-unit id="widgets.deepltranslate.widget.useswidget.title">
Expand Down
9 changes: 6 additions & 3 deletions Resources/Private/Language/locallang.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -174,16 +174,19 @@
</trans-unit>

<trans-unit id="usages.toolbar-label">
<source>DeepL Translate Limit</source>
<source>DeepL Translate Quota</source>
</trans-unit>
<trans-unit id="usages.toolbar.message">
<source>%s / %s</source>
</trans-unit>
<trans-unit id="usages.toolbar-information">
<source>Information not available</source>
</trans-unit>
<trans-unit id="usages.flashmassage.title">
<source>DeepL Translate </source>
<source>DeepL usage and quota</source>
</trans-unit>
<trans-unit id="usages.flashmassage.limit.description">
<source>DeepL Translate Limit %s / %s</source>
<source>DeepL translations for current billing period: %s of %s characters</source>
</trans-unit>

<!-- Translation Access | be_groups -->
Expand Down
17 changes: 4 additions & 13 deletions Resources/Public/Icons/actions-localize-deepl.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.