l10nFallback.patch

Stefan Galinski, 2012-03-28 13:30

Download (8.71 KB)

View differences:

t3lib/class.t3lib_page.php
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 && $OLmode !== 'hideNonTranslated') {
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
......
1356 1395
	include_once($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['XCLASS']['t3lib/class.t3lib_page.php']);
1357 1396
}
1358 1397

  
1359
?>
1398
?>
typo3/sysext/cms/tslib/class.tslib_fe.php
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

  
......
2270 2271
		}
2271 2272

  
2272 2273
			// Get values from TypoScript:
2273
		$this->sys_language_uid = $this->sys_language_content = intval($this->config['config']['sys_language_uid']);
2274
		$this->sys_language_uid = $this->sys_language_content = $this->sys_language_fallback = intval($this->config['config']['sys_language_uid']);
2274 2275
		list($this->sys_language_mode,$sys_language_content) = t3lib_div::trimExplode(';', $this->config['config']['sys_language_mode']);
2275 2276
		$this->sys_language_contentOL = $this->config['config']['sys_language_overlay'];
2276 2277

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

  
2326
				if ($this->sys_language_mode === 'content_fallback') {
2327
					$fallBackOrder = t3lib_div::intExplode(',', $sys_language_content);
2328
					foreach ($fallBackOrder as $languageId) {
2329
						if (!$languageId) {
2330
							continue;
2331
						}
2332

  
2333
						$overlaidPage = $this->sys_page->getPageOverlay($this->id, $languageId);
2334
						if (count($overlaidPage)) {
2335
							$this->sys_language_fallback = $languageId;
2336
							break;
2337
						}
2338
					}
2339
				}
2322 2340
			}
2323 2341
		}
2324 2342

  
typo3/sysext/cms/tslib/content/class.tslib_content_content.php
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/sysext/cms/tslib/content/class.tslib_content_records.php
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,
94
-