I am a beginner in TYPO3 :) and I want to get the current language in an external php file.
How can I do that?
Thanks a lot.
I am a beginner in TYPO3 :) and I want to get the current language in an external php file.
How can I do that?
Thanks a lot.
If you've got an instance of the TSFE, you can access the sys_language_uid
via $GLOBALS['TSFE']->sys_language_uid
For the V9, $GLOBALS['TSFE']->sys_language_uid
is deprecated, it recommanded to use the Language Aspect.
Example :
$languageAspect = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(\TYPO3\CMS\Core\Context\Context::class)->getAspect('language');
$sys_language_uid = $languageAspect->getId();
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');
It is always best way to get Current language:
$GLOBALS['TSFE']->sys_language_uid
or
$GLOBALS['TSFE']->sys_language_content
based on that you get current language id and you can give condition for that.
Get Current Language in Typo3 10.x version or later.
$context = GeneralUtility::makeInstance(\TYPO3\CMS\Core\Context\Context::class);
$langId = $context->getPropertyFromAspect('language', 'id');
In case you need detailed language attributes
$request = $GLOBALS['TYPO3_REQUEST'];
\TYPO3\CMS\Extbase\Utility\DebuggerUtility::var_dump(
$request->getAttribute('language')
);
Further get attributes like i.e. Path of language
$path = $request->getAttribute('language')->getBase()->getPath();
Normally L is always be used as a language parameter in typo3. $_GET['L']
$_GET[L]
can be unset or empty –
Dandruff © 2022 - 2024 — McMap. All rights reserved.