EXT: languagevisibility
License: GNU GPL, Version 2
Repository: https://gitlab.sgalinski.de/typo3/languagevisibility
TYPO3 version: >9.5
Introduction
This extension changes the language handling 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 introduces a new concept „visibility“:
That controls when an 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 elements
new BE module 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 language behavior in the FE:
config.sys_language_mode = ignore
config.sys_language_overlay = 1
//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:
- Extend your table with the required field and TCA
- Register your table to the languagevisibility core
- 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',
'renderType' => 'languageVisibility'
]
]
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 persistence 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);
}