Skip to content

Instantly share code, notes, and snippets.

@fedetibaldo
Created September 18, 2020 08:38
Show Gist options
  • Save fedetibaldo/83881a8d61edc3c54c83f2f1b23fa8b2 to your computer and use it in GitHub Desktop.
Save fedetibaldo/83881a8d61edc3c54c83f2f1b23fa8b2 to your computer and use it in GitHub Desktop.
Get Current Language ISO Code in TYPO3
<?php
use TYPO3\CMS\Core\Context\Context;
use TYPO3\CMS\Core\Utility\GeneralUtility;
// ...
$context = GeneralUtility::makeInstance(Context::class);
/** @var TYPO3\CMS\Core\Site\Entity\Site */
$site = $GLOBALS['TYPO3_REQUEST']->getAttribute('site');
$langId = $context->getPropertyFromAspect('language', 'id');
/** @var TYPO3\CMS\Core\Site\Entity\SiteLanguage */
$language = $site->getLanguageById($langId);
$langCode = $language->getTwoLetterIsoCode();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment