gpt4 book ai didi

TYPO3 Fluid Template 获取语言代码

转载 作者:行者123 更新时间:2023-12-05 01:03:19 30 4
gpt4 key购买 nike

是否可以在 TYPO3 Fluid 模板中获取当前语言 key (或代码)?

与此同时,我找到了另一个使用 View 助手的解决方案 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();
}

}

?>

我在流体模板中使用如下。
<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>

最佳答案

您可以在您的操作中分配变量:

$this->view->assign("sysLanguageUid", $GLOBALS['TSFE']->sys_language_uid);

然后在您的 View 中阅读它:
<f:if condition="{sysLanguageUid} == 0">
You're reading English version of page
</f:if>

另一方面将 Controller 中的 redy-to-use 变量分配为 <f:if ...> 会更容易、更舒适块非常简单,有时只是不舒服:
switch ($GLOBALS['TSFE']->sys_language_uid) {
case 1:
$msg = "Bienvenidos";
break;
case 2:
$msg = "Willkommen";
break;
default:
$msg = "Welcome";
break;
}

$this->view->assign("myMessage", $msg);

关于TYPO3 Fluid Template 获取语言代码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10446432/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com