ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
class.ilHttpRequestsLanguageDetector.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (c) 1998-2015 ILIAS open source, Extended GPL, see docs/LICENSE */
3 
4 require_once 'Services/Language/interfaces/interface.ilLanguageDetector.php';
5 
12 {
16  protected $header_value;
17 
21  public function __construct($header_value)
22  {
23  $this->header_value = $header_value;
24  }
25 
31  public function getIso2LanguageCode()
32  {
33  if(strlen($this->header_value))
34  {
35  $matches = array();
36  // Format: de,de-DE;q=0.8,en-US;q=0.6,en;q=0.4
37  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);
38  if(count($matches[1]))
39  {
40  $langs = array_combine($matches[1], $matches[4]);
41  foreach($langs as $lang => $val)
42  {
43  if($val === '')
44  {
45  $langs[$lang] = 1;
46  }
47  }
48 
49  arsort($langs, SORT_NUMERIC);
50 
51  $keys = array_keys($langs);
52  if(isset($keys[0]))
53  {
54  return substr($keys[0], 0, 2);
55  }
56  }
57  }
58 
59  require_once 'Services/Language/exceptions/class.ilLanguageException.php';
60  throw new ilLanguageException('Could not extract any language information from request.');
61  }
62 }
Class for language related exception handling in ILIAS.
Interface ilLanguageDetector.
Class ilHttpRequestsLanguageDetector.
Create styles array
The data for the language used.
for($i=1; $i<=count($kw_cases_sel); $i+=1) $lang
Definition: langwiz.php:349
getIso2LanguageCode()
Returns the detected ISO2 language code.