LanguageManager.php 1.07 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12
<?php

/**
 * @file
 * Definition of Drupal\Core\Language\LanguageManager.
 */

namespace Drupal\Core\Language;

use Symfony\Component\HttpFoundation\Request;

/**
13 14 15 16 17 18
 * Class responsible for initializing each language type.
 *
 * This service is dependent on the 'request' service and can therefore pass the
 * Request object to the code that deals with each particular language type.
 * This means the Request can be used directly for things like url-based language
 * negotiation.
19 20 21
 */
class LanguageManager {

katbailey's avatar
katbailey committed
22
  private $request;
23
  private $languages;
24

25
  public function __construct(Request $request = NULL) {
26 27 28
    $this->request = $request;
  }

29
  public function getLanguage($type) {
30 31 32 33 34 35
    if (isset($this->languages[$type])) {
      return $this->languages[$type];
    }

    // @todo Objectify the language system so that we don't have to do this.
    include_once DRUPAL_ROOT . '/core/includes/language.inc';
36
    $this->languages[$type] = language_types_initialize($type, $this->request);
37
    return $this->languages[$type];
38 39
  }

40 41 42
  function reset() {
    $this->languages = array();
  }
Crell's avatar
Crell committed
43
}