sgalinski/languagevisibility

Multi level language fallback for TYPO3 projects

Installs: 44

Dependents: 0

Suggesters: 0

Type:typo3-cms-extension

2.1.11 2019-07-10 19:31 UTC

README

This extension changes the languagehandling in TYPO3 to fit enterprise needs (a more flexible - One Tree concept):

  • Multilanguage Fallbacks
  • Individual per language configuration of the behaviour
  • Languagevisibility concept for pages, content, news that enables:
    • Hide or Show several elements only in desired language
    • Create new elements even by pure translators
  • Introduce new FCE localisationmode (translation of FCE with overlay records)

Explanations

The extension introduce a new concept „visibility“:

That controls when a element is visible in a certain language , currently there are 4 visibility modi:

  • show if translated
  • show if translation in fallback-order exists
  • show always (even if no translation -> then default language is forced to be shown, fallback is not considered)
  • show never (even if a translation exist) this can be controled global (=per language) and local (=per element)

This can be set for every supported record in TYPO3. Therefore it is possible to have elements that are only visible in some languages.

new settings for languages:

  • fallback order can be defined in a user friendly way with a multi select. You are able to select x fallback-languages for each language
  • default visibility for pages
  • default visibility for news
  • default visibility for elements

new BE Modul to check visibility

Introduce new FCE mode with normal overlay records:

<langDisable>1</langDisable><langDatabaseOverlay>1</langDatabaseOverlay> enables independent translation in workspaces.

Support for TCA configuration „l10n_mode“ in overlaying process

Configuration

Use this TYPOScript Code to set up your languagebehavior in the FE:

config.sys_language_mode = ignore
config.sys_language_overlay = hideNonTranslated

//normal language configuration:
config.sys_language_uid = 0
config.language = en
config.htmlTag_langKey = en
config.locale_all = en_GB.utf8

//deutsch
 [globalVar = GP:L=1]
  config.sys_language_uid = 1
         config.language = de
       config.htmlTag_langKey = de
        config.locale_all = de_DE.utf8
[global]
...

Use languagevisibility for own records

There are 3 steps to take:

  1. Extend your table with the required field and TCA
  2. Register your table to the languagevisibility Core
  3. Use the correct code so that the desired functionality happened

1. Extend your table

Add this definition to your table TCA configuration:

'tx_languagevisibility_visibility' => [
	'exclude' => 1,
	'label' => 'LLL:EXT:languagevisibility/locallang_db.xlf:pages.tx_languagevisibility_visibility',
	'config' => [
		'type' => 'user',
		'size' => '30',
		'userFunc' => 'tx_languagevisibility_fieldvisibility->user_fieldvisibility',
		'default' => '',
	]
]

And to ext_tables.sql add:

tx_languagevisibility_visibility text NOT NULL

2. Register your table

Use the existing registration Hook :

$GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['languagevisibility']['recordElementSupportedTables'][<table>]= [];

(this will handle your table like a default record element. If you need more control you can also register your own visibility element class)

3. Get your records the right way

extbase support:

For normal extbase collections it should work out of the box, since extbase used TYPO3 Core overlay methods

For some versions you need a patch in extbase TYPO3 persitence class:

protected function doLanguageAndWorkspaceOverlay(Tx_Extbase_Persistence_QOM_SourceInterface $source, array $rows, $languageUid = NULL, $workspaceUid = NULL) {
                $overlayedRows = array();
                foreach ($rows as $row) {
+                       if (!isset($row['uid'])) {
+                                $overlayedRows[] = $row;
+                                continue;
+                        }
+
                        if (!($this->pageSelectObject instanceof t3lib_pageSelect)) {
                                if (TYPO3_MODE == 'FE') {
                                        if (is_object($GLOBALS['TSFE'])) {
@@ -986,7 +991,7 @@
                                        $row = $this->pageSelectObject->getRecordOverlay($tableName, $row, $languageUid, $overlayMode);
                                }
                        }
-                       if ($row !== NULL && is_array($row)) {
+                       if ($row !== NULL && is_array($row) && $row['uid']>0) {
                                $overlayedRows[] = $row;
                        }
                }
@@ -1064,4 +1069,4 @@
        }
}

For other use-cases you can use the API to check your records:

// get languagevisibility uid that is available (check for the correct uid to fall back to)
$table = '<tablename>';
$element = tx_languagevisibility_feservices::getElement($this->row['referenceid'], $table);
$language_uid = tx_languagevisibility_feservices::getOverlayLanguageIdForElement($element, $GLOBALS['TSFE']->sys_language_uid);

// get overlay record
if($language_uid > 0) {
        $this->row = tx_mvc_system_dbtools::getTYPO3RowOverlay($this->row, $table, $language_uid);
}