[TASK] Improve translation handling
This commit is contained in:
94
Classes/Utility/TranslationUtility.php
Normal file
94
Classes/Utility/TranslationUtility.php
Normal file
@@ -0,0 +1,94 @@
|
||||
<?php
|
||||
namespace Cjel\TemplatesAide\Utility;
|
||||
|
||||
/***
|
||||
*
|
||||
* This file is part of the "Templates Aide" Extension for TYPO3 CMS.
|
||||
*
|
||||
* For the full copyright and license information, please read the
|
||||
* LICENSE.txt file that was distributed with this source code.
|
||||
*
|
||||
* (c) 2021 Philipp Dieter <philipp.dieter@attic-media.net>
|
||||
*
|
||||
***/
|
||||
|
||||
use TYPO3\CMS\Extbase\Utility\LocalizationUtility;
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
class TranslationUtility
|
||||
{
|
||||
|
||||
/**
|
||||
* Get all interface constants per prefix
|
||||
*/
|
||||
public static function buildSelectOptionsFromOptions(
|
||||
$options,
|
||||
$column,
|
||||
$element,
|
||||
$extensionKey = null
|
||||
) {
|
||||
$items = [];
|
||||
if ($addEmpty) {
|
||||
$items[] = ['-', ''];
|
||||
}
|
||||
foreach ($options as $option) {
|
||||
$translationKey = "option.$element.$column.$option";
|
||||
$translation = self::getTranslation(
|
||||
$translationKey,
|
||||
$extensionKey
|
||||
);
|
||||
if ($translation) {
|
||||
$items[] = [
|
||||
'code' => $option,
|
||||
'label' => $translation,
|
||||
];
|
||||
} else {
|
||||
$items[] = [
|
||||
'code' => $option,
|
||||
'label' => $translationKey,
|
||||
];
|
||||
}
|
||||
}
|
||||
return $items;
|
||||
}
|
||||
|
||||
/**
|
||||
* shortcut to get translation
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public static function getTranslation($key, $extensionKey)
|
||||
{
|
||||
if (version_compare(TYPO3_branch, '10.0', '>=')) {
|
||||
if (!$extensionKey) {
|
||||
$extensionKey = 'site_templates';
|
||||
}
|
||||
return implode([
|
||||
'LLL:EXT:',
|
||||
$extensionKey,
|
||||
'/Resources/Private/Language/locallang_db.xlf:',
|
||||
$key
|
||||
]);
|
||||
} else {
|
||||
if ($extensionKey) {
|
||||
$translation = LocalizationUtility::translate(
|
||||
$key,
|
||||
$extensionKey
|
||||
);
|
||||
if ($translation) {
|
||||
return $translation;
|
||||
}
|
||||
}
|
||||
$translation = LocalizationUtility::translate(
|
||||
$key,
|
||||
'site_templates'
|
||||
);
|
||||
if ($translation) {
|
||||
return $translation;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user