1eb1b2820b11e5fd175747d335a5ee26d3a8bbe7
2 /***************************************************************
5 * (c) 2006-2009 Kasper Skaarhoj (kasperYYYY@typo3.com)
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.
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.
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.
25 * This copyright notice MUST APPEAR in all copies of the script!
26 ***************************************************************/
28 * Contains translation tools
32 * @author Kasper Skaarhoj <kasperYYYY@typo3.com>
35 * [CLASS/FUNCTION INDEX of SCRIPT]
39 * 67: class t3lib_transl8tools
40 * 74: function getSystemLanguages($page_id=0,$backPath='')
41 * 132: function translationInfo($table,$uid,$sys_language_uid=0)
42 * 187: function getTranslationTable($table)
43 * 197: function isTranslationInOwnTable($table)
44 * 209: function foreignTranslationTable($table)
47 * (This index is automatically created/updated by the extension "extdeveval")
61 * Contains translation tools
63 * @author Kasper Skaarhoj <kasperYYYY@typo3.com>
67 class t3lib_transl8tools
{
70 * Returns array of system languages
71 * @param integer page id (only used to get TSconfig configuration setting flag and label for default language)
72 * @param string Backpath for flags
75 function getSystemLanguages($page_id=0,$backPath='') {
78 // Icons and language titles:
79 t3lib_div
::loadTCA('sys_language');
80 $flagAbsPath = t3lib_div
::getFileAbsFileName($TCA['sys_language']['columns']['flag']['config']['fileFolder']);
81 $flagIconPath = $backPath.'../'.substr($flagAbsPath, strlen(PATH_site
));
83 $modSharedTSconfig = t3lib_BEfunc
::getModTSconfig($page_id, 'mod.SHARED');
84 $languageIconTitles = array();
87 $languageIconTitles[0] = array(
89 'title' => strlen ($modSharedTSconfig['properties']['defaultLanguageLabel']) ?
$modSharedTSconfig['properties']['defaultLanguageLabel'].' ('.$LANG->getLL('defaultLanguage').')' : $LANG->getLL('defaultLanguage'),
91 'flagIcon' => strlen($modSharedTSconfig['properties']['defaultLanguageFlag']) && @is_file
($flagAbsPath.$modSharedTSconfig['properties']['defaultLanguageFlag']) ?
$flagIconPath.$modSharedTSconfig['properties']['defaultLanguageFlag'] : null,
94 // Set "All" language:
95 $languageIconTitles[-1]=array(
97 'title' => $LANG->getLL('multipleLanguages'),
99 'flagIcon' => $flagIconPath.'multi-language.gif',
102 // Find all system languages:
103 $sys_languages = $GLOBALS['TYPO3_DB']->exec_SELECTgetRows(
108 foreach($sys_languages as $row) {
109 $languageIconTitles[$row['uid']] = $row;
111 if ($row['static_lang_isocode'] && t3lib_extMgm
::isLoaded('static_info_tables')) {
112 $staticLangRow = t3lib_BEfunc
::getRecord('static_languages',$row['static_lang_isocode'],'lg_iso_2');
113 if ($staticLangRow['lg_iso_2']) {
114 $languageIconTitles[$row['uid']]['ISOcode'] = $staticLangRow['lg_iso_2'];
117 if (strlen ($row['flag'])) {
118 $languageIconTitles[$row['uid']]['flagIcon'] = @is_file
($flagAbsPath.$row['flag']) ?
$flagIconPath.$row['flag'] : '';
122 return $languageIconTitles;
126 * Information about translation for an element
127 * Will overlay workspace version of record too!
129 * @param string Table name
130 * @param integer Record uid
131 * @param integer Language uid. If zero, then all languages are selected.
132 * @return array Array with information. Errors will return string with message.
134 function translationInfo($table,$uid,$sys_language_uid=0) {
137 if ($TCA[$table] && $uid) {
138 t3lib_div
::loadTCA($table);
140 $row = t3lib_BEfunc
::getRecordWSOL($table,$uid);
141 if (is_array($row)) {
142 $trTable = $this->getTranslationTable($table);
144 if ($trTable!==$table ||
$row[$TCA[$table]['ctrl']['languageField']] <= 0) {
145 if ($trTable!==$table ||
$row[$TCA[$table]['ctrl']['transOrigPointerField']] == 0) {
147 // Look for translations of this record, index by language field value:
148 $translationsTemp = $GLOBALS['TYPO3_DB']->exec_SELECTgetRows(
149 'uid,'.$TCA[$trTable]['ctrl']['languageField'],
151 '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...
152 ' AND '.$TCA[$trTable]['ctrl']['languageField'].(!$sys_language_uid ?
'>0' : '='.intval($sys_language_uid)).
153 ' AND '.$TCA[$trTable]['ctrl']['transOrigPointerField'].'='.intval($uid).
154 t3lib_BEfunc
::deleteClause($trTable).
155 t3lib_BEfunc
::versioningPlaceholderClause($trTable)
158 $translations = array();
159 $translations_errors = array();
160 foreach($translationsTemp as $r) {
161 if (!isset($translations[$r[$TCA[$trTable]['ctrl']['languageField']]])) {
162 $translations[$r[$TCA[$trTable]['ctrl']['languageField']]] = $r;
164 $translations_errors[$r[$TCA[$trTable]['ctrl']['languageField']]][] = $r;
171 'sys_language_uid' => $row[$TCA[$table]['ctrl']['languageField']],
172 'translation_table' => $trTable,
173 'translations' => $translations,
174 'excessive_translations' => $translations_errors
176 } else return 'Record "'.$table.'_'.$uid.'" seems to be a translation already (has a relation to record "'.$row[$TCA[$table]['ctrl']['transOrigPointerField']].'")';
177 } 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']].'")';
178 } else return 'Translation is not supported for this table!';
179 } else return 'Record "'.$table.'_'.$uid.'" was not found';
180 } else return 'No table "'.$table.'" or no UID value';
184 * Returns the table in which translations for input table is found.
186 * @param [type] $table: ...
189 function getTranslationTable($table) {
190 return $this->isTranslationInOwnTable($table) ?
$table : $this->foreignTranslationTable($table);
194 * Returns true, if the input table has localization enabled and done so with records from the same table
196 * @param [type] $table: ...
199 function isTranslationInOwnTable($table) {
202 return $TCA[$table]['ctrl']['languageField'] && $TCA[$table]['ctrl']['transOrigPointerField'] && !$TCA[$table]['ctrl']['transOrigPointerTable'];
206 * Returns foreign translation table, if any
208 * @param [type] $table: ...
211 function foreignTranslationTable($table) {
214 $trTable = $TCA[$table]['ctrl']['transForeignTable'];
216 if ($trTable && $TCA[$trTable] && $TCA[$trTable]['ctrl']['languageField'] && $TCA[$trTable]['ctrl']['transOrigPointerField'] && $TCA[$trTable]['ctrl']['transOrigPointerTable']===$table) {
223 if (defined('TYPO3_MODE') && $TYPO3_CONF_VARS[TYPO3_MODE
]['XCLASS']['t3lib/class.t3lib_transl8tools.php']) {
224 include_once($TYPO3_CONF_VARS[TYPO3_MODE
]['XCLASS']['t3lib/class.t3lib_transl8tools.php']);