78 $this->debugKey = (bool)
$GLOBALS[
'TYPO3_CONF_VARS'][
'BE'][
'languageDebug'];
90 public function init($languageKey)
94 $locales = GeneralUtility::makeInstance(Locales::class);
96 if (in_array($languageKey,
$locales->getLocales())) {
98 $this->lang = $languageKey;
99 $this->languageDependencies[] = $languageKey;
100 foreach (
$locales->getLocaleDependencies($languageKey) as $language) {
101 $this->languageDependencies[] = $language;
114 return $this->debugKey ?
'[' . $value .
']' :
'';
124 public function getLL($index)
136 public function getLLL($index, $localLanguage)
140 if (isset($localLanguage[$this->lang][$index])) {
141 $value = is_string($localLanguage[$this->lang][$index])
144 } elseif (isset($localLanguage[
'default'][$index])) {
145 $value = is_string($localLanguage[
'default'][$index])
146 ? $localLanguage[
'default'][$index]
147 : $localLanguage[
'default'][$index][0][
'target'];
151 return $value . $this->
debugLL($index);
164 public function sL($input)
166 $identifier = $input .
'_' . (int)$this->debugKey;
167 if (isset($this->LL_labels_cache[$this->lang][$identifier])) {
168 return $this->LL_labels_cache[
$this->lang][$identifier];
170 if (strpos($input,
'LLL:') === 0) {
171 $restStr = trim(substr($input, 4));
174 if (strpos($restStr,
'EXT:') === 0) {
175 $restStr = trim(substr($restStr, 4));
178 $parts = explode(
':', $restStr);
179 $parts[0] = $extPrfx . $parts[0];
181 if (!isset($this->LL_files_cache[$parts[0]])) {
182 $this->LL_files_cache[$parts[0]] = $this->
readLLfile($parts[0]);
184 $output = $this->
getLLL($parts[1], $this->LL_files_cache[$parts[0]]);
205 if (is_array(
$GLOBALS[
'TCA_DESCR'][$table]) && !isset(
$GLOBALS[
'TCA_DESCR'][$table][
'columns']) && is_array(
$GLOBALS[
'TCA_DESCR'][$table][
'refs'])) {
207 $GLOBALS[
'TCA_DESCR'][$table][
'columns'] = [];
209 foreach (
$GLOBALS[
'TCA_DESCR'][$table][
'refs'] as $llfile) {
212 if (is_array($localLanguage[
'default'])) {
213 foreach ($localLanguage[
'default'] as $lkey => $lVal) {
218 $keyParts = explode(
'.', $lkey);
219 $keyPartsCount = count($keyParts);
222 $specialInstruction = $keyParts[$keyPartsCount - 1] ===
'+';
223 if ($specialInstruction) {
224 array_pop($keyParts);
229 if ($keyPartsCount > 2) {
230 $type = array_pop($keyParts);
231 $fieldName = implode(
'.', $keyParts);
233 $fieldName = $keyParts[0];
234 $type = $keyParts[1];
237 if ($fieldName ===
'_') {
240 if ($fieldName !==
'' && $fieldName[0] ===
'_') {
241 $fieldName = substr($fieldName, 1);
244 $label = $lVal[0][
'target'] ?: $lVal[0][
'source'];
245 if ($specialInstruction) {
246 $GLOBALS[
'TCA_DESCR'][$table][
'columns'][$fieldName][$type] .= LF . $label;
249 $GLOBALS[
'TCA_DESCR'][$table][
'columns'][$fieldName][$type] = $label;
266 public function includeLLFile($fileRef, $setGlobal =
true, $mergeLocalOntoDefault =
false)
268 $globalLanguage = [];
271 if (is_array($localLanguage) && !empty($localLanguage)) {
274 $globalLanguage = (array)(
$GLOBALS[
'LOCAL_LANG'] ?? []);
277 $globalLanguage = $localLanguage;
280 if ($mergeLocalOntoDefault && $this->lang !==
'default' && is_array($globalLanguage[$this->lang]) && is_array($globalLanguage[
'default'])) {
283 $globalLanguage[
'default'] = array_merge($globalLanguage[
'default'], $globalLanguage[$this->lang]);
284 unset($globalLanguage[$this->lang]);
289 return $globalLanguage;
291 $GLOBALS[
'LOCAL_LANG'] = $globalLanguage;
303 if (isset($this->languageFileCache[$fileRef . $this->lang])) {
304 return $this->languageFileCache[$fileRef .
$this->lang];
308 $languageFactory = GeneralUtility::makeInstance(LocalizationFactory::class);
310 if ($this->lang !==
'default') {
311 $languages = array_reverse($this->languageDependencies);
313 $languages = [
'default'];
316 foreach ($languages as $language) {
317 $tempLL = $languageFactory->getParsedData($fileRef, $language);
318 $localLanguage[
'default'] = $tempLL[
'default'];
319 if (!isset($localLanguage[$this->lang])) {
320 $localLanguage[
$this->lang] = $localLanguage[
'default'];
322 if ($this->lang !==
'default' && isset($tempLL[$language])) {
328 $this->languageFileCache[$fileRef .
$this->lang] = $localLanguage;
330 return $localLanguage;
344 $labels = array_merge((array)
$GLOBALS[
'LOCAL_LANG'][
'default'], (array)
$GLOBALS[
'LOCAL_LANG'][$this->lang]);
346 $labelPattern =
'#^' . preg_quote($prefix,
'#') .
'(' . preg_quote($strip,
'#') .
')?#';
348 foreach ($labels as $label => $value) {
349 if (strpos($label, $prefix) === 0) {
350 $key = preg_replace($labelPattern,
'', $label);
351 $extraction[$key] = $value;