Typo3 - 在外部php文件中获取当前语言

Biz*_*oss 8 typo3

我是typo3 :)的初学者,我想在外部php文件中获取当前语言.

我怎样才能做到这一点 ?

非常感谢.

kon*_*ddy 15

如果您有TSFE的实例,则可以访问sys_language_uidvia$GLOBALS['TSFE']->sys_language_uid


Joh*_*ler 7

TYPO3 9+

$context = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(\TYPO3\CMS\Core\Context\Context::class);

// The requested language of the current page as integer (uid)
$currentLanguageUid = $context->getPropertyFromAspect('language', 'id');   
Run Code Online (Sandbox Code Playgroud)


小智 6

对于$GLOBALS['TSFE']->sys_language_uid不建议使用的V9,建议使用Language Aspect。

范例:

$languageAspect = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(\TYPO3\CMS\Core\Context\Context::class)->getAspect('language');
$sys_language_uid = $languageAspect->getId();
Run Code Online (Sandbox Code Playgroud)


Ash*_*h v 5

获取当前语言始终是最佳方式:

$GLOBALS['TSFE']->sys_language_uid  
Run Code Online (Sandbox Code Playgroud)

或者

$GLOBALS['TSFE']->sys_language_content
Run Code Online (Sandbox Code Playgroud)

基于此,您可以获得当前的语言 ID,并且您可以为此提供条件。

在 Typo3 10.x 版本中获取当前语言。

$context = GeneralUtility::makeInstance(\TYPO3\CMS\Core\Context\Context::class);
$langId = $context->getPropertyFromAspect('language', 'id');
Run Code Online (Sandbox Code Playgroud)