ILIAS  release_10 Revision v10.1-43-ga1241a92c2f
class.ilLanguageDetection.php
Go to the documentation of this file.
1 <?php
2 
3 declare(strict_types=1);
4 
28 {
30 
31  public function __construct()
32  {
33  $this->factory = new ilLanguageDetectorFactory();
34  }
35 
39  public function detect(): string
40  {
41  global $DIC;
42  $ilLog = $DIC->logger()->lang();
43 
44  $installed_languages = ilLanguage::_getInstalledLanguages();
45  $detected_language = $installed_languages[0];
46 
47  foreach ($this->factory->getValidInstances() as $detector) {
48  try {
49  $language = $detector->getIso2LanguageCode();
50  if (in_array($language, $installed_languages, true)) {
51  $detected_language = $language;
52  }
53  } catch (ilLanguageException $e) {
54  $ilLog->warning($e->getMessage());
55  }
56  }
57 
58  return $detected_language;
59  }
60 }
ilLanguageDetectorFactory $factory
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
detect()
Return detected language.
global $DIC
Definition: shib_login.php:25
static _getInstalledLanguages()
Get installed languages.