TYPO3 - Get the current language in an external php file
Asked Answered
C

6

7

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.

Cathrinecathryn answered 10/3, 2011 at 9:4 Comment(1)
What do you mean by external php file?Kuehnel
S
18

If you've got an instance of the TSFE, you can access the sys_language_uid via $GLOBALS['TSFE']->sys_language_uid

Sigismundo answered 10/3, 2011 at 12:27 Comment(4)
I don't have to include any file to use it ? I get an error : Notice: Undefined index: TSFE in.........Cathrinecathryn
Well, if file is included in your TYPO3 as USER or USER_INT, not. How do you include your file? or does it run outside the TYPO3 context?Sigismundo
Thanks, it run outside the TYPO3 contextCathrinecathryn
Since TYPO3 9, use Language Aspect: docs.typo3.org/m/typo3/reference-coreapi/master/en-us/…Kuehnel
U
16

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();
Ursula answered 5/3, 2019 at 15:9 Comment(0)
A
8

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');   
Accuracy answered 24/4, 2019 at 15:0 Comment(0)
B
7

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');
Blankly answered 14/11, 2014 at 6:31 Comment(0)
O
1

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();

Reference : https://docs.typo3.org/m/typo3/reference-coreapi/main/en-us/ApiOverview/SiteHandling/AccessingSiteConfiguration.html

Orenorenburg answered 1/12, 2021 at 6:41 Comment(0)
C
0

Normally L is always be used as a language parameter in typo3. $_GET['L']

Coyle answered 12/5, 2014 at 8:45 Comment(1)
$_GET[L] can be unset or emptyDandruff

© 2022 - 2024 — McMap. All rights reserved.