TYPO3 CMS  TYPO3_6-2
LanguageRepository.php
Go to the documentation of this file.
1 <?php
22 
26  protected $objectManager;
27 
31  protected $selectedLanguages = array();
32 
36  protected $locales;
37 
41  protected $languages = array();
42 
46  protected $configurationPath = 'EXTCONF/lang';
47 
51  public function __construct() {
52  try {
53  $globalSettings = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Configuration\\ConfigurationManager')->getLocalConfigurationValueByPath($this->configurationPath);
54  $this->selectedLanguages = (array) $globalSettings['availableLanguages'];
55  } catch (\Exception $e) {
56  \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Configuration\\ConfigurationManager')->setLocalConfigurationValueByPath(
57  $this->configurationPath,
58  array('availableLanguages' => array())
59  );
60  }
61  }
62 
69  public function injectObjectManager(\TYPO3\CMS\Extbase\Object\ObjectManager $objectManager) {
70  $this->objectManager = $objectManager;
71  }
72 
79  public function injectLocales(\TYPO3\CMS\Core\Localization\Locales $locales) {
80  $this->locales = $locales;
81  }
82 
88  public function findAll() {
89  if (!count($this->languages)) {
90  $languages = $this->locales->getLanguages();
91  array_shift($languages);
92 
93  foreach ($languages as $locale => $language) {
94  $label = htmlspecialchars($GLOBALS['LANG']->sL('LLL:EXT:setup/mod/locallang.xlf:lang_' . $locale));
95  if ($label === '') {
96  $label = htmlspecialchars($language);
97  }
98 
99  $this->languages[$locale] = $this->objectManager->get(
100  'TYPO3\CMS\Lang\Domain\Model\Language',
101  $locale,
102  $label,
103  in_array($locale, $this->selectedLanguages)
104  );
105  }
106 
107  usort($this->languages, function($a, $b) {
110  if ($a->getLanguage() == $b->getLanguage()) {
111  return 0;
112  }
113  return $a->getLanguage() < $b->getLanguage() ? -1 : 1;
114  });
115  }
116 
117  return $this->languages;
118  }
119 
125  public function findSelected() {
126  $languages = $this->findAll();
127 
128  $result = array();
130  foreach ($languages as $language) {
131  if ($language->getSelected()) {
132  $result[] = $language;
133  }
134  }
135 
136  return $result;
137  }
138 
146  // Add possible dependencies for selected languages
147  $dependencies = array();
148  foreach ($languages as $language) {
149  $dependencies = array_merge($dependencies, $this->locales->getLocaleDependencies($language));
150  }
151  if (count($dependencies)) {
152  $languages = array_unique(array_merge($languages, $dependencies));
153  }
154 
155  $dir = count($languages) - count($this->selectedLanguages);
156  $diff = $dir < 0 ? array_diff($this->selectedLanguages, $languages) : array_diff($languages, $this->selectedLanguages);
157 
158  \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Configuration\\ConfigurationManager')->setLocalConfigurationValueByPath(
159  $this->configurationPath,
160  array('availableLanguages' => $languages)
161  );
162 
163  return array(
164  'success' => count($diff) > 0,
165  'dir' => $dir,
166  'diff' => array_values($diff),
167  'languages' => $languages
168  );
169  }
170 }
injectObjectManager(\TYPO3\CMS\Extbase\Object\ObjectManager $objectManager)
if($list_of_literals) if(!empty($literals)) if(!empty($literals)) $result
Analyse literals to prepend the N char to them if their contents aren&#39;t numeric.
injectLocales(\TYPO3\CMS\Core\Localization\Locales $locales)
if(!defined('TYPO3_MODE')) $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_userauth.php']['logoff_pre_processing'][]