2 namespace TYPO3\CMS\Lang\Domain\Repository
;
4 * This file is part of the TYPO3 CMS project.
6 * It is free software; you can redistribute it and/or modify it under
7 * the terms of the GNU General Public License, either version 2
8 * of the License, or any later version.
10 * For the full copyright and license information, please read the
11 * LICENSE.txt file that was distributed with this source code.
13 * The TYPO3 project - inspiring people to share!
19 * @author Sebastian Fischer <typo3@evoweb.de>
21 class LanguageRepository
{
24 * @var \TYPO3\CMS\Extbase\Object\ObjectManagerInterface
26 protected $objectManager;
31 protected $selectedLanguages = array();
34 * @var \TYPO3\CMS\Core\Localization\Locales
41 protected $languages = array();
46 protected $configurationPath = 'EXTCONF/lang';
49 * Constructor of the language repository
51 public function __construct() {
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())
64 * Injects the object manager
66 * @param \TYPO3\CMS\Extbase\Object\ObjectManager $objectManager
69 public function injectObjectManager(\TYPO3\CMS\Extbase\
Object\ObjectManager
$objectManager) {
70 $this->objectManager
= $objectManager;
76 * @param \TYPO3\CMS\Core\Localization\Locales $locales
79 public function injectLocales(\TYPO3\CMS\Core\Localization\Locales
$locales) {
80 $this->locales
= $locales;
84 * Returns all objects of this repository.
88 public function findAll() {
89 if (!count($this->languages
)) {
90 $languages = $this->locales
->getLanguages();
91 array_shift($languages);
93 foreach ($languages as $locale => $language) {
94 $label = htmlspecialchars($GLOBALS['LANG']->sL('LLL:EXT:setup/mod/locallang.xlf:lang_' . $locale));
96 $label = htmlspecialchars($language);
99 $this->languages
[$locale] = $this->objectManager
->get(
100 'TYPO3\CMS\Lang\Domain\Model\Language',
103 in_array($locale, $this->selectedLanguages
)
107 usort($this->languages
, function($a, $b) {
108 /** @var $a \TYPO3\CMS\Lang\Domain\Model\Language */
109 /** @var $b \TYPO3\CMS\Lang\Domain\Model\Language */
110 if ($a->getLanguage() == $b->getLanguage()) {
113 return $a->getLanguage() < $b->getLanguage() ?
-1 : 1;
117 return $this->languages
;
121 * Find selected languages
125 public function findSelected() {
126 $languages = $this->findAll();
129 /** @var $language \TYPO3\CMS\Lang\Domain\Model\Language */
130 foreach ($languages as $language) {
131 if ($language->getSelected()) {
132 $result[] = $language;
140 * Update selected languages
142 * @param array $languages
145 public function updateSelectedLanguages($languages) {
146 // Add possible dependencies for selected languages
147 $dependencies = array();
148 foreach ($languages as $language) {
149 $dependencies = array_merge($dependencies, $this->locales
->getLocaleDependencies($language));
151 if (count($dependencies)) {
152 $languages = array_unique(array_merge($languages, $dependencies));
155 $dir = count($languages) - count($this->selectedLanguages
);
156 $diff = $dir < 0 ?
array_diff($this->selectedLanguages
, $languages) : array_diff($languages, $this->selectedLanguages
);
158 \TYPO3\CMS\Core\Utility\GeneralUtility
::makeInstance('TYPO3\\CMS\\Core\\Configuration\\ConfigurationManager')->setLocalConfigurationValueByPath(
159 $this->configurationPath
,
160 array('availableLanguages' => $languages)
164 'success' => count($diff) > 0,
166 'diff' => array_values($diff),
167 'languages' => $languages