LanguageManager.php 952 Bytes
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
 * The LanguageManager service intializes the language types passing in the
 * Request object, which can then be used for e.g. url-based language negotiation.
15 16 17
 */
class LanguageManager {

katbailey's avatar
katbailey committed
18
  private $request;
19
  private $languages;
20

21
  public function __construct(Request $request = NULL) {
22 23 24
    $this->request = $request;
  }

25
  public function getLanguage($type) {
26 27 28 29 30 31 32 33
    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';
    $this->languages[$type] = language_types_initialize($type, array('request' => $this->request));
    return $this->languages[$type];
34 35
  }

36 37 38
  function reset() {
    $this->languages = array();
  }
39
}