Skip to content

Commit 8d646cb

Browse files
committed
[REFACTOR] Remove option to select further Mediaplayer Translation Files and simplified the ViewHelper
1 parent 827013d commit 8d646cb

File tree

6 files changed

+16
-49
lines changed

6 files changed

+16
-49
lines changed

Classes/ViewHelpers/MediaPlayerConfigViewHelper.php

Lines changed: 15 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -39,16 +39,12 @@ public static function renderStatic(
3939
$id = $arguments['id'];
4040
$inputSettings = $arguments['settings'];
4141

42-
// Whitelist keys to keep out stuff such as playerTranslations
42+
// Whitelist keys to keep out keys from settings array
4343
$allowedKeys = ['shareButtons', 'screenshotCaptions', 'constants', 'equalizer'];
4444
$result = array_intersect_key($inputSettings, array_flip($allowedKeys));
4545

4646
// Add translations
47-
$translationBaseFiles = $inputSettings['playerTranslations']['baseFile'] ?? 'EXT:dlf/Resources/Private/Language/locallang_media.xlf';
48-
if (!is_array($translationBaseFiles)) {
49-
$translationBaseFiles = [$translationBaseFiles];
50-
}
51-
$result['lang'] = self::getTranslations($translationBaseFiles);
47+
$result['lang'] = self::getTranslations('EXT:dlf/Resources/Private/Language/locallang_media.xlf');
5248

5349
// Resolve paths
5450
foreach ($result['shareButtons'] ?? [] as $key => $button) {
@@ -87,34 +83,32 @@ public static function renderStatic(
8783
}
8884

8985
/**
90-
* Collect translation keys from the specified XLIFF file and translate them
86+
* Collect translation keys from the XLIFF file and translate them
9187
* using the current language.
9288
*
9389
* Keys of the result array:
9490
* - locale: Locale identifier of current site language
9591
* - twoLetterIsoCode: Two-letter ISO code of current site language
9692
* - phrases: Map from translation keys to their translations
9793
*/
98-
private static function getTranslations(array $translationBaseFiles)
94+
private static function getTranslations(string $translationFile): array
9995
{
10096
$language = $GLOBALS['TYPO3_REQUEST']->getAttribute('language');
10197
$languageKey = $language->getTypo3Language();
102-
$phrases = [];
10398

99+
// Get default language labels
104100
$localizationFactory = GeneralUtility::makeInstance(LocalizationFactory::class);
101+
$defaultTranslations = $localizationFactory->getParsedData($translationFile, 'default');
105102

106-
// TODO: Wouldn't there be a TypoScript utility?
107-
ksort($translationBaseFiles);
108-
foreach ($translationBaseFiles as $filename) {
109-
// Grab available translation keys from the specified file
110-
$translationKeys = array_keys($localizationFactory->getParsedData($filename, 'default')['default']);
111-
112-
// Translate each available key as per the current language.
113-
// - This falls back to default language if a key isn't translated
114-
// - Pass $languageKey to ensure that translation matches ISO code
115-
foreach ($translationKeys as $transKey) {
116-
$phrases[$transKey] = LocalizationUtility::translate(
117-
"LLL:$filename:$transKey",
103+
$phrases = [];
104+
if (isset($defaultTranslations['default']) && is_array($defaultTranslations['default'])) {
105+
foreach (array_keys($defaultTranslations['default']) as $translationKey) {
106+
107+
// Translate each available key as per the current language.
108+
// - This falls back to default language if a key isn't translated
109+
// - Pass $languageKey to ensure that translation matches ISO code
110+
$phrases[$translationKey] = LocalizationUtility::translate(
111+
"LLL:$translationFile:$translationKey",
118112
/* extensionName= */null,
119113
/* arguments= */null,
120114
$languageKey

Configuration/FlexForms/MediaPlayer.xml

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -41,17 +41,6 @@
4141
</config>
4242
</TCEforms>
4343
</settings.elementId>
44-
<settings.playerTranslations.baseFile>
45-
<TCEforms>
46-
<exclude>1</exclude>
47-
<label>LLL:EXT:dlf/Resources/Private/Language/locallang_be.xlf:plugins.mediaplayer.flexform.playerTranslations.baseFile</label>
48-
<config>
49-
<type>input</type>
50-
<eval>required</eval>
51-
<default>EXT:dlf/Resources/Private/Language/locallang_media.xlf</default>
52-
</config>
53-
</TCEforms>
54-
</settings.playerTranslations.baseFile>
5544
<settings.shareButtons>
5645
<title>LLL:EXT:dlf/Resources/Private/Language/locallang_be.xlf:plugins.mediaplayer.flexform.shareButtons.title</title>
5746
<type>array</type>

Documentation/Features/MediaPlayer/Configuration.rst

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -61,15 +61,6 @@ For information on equalizer configuration, see :ref:`the equalizer subpage <eq_
6161
.. code-block:: typoscript
6262
6363
plugin.tx_dlf_mediaplayer {
64-
settings {
65-
playerTranslations {
66-
// Language file of player localization strings without language prefix
67-
baseFile = EXT:dlf/Resources/Private/Language/locallang_media.xlf
68-
// More files can be added, e.g., to override or add translation keys in a sitepackage
69-
baseFile {
70-
10 = EXT:myextension/Resources/Private/Language/locallang_media.xlf
71-
}
72-
}
7364
7465
// Share buttons to be shown in bookmark modal
7566
// Both numeric and non-numeric keys may be used

Documentation/Features/MediaPlayer/Developers.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ Localization
5757
The player can be localized via TYPO3/XLIFF language files.
5858

5959
* There is a separate language file for the media player related translation strings.
60-
The file to be used is configured in the TypoScript setting ``playerTranslations.baseFile`` of the player plugin, which defaults to ``locallang_media.xlf``.
60+
The file is located at ``dlf/Resources/Private/Language/locallang_media.xlf``.
6161

6262
* Translation strings use the `ICU MessageFormat <https://unicode-org.github.io/icu/userguide/format_parse/>`__ syntax,
6363
which in particular supports pluralization, enumerations (via ``select``), number formatting (e.g., percentages), and named placeholders.

Resources/Private/Language/de.locallang_be.xlf

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -209,10 +209,6 @@
209209
<source><![CDATA[@ID value of the HTML element that should host the player]]></source>
210210
<target><![CDATA[@ID-Wert des HTML-Elements, das den Player enthalten soll]]></target>
211211
</trans-unit>
212-
<trans-unit id="plugins.mediaplayer.flexform.playerTranslations.baseFile">
213-
<source><![CDATA[Language file of player localization strings without language prefix]]></source>
214-
<source><![CDATA[Pfad zur XLIFF-Lokalisierungsdatei (ohne Sprachkürzel)]]></source>
215-
</trans-unit>
216212
<trans-unit id="plugins.mediaplayer.flexform.shareButtons.title" approved="yes">
217213
<source><![CDATA[Share Buttons]]></source>
218214
<target><![CDATA[Share-Buttons]]></target>

Resources/Private/Language/locallang_be.xlf

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -398,9 +398,6 @@
398398
<trans-unit id="plugins.mediaplayer.flexform.elementId">
399399
<source><![CDATA[@ID value of the HTML element that should host the player]]></source>
400400
</trans-unit>
401-
<trans-unit id="plugins.mediaplayer.flexform.playerTranslations.baseFile">
402-
<source><![CDATA[Language file of player localization strings without language prefix]]></source>
403-
</trans-unit>
404401
<trans-unit id="plugins.mediaplayer.flexform.shareButtons.title">
405402
<source><![CDATA[Share Buttons]]></source>
406403
</trans-unit>

0 commit comments

Comments
 (0)