l10nFallback.patch

Stefan Galinski, 2012-03-22 15:10

Download (9.66 KB)

View differences:

typo3_src-4.6.6/t3lib/class.t3lib_page.php 2012-03-14 23:09:25.849865258 +0100
247 247
	function getPageOverlay($pageInput, $lUid = -1) {
248 248

  
249 249
			// Initialize:
250
		$specialLanguageRequested = TRUE;
250 251
		if ($lUid < 0) {
252
			$specialLanguageRequested = FALSE;
251 253
			$lUid = $this->sys_language_uid;
252 254
		}
253 255
		$row = NULL;
......
275 277
			}
276 278

  
277 279
			if (count($fieldArr)) {
280
				$orFallbackLanguage = '';
281
				if (!$specialLanguageRequested && !in_array($GLOBALS['TSFE']->sys_language_fallback, array(0, $lUid))) {
282
					$orFallbackLanguage = ' OR sys_language_uid = ' . $GLOBALS['TSFE']->sys_language_fallback;
283
				}
284

  
278 285
				/*
279 286
					NOTE to enabledFields('pages_language_overlay'):
280 287
					Currently the showHiddenRecords of TSFE set will allow pages_language_overlay records to be selected as they are child-records of a page.
......
282 289
				*/
283 290

  
284 291
					// Selecting overlay record:
292
				$fieldArr[] = 'sys_language_uid';
285 293
				$res = $GLOBALS['TYPO3_DB']->exec_SELECTquery(
286 294
					implode(',', $fieldArr),
287 295
					'pages_language_overlay',
288 296
					'pid=' . intval($page_id) . '
289
								AND sys_language_uid=' . intval($lUid) .
297
								AND (sys_language_uid=' . intval($lUid) . $orFallbackLanguage . ')'.
290 298
					$this->enableFields('pages_language_overlay'),
291 299
					'',
292 300
					'',
293
					'1'
301
					2
294 302
				);
295
				$row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res);
303

  
304
					// Prefer the lUid row instead
305
				$row = NULL;
306
				while (($temp = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res))) {
307
					$row = $temp;
308
					if ($row['sys_language_uid'] == $lUid) {
309
						break;
310
					}
311
				}
296 312
				$GLOBALS['TYPO3_DB']->sql_free_result($res);
297 313
				$this->versionOL('pages_language_overlay', $row);
298 314

  
......
316 332
	}
317 333

  
318 334
	/**
335
	 * Creates a language overlay for records that are stored inside tables that containing the
336
	 * translation informations itself. In opposite to getRecordOverlay this method checks the
337
	 * sys_language_fallback variable if the fetched record wasn't overlaid.
338
	 *
339
	 * @param string $table
340
	 * @param array $row Record to overlay. Must containt uid, pid and $table]['ctrl']['languageField']
341
	 * @param integer $sys_language_content Pointer to the sys_language uid for content on the site.
342
	 * @param string $OLmode Overlay mode. If "hideNonTranslated" then records without translation will not be returned un-translated but unset (and return value is FALSE)
343
	 * @return mixed Returns the input record, possibly overlaid with a translation. But if $OLmode is "hideNonTranslated" then it will return FALSE if no translation is found.
344
	 */
345
	public function getRecordOverlayWithFallback($table, $row, $sys_language_content, $OLmode = '') {
346
		$fallback = $GLOBALS['TSFE']->sys_language_fallback;
347
		$record = $this->getRecordOverlay($table, $row, $sys_language_content, $OLmode);
348
		if ($fallback && $sys_language_content && $fallback !== $sys_language_content) {
349
			if (!(is_array($record) && isset($record['_LOCALIZED_UID']))) {
350
				$record = $this->getRecordOverlay($table, $row, $fallback, $OLmode);
351
			}
352
		}
353

  
354
		return $record;
355
	}
356

  
357
	/**
319 358
	 * Creates language-overlay for records in general (where translation is found in records from the same table)
320 359
	 *
321 360
	 * @param	string		Table name
typo3_src-4.6.6/typo3/sysext/cms/tslib/class.tslib_fe.php 2012-03-14 23:03:30.959866193 +0100
170 170
	var $sys_language_uid=0;			// Site language, 0 (zero) is default, int+ is uid pointing to a sys_language record. Should reflect which language menus, templates etc is displayed in (master language) - but not necessarily the content which could be falling back to default (see sys_language_content)
171 171
	var $sys_language_mode='';			// Site language mode for content fall back.
172 172
	var $sys_language_content=0;		// Site content selection uid (can be different from sys_language_uid if content is to be selected from a fall-back language. Depends on sys_language_mode)
173
	public $sys_language_fallback = 0;		// Almost the same as sys_language_content, but can differ if a content_fallback mode was requested
173 174
	var $sys_language_contentOL=0;		// Site content overlay flag; If set - and sys_language_content is > 0 - , records selected will try to look for a translation pointing to their uid. (If configured in [ctrl][languageField] / [ctrl][transOrigP...]
174 175
	var $sys_language_isocode = '';		// Is set to the iso code of the sys_language_content if that is properly defined by the sys_language record representing the sys_language_uid. (Requires the extension "static_info_tables")
175 176

  
......
2261 2262
		}
2262 2263

  
2263 2264
			// Get values from TypoScript:
2264
		$this->sys_language_uid = $this->sys_language_content = intval($this->config['config']['sys_language_uid']);
2265
		$this->sys_language_uid = $this->sys_language_content = $this->sys_language_fallback = intval($this->config['config']['sys_language_uid']);
2265 2266
		list($this->sys_language_mode,$sys_language_content) = t3lib_div::trimExplode(';', $this->config['config']['sys_language_mode']);
2266 2267
		$this->sys_language_contentOL = $this->config['config']['sys_language_overlay'];
2267 2268

  
......
2292 2293
								$fallBackOrder = t3lib_div::intExplode(',', $sys_language_content);
2293 2294
								foreach($fallBackOrder as $orderValue)	{
2294 2295
									if (!strcmp($orderValue,'0') || count($this->sys_page->getPageOverlay($this->id, $orderValue)))	{
2295
										$this->sys_language_content = $orderValue;	// Setting content uid (but leaving the sys_language_uid)
2296
											// Setting content uid (but leaving the sys_language_uid)
2297
										$this->sys_language_content = $this->sys_language_fallback = $orderValue;
2298
										$this->page = $this->sys_page->getPageOverlay($this->page, $orderValue);
2296 2299
										break;
2297 2300
									}
2298 2301
								}
......
2302 2305
							break;
2303 2306
							default:
2304 2307
									// Default is that everything defaults to the default language...
2305
								$this->sys_language_uid = $this->sys_language_content = 0;
2308
								$this->sys_language_uid = $this->sys_language_fallback = $this->sys_language_content = 0;
2306 2309
							break;
2307 2310
						}
2308 2311
					}
......
2310 2313
			} else {
2311 2314
					// Setting sys_language if an overlay record was found (which it is only if a language is used)
2312 2315
				$this->page = $this->sys_page->getPageOverlay($this->page, $this->sys_language_uid);
2316

  
2317
				if ($this->sys_language_mode === 'content_fallback') {
2318
					$fallBackOrder = t3lib_div::intExplode(',', $sys_language_content);
2319
					foreach ($fallBackOrder as $languageId) {
2320
						if (!$languageId) {
2321
							continue;
2322
						}
2323

  
2324
						$overlaidPage = $this->sys_page->getPageOverlay($this->id, $languageId);
2325
						if (count($overlaidPage)) {
2326
							$this->sys_language_fallback = $languageId;
2327
							break;
2328
						}
2329
					}
2330
				}
2313 2331
			}
2314 2332
		}
2315 2333

  
typo3_src-4.6.6/typo3/sysext/cms/tslib/content/class.tslib_content_content.php 2012-03-14 23:03:57.439865542 +0100
118 118
							if ($conf['table'] == 'pages') {
119 119
								$row = $GLOBALS['TSFE']->sys_page->getPageOverlay($row);
120 120
							} else {
121
								$row = $GLOBALS['TSFE']->sys_page->getRecordOverlay($conf['table'], $row, $GLOBALS['TSFE']->sys_language_content, $GLOBALS['TSFE']->sys_language_contentOL);
121
								$row = $GLOBALS['TSFE']->sys_page->getRecordOverlayWithFallback($conf['table'], $row, $GLOBALS['TSFE']->sys_language_content, $GLOBALS['TSFE']->sys_language_contentOL);
122 122
							}
123 123
						}
124 124

  
typo3_src-4.6.6/typo3/sysext/cms/tslib/content/class.tslib_content_records.php 2012-03-14 23:04:30.799864229 +0100
87 87

  
88 88
					// Language overlay:
89 89
				if (is_array($row) && $GLOBALS['TSFE']->sys_language_contentOL) {
90
					$row = $GLOBALS['TSFE']->sys_page->getRecordOverlay(
90
					$row = $GLOBALS['TSFE']->sys_page->getRecordOverlayWithFallback(
91 91
						$val['table'],
92 92
						$row,
93 93
						$GLOBALS['TSFE']->sys_language_content,
typo3_src-4.6.6/typo3/sysext/extbase/Classes/Persistence/Storage/Typo3DbBackend.php 2012-03-14 23:04:15.999869947 +0100
986 986
			} elseif(isset($GLOBALS['TCA'][$tableName]['ctrl']['languageField']) && $GLOBALS['TCA'][$tableName]['ctrl']['languageField'] !== '') {
987 987
				if (in_array($row[$GLOBALS['TCA'][$tableName]['ctrl']['languageField']], array(-1,0))) {
988 988
					$overlayMode = ($languageMode === 'strict') ? 'hideNonTranslated' : '';
989
					$row = $this->pageSelectObject->getRecordOverlay($tableName, $row, $languageUid, $overlayMode);
989
					$row = $this->pageSelectObject->getRecordOverlayWithFallback($tableName, $row, $languageUid, $overlayMode);
990 990
				}
991 991
			}
992 992
			if ($row !== NULL && is_array($row)) {