Is it possible to get the current language key (or code) in a TYPO3 Fluid template?
In the meantime I've found another solution using a view helper found here:
<?php
class Tx_AboUnitReservation_ViewHelpers_LanguageViewHelper extends Tx_Fluid_Core_ViewHelper_AbstractViewHelper {
/**
* Get the current language
*/
protected function getLanguage() {
if (TYPO3_MODE === 'FE') {
if (isset($GLOBALS['TSFE']->config['config']['language'])) {
return $GLOBALS['TSFE']->config['config']['language'];
}
} elseif (strlen($GLOBALS['BE_USER']->uc['lang']) > 0) {
return $GLOBALS['BE_USER']->uc['lang'];
}
return 'en'; //default
}
/**
* Return current language
* @return string
*/
public function render() {
return $this->getLanguage();
}
}
?>
Which I use in the fluid template as follows.
<f:alias map="{isGerman: 'de'}">
<f:if condition="{aboUnitReservation:language()} == {isGerman}">
<script type="text/javascript" src="{f:uri.resource(path:'js/jquery.ui.datepicker-de-CH.js')}"></script>
</f:if>
</f:alias>
Another solution using TypoScript object in Fluid template:
# German language
temp.language = TEXT
temp.language.value = at
# English language
[globalVar = GP:L = 1]
temp.language.value = en
[global]
lib.language < temp.language
And Fluid code:
<f:if condition="{f:cObject(typoscriptObjectPath: 'lib.language')} == 'at'">
<f:then>
...
</f:then>
<f:else>
...
</f:else>
</f:if>
Object temp.language
can contain any values, of course.