public static function loadLanguageFile($strName, $strLanguage = null, $blnNoCache = false)
{
if ($strLanguage === null) {
$strLanguage = str_replace('-', '_', $GLOBALS['TL_LANGUAGE']);
}
// Fall back to English
if ($strLanguage == '') {
$strLanguage = 'en';
}
// Return if the language file has been loaded already
if (isset(static::$arrLanguageFiles[$strName][$strLanguage]) && !$blnNoCache) {
return;
}
$strCacheKey = $strLanguage;
// Make sure the language exists
if (!static::isInstalledLanguage($strLanguage)) {
$strShortLang = substr($strLanguage, 0, 2);
// Fall back to "de" if "de_DE" does not exist
if ($strShortLang != $strLanguage && static::isInstalledLanguage($strShortLang)) {
$strLanguage = $strShortLang;
} else {
$strLanguage = 'en';
}
}
// Use a global cache variable to support nested calls
static::$arrLanguageFiles[$strName][$strCacheKey] = $strLanguage;
// Fall back to English
$arrCreateLangs = $strLanguage == 'en' ? array('en') : array('en', $strLanguage);
// Prepare the XLIFF loader
$xlfLoader = new XliffFileLoader(static::getContainer()->getParameter('kernel.root_dir'), true);
$strCacheDir = static::getContainer()->getParameter('kernel.cache_dir');
// Load the language(s)
foreach ($arrCreateLangs as $strCreateLang) {
// Try to load from cache
if (file_exists($strCacheDir . '/contao/languages/' . $strCreateLang . '/' . $strName . '.php')) {
include $strCacheDir . '/contao/languages/' . $strCreateLang . '/' . $strName . '.php';
} else {
try {
$files = static::getContainer()->get('contao.resource_locator')->locate('languages/' . $strCreateLang . '/' . $strName . '.php', null, false);
} catch (\InvalidArgumentException $e) {
$files = array();
}
foreach ($files as $file) {
include $file;
}
try {
$files = static::getContainer()->get('contao.resource_locator')->locate('languages/' . $strCreateLang . '/' . $strName . '.xlf', null, false);
} catch (\InvalidArgumentException $e) {
$files = array();
}
foreach ($files as $file) {
$xlfLoader->load($file, $strCreateLang);
}
}
}
// HOOK: allow to load custom labels
if (isset($GLOBALS['TL_HOOKS']['loadLanguageFile']) && is_array($GLOBALS['TL_HOOKS']['loadLanguageFile'])) {
foreach ($GLOBALS['TL_HOOKS']['loadLanguageFile'] as $callback) {
static::importStatic($callback[0])->{$callback[1]}($strName, $strLanguage, $strCacheKey);
}
}
// Handle single quotes in the deleteConfirm message
if ($strName == 'default') {
$GLOBALS['TL_LANG']['MSC']['deleteConfirm'] = str_replace("'", "\\'", $GLOBALS['TL_LANG']['MSC']['deleteConfirm']);
}
// Local configuration file
if (file_exists(TL_ROOT . '/system/config/langconfig.php')) {
@trigger_error('Using the langconfig.php file has been deprecated and will no longer work in Contao 5.0. Create one or more language files in app/Resources/contao/languages instead.', E_USER_DEPRECATED);
include TL_ROOT . '/system/config/langconfig.php';
}
}