b637863220841da1463617ba6bfc9c78113dcc01
[Packages/TYPO3.CMS.git] / t3lib / class.t3lib_transl8tools.php
1 <?php
2 /***************************************************************
3 * Copyright notice
4 *
5 * (c) 2006 Kasper Skaarhoj (kasperYYYY@typo3.com)
6 * All rights reserved
7 *
8 * This script is part of the TYPO3 project. The TYPO3 project is
9 * free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
13 *
14 * The GNU General Public License can be found at
15 * http://www.gnu.org/copyleft/gpl.html.
16 * A copy is found in the textfile GPL.txt and important notices to the license
17 * from the author is found in LICENSE.txt distributed with these scripts.
18 *
19 *
20 * This script is distributed in the hope that it will be useful,
21 * but WITHOUT ANY WARRANTY; without even the implied warranty of
22 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23 * GNU General Public License for more details.
24 *
25 * This copyright notice MUST APPEAR in all copies of the script!
26 ***************************************************************/
27 /**
28 * Contains translation tools
29 *
30 * $Id: class.t3lib_loaddbgroup.php 1816 2006-11-26 00:43:24Z mundaun $
31 *
32 * @author Kasper Skaarhoj <kasperYYYY@typo3.com>
33 */
34 /**
35 * [CLASS/FUNCTION INDEX of SCRIPT]
36 *
37 */
38
39
40
41
42
43
44
45
46
47
48 /**
49 * Contains translation tools
50 *
51 * @author Kasper Skaarhoj <kasperYYYY@typo3.com>
52 * @package TYPO3
53 * @subpackage t3lib
54 */
55 class t3lib_transl8tools {
56
57
58 function getSystemLanguages($page_id=0,$backPath='') {
59 global $TCA,$LANG;
60
61 // Icons and language titles:
62 t3lib_div::loadTCA('sys_language');
63 $flagAbsPath = t3lib_div::getFileAbsFileName($TCA['sys_language']['columns']['flag']['config']['fileFolder']);
64 $flagIconPath = $backPath.'../'.substr($flagAbsPath, strlen(PATH_site));
65
66 $modSharedTSconfig = t3lib_BEfunc::getModTSconfig($page_id, 'mod.SHARED');
67 $languageIconTitles = array();
68
69 // Set default:
70 $languageIconTitles[0] = array(
71 'uid' => 0,
72 'title' => strlen ($modSharedTSconfig['properties']['defaultLanguageLabel']) ? $modSharedTSconfig['properties']['defaultLanguageLabel'].' ('.$LANG->getLL('defaultLanguage').')' : $LANG->getLL('defaultLanguage'),
73 'ISOcode' => 'DEF',
74 'flagIcon' => strlen($modSharedTSconfig['properties']['defaultLanguageFlag']) && @is_file($flagAbsPath.$modSharedTSconfig['properties']['defaultLanguageFlag']) ? $flagIconPath.$modSharedTSconfig['properties']['defaultLanguageFlag'] : null,
75 );
76
77 // Set "All" language:
78 $languageIconTitles[-1]=array(
79 'uid' => -1,
80 'title' => $LANG->getLL('multipleLanguages'),
81 'ISOcode' => 'DEF',
82 'flagIcon' => $flagIconPath.'multi-language.gif',
83 );
84
85 // Find all system languages:
86 $sys_languages = $GLOBALS['TYPO3_DB']->exec_SELECTgetRows(
87 '*',
88 'sys_language',
89 ''
90 );
91 foreach($sys_languages as $row) {
92 $languageIconTitles[$row['uid']] = $row;
93
94 if ($row['static_lang_isocode'] && t3lib_extMgm::isLoaded('static_info_tables')) {
95 $staticLangRow = t3lib_BEfunc::getRecord('static_languages',$row['static_lang_isocode'],'lg_iso_2');
96 if ($staticLangRow['lg_iso_2']) {
97 $languageIconTitles[$row['uid']]['ISOcode'] = $staticLangRow['lg_iso_2'];
98 }
99 }
100 if (strlen ($row['flag'])) {
101 $languageIconTitles[$row['uid']]['flagIcon'] = @is_file($flagAbsPath.$row['flag']) ? $flagIconPath.$row['flag'] : '';
102 }
103 }
104
105 return $languageIconTitles;
106 }
107
108 /**
109 * Initialization of the class.
110 */
111 function translationInfo($table,$uid,$sys_language_uid=0) {
112 global $TCA;
113
114 if ($TCA[$table] && $uid) {
115 t3lib_div::loadTCA($table);
116
117 $row = t3lib_BEfunc::getRecordWSOL($table,$uid);
118 if (is_array($row)) {
119 $trTable = $this->getTranslationTable($table);
120 if ($trTable) {
121 if ($trTable!==$table || $row[$TCA[$table]['ctrl']['languageField']] <= 0) {
122 if ($trTable!==$table || $row[$TCA[$table]['ctrl']['transOrigPointerField']] == 0) {
123
124 // Look for translations of this record, index by language field value:
125 $translationsTemp = $GLOBALS['TYPO3_DB']->exec_SELECTgetRows(
126 'uid,'.$TCA[$trTable]['ctrl']['languageField'],
127 $trTable,
128 'pid='.intval($table==='pages' ? $row['uid'] : $row['pid']). // Making exception for pages of course where the translations will always be ON the page, not on the level above...
129 ' AND '.$TCA[$trTable]['ctrl']['languageField'].(!$sys_language_uid ? '>0' : '='.intval($sys_language_uid)).
130 ' AND '.$TCA[$trTable]['ctrl']['transOrigPointerField'].'='.intval($uid).
131 t3lib_BEfunc::deleteClause($trTable).
132 t3lib_BEfunc::versioningPlaceholderClause($trTable)
133 );
134
135 $translations = array();
136 $translations_errors = array();
137 foreach($translationsTemp as $r) {
138 if (!isset($translations[$r[$TCA[$trTable]['ctrl']['languageField']]])) {
139 $translations[$r[$TCA[$trTable]['ctrl']['languageField']]] = $r;
140 } else {
141 $translations_errors[$r[$TCA[$trTable]['ctrl']['languageField']]][] = $r;
142 }
143 }
144
145 return array(
146 'table' => $table,
147 'uid' => $uid,
148 'sys_language_uid' => $row[$TCA[$table]['ctrl']['languageField']],
149 'translation_table' => $trTable,
150 'translations' => $translations,
151 'excessive_translations' => $translations_errors
152 );
153 } else return 'Record "'.$table.'_'.$uid.'" seems to be a translation already (has a relation to record "'.$row[$TCA[$table]['ctrl']['transOrigPointerField']].'")';
154 } else return 'Record "'.$table.'_'.$uid.'" seems to be a translation already (has a language value "'.$row[$TCA[$table]['ctrl']['languageField']].'", relation to record "'.$row[$TCA[$table]['ctrl']['transOrigPointerField']].'")';
155 } else return 'Translation is not supported for this table!';
156 } else return 'Record "'.$table.'_'.$uid.'" was not found';
157 } else return 'No table "'.$table.'" or no UID value';
158 }
159
160 /**
161 * Returns the table in which translations for input table is found.
162 */
163 function getTranslationTable($table) {
164 return $this->isTranslationInOwnTable($table) ? $table : $this->foreignTranslationTable($table);
165 }
166
167 /**
168 * Returns true, if the input table has localization enabled and done so with records from the same table
169 */
170 function isTranslationInOwnTable($table) {
171 global $TCA;
172
173 return $TCA[$table]['ctrl']['languageField'] && $TCA[$table]['ctrl']['transOrigPointerField'] && !$TCA[$table]['ctrl']['transOrigPointerTable'];
174 }
175
176 /**
177 * Returns foreign translation table, if any
178 */
179 function foreignTranslationTable($table) {
180 global $TCA;
181
182 $trTable = $TCA[$table]['ctrl']['transForeignTable'];
183
184 if ($trTable && $TCA[$trTable] && $TCA[$trTable]['ctrl']['languageField'] && $TCA[$trTable]['ctrl']['transOrigPointerField'] && $TCA[$trTable]['ctrl']['transOrigPointerTable']===$table) {
185 return $trTable;
186 }
187 }
188 }
189
190
191 if (defined('TYPO3_MODE') && $TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['t3lib/class.t3lib_transl8tools.php']) {
192 include_once($TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['t3lib/class.t3lib_transl8tools.php']);
193 }
194 ?>