We implement a language menu when the website has two or more languages.
Problems occur on the detail pages when a page is translated and a record is not (note that the system is not configured to support Fallback Type: Fallback: Show default language if no translation exists).
By default, the language menu will display items in the default language and other available languages once the page is translated.
Overview details:
We have configured German as the default language, with English as the secondary language, which means some pages will be shown in both languages.
If we are on the German version and want to see the English version, we will click on the link for English (of the language menu), and the page will be shown in English.
Suppose the page is used for the record detail view (by adding a plugin for detail view as a content of the page), and the record is not translated, the language menu in most cases will show two items (the menu can be configured to show only non-current items).
German will be shown as the current language item, and we will have another item in English, still because the record is not translated, the URL of the English link will not have the record ID as a parameter, which means the link will have only a language parameter.
If we click on the English, we will be redirected to the English page, the plugin in most cases shows some random message.
In this case, we should not display the language menu on the detail view page if the record is not translated, and we should not offer an incorrect URL.
TYPO3 does not have a feature/option for the language menu that will check if the record is not translated and then disable the second language item or in this case hide the language menu.
Check the possible solution:
The first step is to create 2 libs, one to note if the page is single view and the other to get the record data
First, we will create a lib to set if the page is a page for showing record details, by default value is 0:
lib.link.singleView = TEXT
lib.link.singleView.value = 0
Second, we will create lib.recordData which will store the ID of the record, and lib.recordData value will be JSON string which will have recordTable and recordUid as content, in this case, we can use any table and record.
In the example, we will use the news feature as a reference, to be able to get the record we would need to get the record ID as a param from the URL.
[traverse(request.getQueryParams(), 'tx_news_pi1/news') > 0]
lib.link.singleView.value = 1
lib.recordData = TEXT
lib.recordData.data = GP:tx_news_pi1|news
lib.recordData.wrap = {"recordTable":"tx_news_domain_model_news", "recordUid":|}
[global]