ILIAS  release_8 Revision v8.19-1-g4e8f2f9140c
All Data Structures Namespaces Files Functions Variables Modules Pages
ilHttpRequestsLanguageDetector Class Reference

This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Learning e.V. More...

+ Inheritance diagram for ilHttpRequestsLanguageDetector:
+ Collaboration diagram for ilHttpRequestsLanguageDetector:

Public Member Functions

 __construct (string $header_value)
 
 getIso2LanguageCode ()
 Returns the detected ISO2 language code. More...
 

Protected Attributes

string $header_value
 

Detailed Description

This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Learning e.V.

ILIAS is licensed with the GPL-3.0, see https://www.gnu.org/licenses/gpl-3.0.en.html You should have received a copy of said license along with the source code, too.

If this is not the case or you just want to try ILIAS, you'll find us at: https://www.ilias.de https://github.com/ILIAS-eLearning Class ilHttpRequestsLanguageDetector

Author
Michael Jansen mjans.nosp@m.en@d.nosp@m.ataba.nosp@m.y.de /

Definition at line 29 of file class.ilHttpRequestsLanguageDetector.php.

Constructor & Destructor Documentation

◆ __construct()

ilHttpRequestsLanguageDetector::__construct ( string  $header_value)

Definition at line 33 of file class.ilHttpRequestsLanguageDetector.php.

References $header_value.

34  {
35  $this->header_value = $header_value;
36  }

Member Function Documentation

◆ getIso2LanguageCode()

ilHttpRequestsLanguageDetector::getIso2LanguageCode ( )

Returns the detected ISO2 language code.

Exceptions
ilLanguageException

Implements ilLanguageDetector.

Definition at line 42 of file class.ilHttpRequestsLanguageDetector.php.

References $keys, and $lang.

42  : string
43  {
44  if (strlen($this->header_value)) {
45  $matches = array();
46  // Format: de,de-DE;q=0.8,en-US;q=0.6,en;q=0.4
47  preg_match_all("/([a-z]{1,8}(-[a-z]{1,8})?)\s*(;\s*q\s*=\s*(1|0\.[0-9]+))?/i", $this->header_value, $matches);
48  if (count($matches[1])) {
49  $langs = array_combine($matches[1], $matches[4]);
50  foreach ($langs as $lang => $val) {
51  if ($val === '') {
52  $langs[$lang] = 1;
53  }
54  }
55  arsort($langs, SORT_NUMERIC);
56 
57  $keys = array_keys($langs);
58  if (isset($keys[0])) {
59  return substr($keys[0], 0, 2);
60  }
61  }
62  }
63 
64  require_once "Services/Language/exceptions/class.ilLanguageException.php";
65  throw new ilLanguageException("Could not extract any language information from request.");
66  }
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
$keys
Definition: metadata.php:204
$lang
Definition: xapiexit.php:26

Field Documentation

◆ $header_value

string ilHttpRequestsLanguageDetector::$header_value
protected

Definition at line 31 of file class.ilHttpRequestsLanguageDetector.php.

Referenced by __construct().


The documentation for this class was generated from the following file: