Commit 4dd593e4 authored by Tymoteusz Motylewski's avatar Tymoteusz Motylewski Committed by Xavier Perseguers
Browse files

[FEATURE] Allow AbstractPlugin::pi_loadLL to load custom language file

Add optional parameter to pi_loadlLL method to allow loading
language files located somewhere else than $this->scriptRelPath folder.
This change allows to place language files in Resources/Private/Language
also in pi-based plugins.

Resolves: #69416
Releases: master
Change-Id: Ibcfef65b1606a86559f17e706f8873a2c5a3973b
Reviewed-on: http://review.typo3.org/42934

Reviewed-by: Alexander Opitz's avatarAlexander Opitz <opitz.alexander@googlemail.com>
Tested-by: Alexander Opitz's avatarAlexander Opitz <opitz.alexander@googlemail.com>
Reviewed-by: Xavier Perseguers's avatarXavier Perseguers <xavier@typo3.org>
Tested-by: Xavier Perseguers's avatarXavier Perseguers <xavier@typo3.org>
parent cb093068
========================================================================
Feature: #69416 - Plugins (AbstractPlugin) can load custom language file
========================================================================
Description
===========
``AbstractPlugin::pi_loadLL`` takes an optional argument specifing path to a language file. It allows placing language files in other paths like in Extbase structure "Resources/Private/Language". Previously language file had to be located in the directory set in the ``scriptRelPath`` property.
Impact
======
Possibility to put language label files in other paths.
......@@ -971,25 +971,32 @@ class AbstractPlugin {
}
/**
* Loads local-language values by looking for a "locallang" file in the
* plugin class directory ($this->scriptRelPath) and if found includes it.
* Loads local-language values from the file passed as a parameter or
* by looking for a "locallang" file in the
* plugin class directory ($this->scriptRelPath).
* Also locallang values set in the TypoScript property "_LOCAL_LANG" are
* merged onto the values found in the "locallang" file.
* Supported file extensions xlf, xml
*
* @param string $languageFilePath path to the plugin language file in format EXT:....
* @return void
*/
public function pi_loadLL() {
if (!$this->LOCAL_LANG_loaded && $this->scriptRelPath) {
public function pi_loadLL($languageFilePath = '') {
if ($this->LOCAL_LANG_loaded) {
return;
}
if ($languageFilePath === '' && $this->scriptRelPath) {
$languageFilePath = 'EXT:' . $this->extKey . '/' . dirname($this->scriptRelPath) . '/locallang.xlf';
}
if ($languageFilePath !== '') {
/** @var $languageFactory LocalizationFactory */
$languageFactory = GeneralUtility::makeInstance(LocalizationFactory::class);
$basePath = 'EXT:' . $this->extKey . '/' . dirname($this->scriptRelPath) . '/locallang.xlf';
// Read the strings in the required charset (since TYPO3 4.2)
$this->LOCAL_LANG = $languageFactory->getParsedData($basePath, $this->LLkey, $this->frontendController->renderCharset);
$this->LOCAL_LANG = $languageFactory->getParsedData($languageFilePath, $this->LLkey, $this->frontendController->renderCharset);
$alternativeLanguageKeys = GeneralUtility::trimExplode(',', $this->altLLkey, TRUE);
foreach ($alternativeLanguageKeys as $languageKey) {
$tempLL = $languageFactory->getParsedData($basePath, $languageKey);
$tempLL = $languageFactory->getParsedData($languageFilePath, $languageKey);
if ($this->LLkey !== 'default' && isset($tempLL[$languageKey])) {
$this->LOCAL_LANG[$languageKey] = $tempLL[$languageKey];
}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment