TYPO3 CMS  TYPO3_7-6
TranslationConfigurationProvider.php
Go to the documentation of this file.
1 <?php
3 
4 /*
5  * This file is part of the TYPO3 CMS project.
6  *
7  * It is free software; you can redistribute it and/or modify it under
8  * the terms of the GNU General Public License, either version 2
9  * of the License, or any later version.
10  *
11  * For the full copyright and license information, please read the
12  * LICENSE.txt file that was distributed with this source code.
13  *
14  * The TYPO3 project - inspiring people to share!
15  */
16 
21 
26 {
30  protected function getDatabaseConnection()
31  {
32  return $GLOBALS['TYPO3_DB'];
33  }
34 
38  protected function getLanguageService()
39  {
40  return $GLOBALS['LANG'];
41  }
42 
53  public function getSystemLanguages($pageId = 0)
54  {
55  $modSharedTSconfig = BackendUtility::getModTSconfig($pageId, 'mod.SHARED');
56 
57  // default language and "all languages" are always present
58  $languages = [
59  // 0: default language
60  0 => [
61  'uid' => 0,
62  'title' => $this->getDefaultLanguageLabel($modSharedTSconfig),
63  'ISOcode' => 'DEF',
64  'flagIcon' => $this->getDefaultLanguageFlag($modSharedTSconfig),
65  ],
66  // -1: all languages
67  -1 => [
68  'uid' => -1,
69  'title' => $this->getLanguageService()->getLL('multipleLanguages'),
70  'ISOcode' => 'DEF',
71  'flagIcon' => 'flags-multiple',
72  ],
73  ];
74 
75  // add the additional languages from database records
76  $languageRecords = $this->getDatabaseConnection()->exec_SELECTgetRows('*', 'sys_language', '');
77  foreach ($languageRecords as $languageRecord) {
78  $languages[$languageRecord['uid']] = $languageRecord;
79  // @todo: this should probably resolve language_isocode too and throw a deprecation if not filled
80  if ($languageRecord['static_lang_isocode'] && ExtensionManagementUtility::isLoaded('static_info_tables')) {
81  $staticLangRow = BackendUtility::getRecord('static_languages', $languageRecord['static_lang_isocode'], 'lg_iso_2');
82  if ($staticLangRow['lg_iso_2']) {
83  $languages[$languageRecord['uid']]['ISOcode'] = $staticLangRow['lg_iso_2'];
84  }
85  }
86  if ($languageRecord['flag'] !== '') {
87  $languages[$languageRecord['uid']]['flagIcon'] = 'flags-' . $languageRecord['flag'];
88  }
89  }
90  return $languages;
91  }
92 
104  public function translationInfo($table, $uid, $languageUid = 0, array $row = null, $selFieldList = '')
105  {
106  if (!$GLOBALS['TCA'][$table] || !$uid) {
107  return 'No table "' . $table . '" or no UID value';
108  }
109  if ($row === null) {
110  $row = BackendUtility::getRecordWSOL($table, $uid);
111  }
112  if (!is_array($row)) {
113  return 'Record "' . $table . '_' . $uid . '" was not found';
114  }
115  $translationTable = $this->getTranslationTable($table);
116  if ($translationTable === '') {
117  return 'Translation is not supported for this table!';
118  }
119  if ($translationTable === $table && $row[$GLOBALS['TCA'][$table]['ctrl']['languageField']] > 0) {
120  return 'Record "' . $table . '_' . $uid . '" seems to be a translation already (has a language value "' . $row[$GLOBALS['TCA'][$table]['ctrl']['languageField']] . '", relation to record "' . $row[$GLOBALS['TCA'][$table]['ctrl']['transOrigPointerField']] . '")';
121  }
122  if ($translationTable === $table && $row[$GLOBALS['TCA'][$table]['ctrl']['transOrigPointerField']] != 0) {
123  return 'Record "' . $table . '_' . $uid . '" seems to be a translation already (has a relation to record "' . $row[$GLOBALS['TCA'][$table]['ctrl']['transOrigPointerField']] . '")';
124  }
125  // Look for translations of this record, index by language field value:
126  if (!$selFieldList) {
127  $selFieldList = 'uid,' . $GLOBALS['TCA'][$translationTable]['ctrl']['languageField'];
128  }
129  $where = $GLOBALS['TCA'][$translationTable]['ctrl']['transOrigPointerField'] . '=' . (int)$uid .
130  ' AND pid=' . (int)($table === 'pages' ? $row['uid'] : $row['pid']) .
131  ' AND ' . $GLOBALS['TCA'][$translationTable]['ctrl']['languageField'] . (! $languageUid ? '>0' : '=' . (int)$languageUid) .
132  BackendUtility::deleteClause($translationTable) .
134  $translationRecords = $this->getDatabaseConnection()->exec_SELECTgetRows($selFieldList, $translationTable, $where);
135  $translations = [];
136  $translationsErrors = [];
137  foreach ($translationRecords as $translationRecord) {
138  if (!isset($translations[$translationRecord[$GLOBALS['TCA'][$translationTable]['ctrl']['languageField']]])) {
139  $translations[$translationRecord[$GLOBALS['TCA'][$translationTable]['ctrl']['languageField']]] = $translationRecord;
140  } else {
141  $translationsErrors[$translationRecord[$GLOBALS['TCA'][$translationTable]['ctrl']['languageField']]][] = $translationRecord;
142  }
143  }
144  return [
145  'table' => $table,
146  'uid' => $uid,
147  'CType' => $row['CType'],
148  'sys_language_uid' => $row[$GLOBALS['TCA'][$table]['ctrl']['languageField']],
149  'translation_table' => $translationTable,
150  'translations' => $translations,
151  'excessive_translations' => $translationsErrors
152  ];
153  }
154 
161  public function getTranslationTable($table)
162  {
163  return $this->isTranslationInOwnTable($table) ? $table : $this->foreignTranslationTable($table);
164  }
165 
172  public function isTranslationInOwnTable($table)
173  {
174  return $GLOBALS['TCA'][$table]['ctrl']['languageField'] && $GLOBALS['TCA'][$table]['ctrl']['transOrigPointerField'] && !$GLOBALS['TCA'][$table]['ctrl']['transOrigPointerTable'];
175  }
176 
183  public function foreignTranslationTable($table)
184  {
185  $translationTable = $GLOBALS['TCA'][$table]['ctrl']['transForeignTable'];
186  if (
187  !$translationTable ||
188  !$GLOBALS['TCA'][$translationTable] ||
189  !$GLOBALS['TCA'][$translationTable]['ctrl']['languageField'] ||
190  !$GLOBALS['TCA'][$translationTable]['ctrl']['transOrigPointerField'] ||
191  $GLOBALS['TCA'][$translationTable]['ctrl']['transOrigPointerTable'] !== $table
192  ) {
193  $translationTable = '';
194  }
195  return $translationTable;
196  }
197 
202  protected function getDefaultLanguageFlag(array $modSharedTSconfig)
203  {
204  if (strlen($modSharedTSconfig['properties']['defaultLanguageFlag'])) {
205  // fallback "old iconstyles"
206  if (preg_match('/\\.gif$/', $modSharedTSconfig['properties']['defaultLanguageFlag'])) {
207  $modSharedTSconfig['properties']['defaultLanguageFlag'] = str_replace('.gif', '', $modSharedTSconfig['properties']['defaultLanguageFlag']);
208  }
209  $defaultLanguageFlag = 'flags-' . $modSharedTSconfig['properties']['defaultLanguageFlag'];
210  } else {
211  $defaultLanguageFlag = 'empty-empty';
212  }
213  return $defaultLanguageFlag;
214  }
215 
220  protected function getDefaultLanguageLabel(array $modSharedTSconfig)
221  {
222  if (strlen($modSharedTSconfig['properties']['defaultLanguageLabel'])) {
223  $defaultLanguageLabel = $modSharedTSconfig['properties']['defaultLanguageLabel'] . ' (' . $this->getLanguageService()->sl('LLL:EXT:lang/locallang_mod_web_list.xlf:defaultLanguage') . ')';
224  } else {
225  $defaultLanguageLabel = $this->getLanguageService()->sl('LLL:EXT:lang/locallang_mod_web_list.xlf:defaultLanguage');
226  }
227  return $defaultLanguageLabel;
228  }
229 }
translationInfo($table, $uid, $languageUid=0, array $row=null, $selFieldList='')
$uid
Definition: server.php:38
static getRecord($table, $uid, $fields=' *', $where='', $useDeleteClause=true)
if(TYPO3_MODE==='BE') $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_tsfebeuserauth.php']['frontendEditingController']['default']
static getRecordWSOL($table, $uid, $fields=' *', $where='', $useDeleteClause=true, $unsetMovePointers=false)
static deleteClause($table, $tableAlias='')