ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
class.ilHttpRequestsLanguageDetector.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
27{
28 protected string $header_value;
29
30 public function __construct(string $header_value)
31 {
32 $this->header_value = $header_value;
33 }
34
39 public function getIso2LanguageCode(): string
40 {
41 if (strlen($this->header_value)) {
42 $matches = array();
43 // Format: de,de-DE;q=0.8,en-US;q=0.6,en;q=0.4
44 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);
45 if (count($matches[1])) {
46 $langs = array_combine($matches[1], $matches[4]);
47 foreach ($langs as $lang => $val) {
48 if ($val === '') {
49 $langs[$lang] = 1;
50 }
51 }
52 arsort($langs, SORT_NUMERIC);
53
54 $keys = array_keys($langs);
55 if (isset($keys[0])) {
56 return substr($keys[0], 0, 2);
57 }
58 }
59 }
60
61 throw new ilLanguageException("Could not extract any language information from request.");
62 }
63}
Class ilHttpRequestsLanguageDetector.
getIso2LanguageCode()
Returns the detected ISO2 language code.
Class for language related exception handling in ILIAS.
Interface ilLanguageDetector.
$lang
Definition: xapiexit.php:25