tt_address Datensätze in alternative Sprache übersetzen

Kategorie: TYPO3
Publikationsdatum: 31.05.2012
Hin und wieder ist es notwendig die Einträge aus der Tabelle tt_address übersetzen zu können. Zum Beispiel wird die Beschreibung zur Person in Deutsch anders lauten als in englischer Sprache. Somit ist eine Übersetzung notwendig.

Man könnte nun die bestehende Adress-Erweiterung umbauen oder eine eigene Erweiterung erstellen, welche die vorhandene Erweiterung ausbaut. Im folgenden Beispiel wird eine eigene Erweiterung erstellt.

Als erstes wird nun ein Ordner im Verzeichnis typo3conf mit dem Key der Erweiterung, zum Beispiel ttaddress_l18n, als Name angelegt. Innerhalb dieses Ordners wird nun folgende Struktur erstellt:

xclass/class.ux_tx_ttaddress_pi1.php
ext_emconf.php
ext_localconf.php
ext_tables.php
ext_tables.sql


Datei ext_emconf.php
PHP
  1. <?php
  2. $EM_CONF[$_EXTKEY] = array(
  3. 'title' => 'Titel der Extension',
  4. 'description' => 'Beschreibung der Extension',
  5. 'category' => 'misc',
  6. 'author' => 'Author', // Name des Authors
  7. 'author_email' => 'demo@extension.ch', // Email von Author
  8. 'shy' => '', // Versteckt
  9. 'dependencies' => 'tt_address', // Abhängig von
  10. 'conflicts' => '', // Probleme mit
  11. 'priority' => 'bottom',
  12. 'module' => '',
  13. 'state' => 'stable', // Status
  14. 'internal' => '',
  15. 'uploadfolder' => 0,
  16. 'createDirs' => '',
  17. 'modify_tables' => 'tt_address', // Welche Tabellen werden verändert
  18. 'clearCacheOnLoad' => 0,
  19. 'lockType' => '',
  20. 'author_company' => '',
  21. 'version' => '0.1.1',
  22. 'constraints' => array(
  23. 'depends' => array(
  24. 'tt_address' => '',
  25. 'php' => '5.2.0-0.0.0',
  26. 'typo3' => '4.3.0-0.0.0',
  27. ),
  28. 'conflicts' => array(
  29. ),
  30. 'suggests' => array(
  31. ),
  32. ),
  33. 'suggests' => array(
  34. ),
  35. '_md5_values_when_last_written' => '',
  36. );
  37. ?>

 

Datei ext_localconf.php

PHP
  1. <?php
  2. if (!defined ('TYPO3_MODE')) die ('Access denied.');
  3.  
  4. // XCLASS
  5. $TYPO3_CONF_VARS['FE']['XCLASS']['ext/tt_address/pi1/class.tx_ttaddress_pi1.php'] = t3lib_extMgm::extPath($_EXTKEY).'xclass/class.ux_tx_ttaddress_pi1.php';
  6. ?>

 

Datei ext_tables.php

PHP
  1. <?php
  2. if (!defined ('TYPO3_MODE')) die ('Access denied.');
  3.  
  4. $_extConfig = unserialize($GLOBALS["TYPO3_CONF_VARS"]["EXT"]["extConf"][$_EXTKEY]);
  5.  
  6. t3lib_div::loadTCA("tt_address");
  7.  
  8. $addCtrlAndOverride = array (
  9. 'sortby' => 'sorting',
  10. 'label_alt' => 'sys_language_uid',
  11. // Display Language after Label
  12. 'label_alt_force' => 0,
  13. 'languageField' => 'sys_language_uid',
  14. 'transOrigPointerField' => 'l18n_parent',
  15. 'transOrigDiffSourceField' => 'l18n_diffsource'
  16. );
  17.  
  18. /* add fields to ctrl list */
  19. $TCA['tt_address']['ctrl'] = array_merge($TCA['tt_address']['ctrl'],$addCtrlAndOverride);
  20. /* add fields to feInterface list */
  21. $TCA['tt_address']['feInterface']['fe_admin_fieldList'] .= ',sys_language_uid,l18n_parent,l18n_diffsource';
  22.  
  23.  
  24. $addTTAddressColumns = array (
  25. 'sys_language_uid' => array(
  26. 'exclude' => 1,
  27. 'label' => 'LLL:EXT:lang/locallang_general.xml:LGL.language',
  28. 'config' => array(
  29. 'type' => 'select',
  30. 'foreign_table' => 'sys_language',
  31. 'foreign_table_where' => 'ORDER BY sys_language.title',
  32. 'items' => array(
  33. array('LLL:EXT:lang/locallang_general.php:LGL.allLanguages', -1),
  34. array('LLL:EXT:lang/locallang_general.php:LGL.default_value', 0)
  35. )
  36. )
  37. ),
  38. 'l18n_parent' => array(
  39. 'displayCond' => 'FIELD:sys_language_uid:>:0',
  40. 'exclude' => 1,
  41. 'label' => 'LLL:EXT:lang/locallang_general.xml:LGL.l18n_parent',
  42. 'config' => array(
  43. 'type' => 'select',
  44. 'items' => array(
  45. array('', 0),
  46. ),
  47. 'foreign_table' => 'tt_address',
  48. 'foreign_table_where' => 'AND tt_address.pid=###CURRENT_PID### AND tt_address.sys_language_uid IN (-1,0)',
  49. )
  50. ),
  51. 'l18n_diffsource' => array(
  52. 'config' => array(
  53. 'type' => 'passthrough'
  54. )
  55. ),
  56. 'addressgroup' => array(
  57. // Do not show for a Translation
  58. 'l10n_mode' => 'exclude',
  59. //'l10n_mode' => 'mergeIfNotBlank',
  60. 'exclude' => 1,
  61. 'label' => 'LLL:EXT:tt_address/locallang_tca.xml:tt_address.addressgroup',
  62. 'config' => array(
  63. 'type' => 'select',
  64. 'form_type' => 'user',
  65. 'userFunc' => 'tx_ttaddress_treeview->displayGroupTree',
  66. 'treeView' => 1,
  67. 'foreign_table' => 'tt_address_group',
  68. 'size' => 5,
  69. 'autoSizeMax' => 25,
  70. 'minitems' => 0,
  71. 'maxitems' => 50,
  72. 'MM' => 'tt_address_group_mm',
  73. )
  74. )
  75.  
  76. );
  77.  
  78. /* add fields to TCA */
  79. t3lib_extMgm::addTCAcolumns('tt_address', $addTTAddressColumns);
  80. ?>

 

Datei ext_tables.sql

MySQL
  1. #
  2. # Table structure for table 'tt_address'
  3. #
  4.  
  5. CREATE TABLE tt_address (
  6. sorting int(10) DEFAULT '0' NOT NULL,
  7. sys_language_uid int(11) DEFAULT '0' NOT NULL,
  8. l18n_parent int(11) DEFAULT '0' NOT NULL,
  9. l18n_diffsource mediumblob NOT NULL
  10. );

Datei xclass/class.ux_tx_ttaddress_pi1.php
PHP
  1. <?php
  2. class ux_tx_ttaddress_pi1 extends tx_ttaddress_pi1 {
  3. /*
  4.   * override tt_address/pi1/class.tx_ttaddress_pi1.php->checkSorting
  5.   */
  6. function checkSorting($sortBy) {
  7. t3lib_div::loadTCA('tt_address');
  8. $validSortings = array_keys($GLOBALS['TCA']['tt_address']['columns']);
  9. $validSortings[] = 'sorting';
  10. if(!in_array($sortBy, $validSortings)) {
  11. $sortBy = 'name';
  12. }
  13. return $sortBy;
  14. }
  15.  
  16. /*
  17.   * override tt_address/pi1/class.tx_ttaddress_pi1.php->getSingleRecords
  18.   */
  19. function getSingleRecords() {
  20. $singleRecords = array();
  21. $uidList = $GLOBALS['TYPO3_DB']->cleanIntList(
  22. $this->conf['singleSelection']
  23. );
  24.  
  25. if(!empty($uidList) && !empty($this->conf['pidList'])) {
  26. $select = '*';
  27. $table = 'tt_address';
  28. // we try to get the default language entry (normal behaviour) or, if not possible, currently the needed language (fallback if no default language entry is available)
  29. $where = '(sys_language_uid IN (-1,0) OR (sys_language_uid = ' .$GLOBALS['TSFE']->sys_language_uid. ' AND l18n_parent = 0))';
  30. $where .= ' AND uid IN('.$uidList.') AND pid IN('.$this->conf['pidList'].')';
  31. // always (!) use TYPO3 default function for adding hidden = 0, deleted = 0, group and date statements
  32. if ($GLOBALS['TSFE']->sys_language_content==0) {
  33. $where .= $GLOBALS['TSFE']->sys_page->enableFields($table);
  34. }
  35. $order = '';
  36. $group = '';
  37. $limit = '';
  38. $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery($select, $table, $where, $group, $order, $limit);
  39.  
  40. while ($row=$GLOBALS ['TYPO3_DB']->sql_fetch_assoc($res) ){
  41. if ($GLOBALS['TSFE']->sys_language_content){
  42. //$row=$GLOBALS['TSFE']->sys_page->getRecordOverlay('tt_address',$row,$GLOBALS['TSFE']->sys_language_content,$GLOBALS['TSFE']->sys_language_contentOL);
  43. $row=$GLOBALS['TSFE']->sys_page->getRecordOverlay('tt_address',$row,$GLOBALS['TSFE']->sys_language_content,$GLOBALS['TSFE']->sys_language_mode=='strict'?'hideNonTranslated':'');
  44. }
  45. $singleRecords[$row['uid']] = $this->getGroupsForAddress($row);
  46. }
  47. }
  48.  
  49. return $singleRecords;
  50. }
  51.  
  52. /*
  53.   * override tt_address/pi1/class.tx_ttaddress_pi1.php->getRecordsFromGroups
  54.   */
  55. function getRecordsFromGroups() {
  56. $groupRecords = array();
  57.  
  58. // similar to t3lib_db::cleanIntList(), but we need the count for AND combination
  59. $groups = t3lib_div::intExplode(',',$this->conf['groupSelection']);
  60. $count = count($groups);
  61. $groupList = implode(',', $groups);
  62.  
  63. if(!empty($groupList) && !empty($this->conf['pidList'])) {
  64. if($this->conf['combination'] == 'AND') {
  65. // AND
  66. $res = $GLOBALS['TYPO3_DB']->sql_query(
  67. 'SELECT tt_address.*, COUNT(tt_address.uid) AS c '.
  68. 'FROM tt_address '.
  69. 'JOIN tt_address_group_mm AS tta_txagg_mm ON tt_address.uid = tta_txagg_mm.uid_local '.
  70. 'JOIN tt_address_group AS txagg ON txagg.uid = tta_txagg_mm.uid_foreign '.
  71. 'WHERE uid_foreign IN ('.$groupList.') '.
  72. $GLOBALS['TSFE']->sys_page->enableFields('tt_address').
  73. ' AND tt_address.pid IN('.$this->conf['pidList'].') '.
  74. // this line added by tt_address_l18n
  75. ' AND (tt_address.sys_language_uid IN (-1,0) OR (tt_address.sys_language_uid = ' .$GLOBALS['TSFE']->sys_language_uid. ' AND tt_address.l18n_parent = 0)) '.
  76. 'GROUP BY tt_address.uid '.
  77. 'HAVING c = '.$count.' '
  78. );
  79. } elseif($this->conf['combination'] == 'OR') {
  80. // OR
  81. $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery(
  82. 'DISTINCT tt_address.*',
  83. 'tt_address, tt_address_group_mm, tt_address_group',
  84. 'tt_address_group_mm.uid_foreign IN('.$groupList.
  85. ') AND tt_address.uid = tt_address_group_mm.uid_local '.
  86. $GLOBALS['TSFE']->sys_page->enableFields('tt_address').
  87. ' AND tt_address.pid IN('.$this->conf['pidList'].')'.
  88. // this line added by tt_address_l18n
  89. ' AND (tt_address.sys_language_uid IN (-1,0) OR (tt_address.sys_language_uid = ' .$GLOBALS['TSFE']->sys_language_uid. ' AND tt_address.l18n_parent = 0)) '
  90. );
  91. }
  92.  
  93. while($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) {
  94. if ($GLOBALS['TSFE']->sys_language_content){
  95. $row=$GLOBALS['TSFE']->sys_page->getRecordOverlay('tt_address',$row,$GLOBALS['TSFE']->sys_language_content,$GLOBALS['TSFE']->sys_language_mode=='strict'?'hideNonTranslated':'');
  96. }
  97. $groupRecords[$row['uid']] = $this->getGroupsForAddress($row);
  98. }
  99. }
  100.  
  101. return $groupRecords;
  102. }
  103. }
  104. ?>
Am Ende die Erweiterung noch installieren, fertig.
Stichwörter: tt_address, alternative Sprache
 
 
NACH OBEN