Rareș Popescu
Rareș Popescu

Reputation: 81

TYPO3: How can I use localized content for several languages into the same page?

I'm developing a localized Typo3 extension and I've build the repository and models, currently being able to view each language version of the content into its own language id page on the frontend.

I need however to display some of the translated properties(content fields) into a single webpage, but I do not know nor am I able to find on other sources how to handle all the translated content into my templates view or how to assign the variables.

Example:

In my Controller there is:

$test = $this->testRepository->findAll();
$this->view->assign('test', $test);

For which I display the content in my template as:

{test.title}

Now, Typo3 does the work and for EN it displays the english version of 'title', for DE the german version and so on, but all of this on separate pages.

How can I take all of the language versions of 'test.title' and display them into the same page?

Thank you

Upvotes: 2

Views: 479

Answers (1)

Jay Böttcher
Jay Böttcher

Reputation: 534

Just an idea, I didn't test it yet.

In your Repository, insert this function:

public function initializeObject() {
    $querySettings = $this->createQuery()->getQuerySettings();
    $querySettings->setRespectSysLanguage(false);
    $querySettings->setLanguageMode('ignore');
    $this->setDefaultQuerySettings($querySettings);
}

If you don't want to ignore the language filtering in your whole extension, just change the query settings only for a single query.

Now you should get all translations at once for your query. Do your own filtering of languages with

$query->matching($query->equals('sysLanguageUid', 1));

Don't forget to define sysLanguageUid with getter and setter functions in your model.

Upvotes: 1

Related Questions