TYPO3:如何在扩展中呈现翻译的内容

时间:2014-05-21 12:15:29

标签: typo3

我正在开发一个TYPO3 6.0插件,它将当前页面的子页面显示为标签。例如,在以下页面中,我的插件插入TabRoot

Example TYPO3 pages

如果请求TabRoot,插件的ActionController会在数据库中查找子页面标题和内容,并将所有收集的数据传递给Fluid模板。然后该页面呈现如下:

Tab selector functionality

有了JS,我总是根据选择隐藏/显示下面的内容。我的问题是我想根据当前语言选择显示子页面的 翻译内容 。我怎么能这样做?我用几种方法尝试过它,但它们都没有完美无缺。这些是我尝试过的方法:


使用RECORDS 此方法不受所选语言的影响,它始终以默认语言返回内容:

//Get the ids of the parts of the page

$select_fields = "uid";
$from_table = "tt_content";
$where_clause = 'pid = ' . $pageId;
$res = $GLOBALS['TYPO3_DB']->exec_SELECTquery(
      $select_fields,
      $from_table,
      $where_clause,
      $groupBy='',
      $orderBy='sorting',
      $limit=''
);

$ids = '';
$firstIteration = true;
while ( $row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc( $res ) ) {
    if (!$firstIteration) $ids .= ",";
    $ids .= $row ['uid'];

    $firstIteration = false;
}
$GLOBALS['TYPO3_DB']->sql_free_result( $res );

//Render the parts of the page

$conf ['tables'] = 'tt_content';
$conf ['source'] = $ids;
$conf ['dontCheckPid'] = 1;
$content = $this->cObj->cObjGetSingle ( 'RECORDS', $conf );

使用CONTENTS 根据TYPO3: How to render localized tt_content in own extension,这是执行此操作的方法,但对我来说,这也会返回使用默认语言呈现的内容。它不受语言变化的影响。

$conf = array(
    'table' => 'tt_content',
    'select.' => array(
            'pidInList' => $pageId,
            'orderBy'  => 'sorting',
            'languageField' => 'sys_language_uid'
    )
);
$content = $this->cObj->cObjGetSingle ( 'CONTENT', $conf );

使用VHS:Fluid ViewHelpers 我安装了vhs扩展程序并尝试使用<v:content.render />呈现内容。结果与CONTENTS相同;它只适用于默认语言。

{namespace v=Tx_Vhs_ViewHelpers}

...

<v:content.render column="0" order="'sorting'" sortDirection="'ASC'"
        pageUid="{pageId}" render="1" hideUntranslated="1" />

使用我自己的SQL查询我尝试获取页面的bodytext字段,然后使用\TYPO3\CMS\Frontend\Plugin\AbstractPlugin::pi_RTEcssText()呈现这些字段。此方法基于当前语言返回内容,但问题是bodytext不包含完整内容(图像,其他插件等)。

$select_fields = "bodytext";
$from_table = "tt_content";
$where_clause = 'pid = ' . $pageId
    . ' AND sys_language_uid = ' . $GLOBALS ['TSFE']->sys_language_uid;
$res = $GLOBALS['TYPO3_DB']->exec_SELECTquery(
      $select_fields,
      $from_table,
      $where_clause,
      $groupBy='',
      $orderBy='sorting',
      $limit=''
);

$content = '';
while ( $row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc( $res ) ) {
   $content .= 
   \TYPO3\CMS\Frontend\Plugin\AbstractPlugin::pi_RTEcssText( $row ['bodytext'] );
}
$GLOBALS['TYPO3_DB']->sql_free_result( $res );

我错过了什么?在CONTENTS方法的情况下,为什么不使用当前语言呈现内容?

2 个答案:

答案 0 :(得分:0)

在TYPO3 4.x中,您可以使用以下方法加载已翻译的记录:

  • t3lib_pageSelect->getRecordOverlay
  • t3lib_pageSelect->getPageOverlay

它们也可在$GLOBALS['TSFE']->sys_page->getRecordOverlay()获得。

答案 1 :(得分:0)

最简单的方法是使用cObject viewhelper从TypoScript直接呈现。

TypoScript模板中提供配置:

lib.myContent = CONTENT
lib.myContent {
  ...
}

顺便说一句,您正在绕过TYPO3 CMS API。请不要这样做。始终使用API​​方法查询数据。 例如\TYPO3\CMS\core\Database\DatabaseConnection始终可以使用GLOBALS['TYPO3_DB']->。请勿使用mysql功能。

最重要的是,我相信您可以使用纯TypoScript存档您想要做的任何事情,而无需编写任何内容。随意提出新问题以获得帮助。

相关问题