A few basics every now and then :-): At our web agency, we are currently writing a small partial for the list output of the TYPO3 "blog" extension. We want to add our own text to the link provided by the blog extension rather than displaying the title, which is the default setting.
Thus, we want to change the default output of the button.
<button itemprop="name"><blog:link.post post="{post}" /></button>
slightly. First, we only want to retrieve the URL to the blog post instead of the entire link code. We can achieve this with the parameter "returnUri". We therefore use the following syntax:
<blog:link.post post="{post}" returnUri="1" />
or
<blog:link.post post="{post}" returnUri="true" />
Since we now only receive the plain (relative) URL, we still need to add the link and the link text. We can do this, for example, as follows:
<button itemprop="name"><a href="/<blog:link.post post="{post}" returnUri="1" />"><f:translate key="LLL:fileadmin/lang/locallang.xlf:domain_model.button_title"/></a></button>
We therefore place the blog:link element in the href attribute of the a element and write our own text inside the a element. This brings us to our actual topic: translations. Since we were already able to specify the location of the translation files in the key, we only need to create the source file and the (in our case) German translation file. So, let's create
\fileadmin\lang\locallang.xlf
with the following example content
<?xml version="1.0" encoding="UTF-8"?>
<xliff version="1.0" xmlns:t3="http://typo3.org/schemas/xliff">
<file source-language="en" datatype="plaintext" original="LLL:fileadmin/lang/locallang.xlf">
<header/>
<body>
<trans-unit id="domain_model.button_title" resname="domain_model.button_title">
<source>To the job advertisement</source>
</trans-unit>
</body>
</file>
</xliff>
and then the translation file
\fileadmin\lang\de.locallang.xlf
with the following example content:
<?xml version="1.0" encoding="UTF-8"?>
<xliff version="1.0" xmlns:t3="http://typo3.org/schemas/xliff">
<file source-language="en" target-language="de" datatype="plaintext" original="LLL:fileadmin/lang/locallang.xlf">
<header/>
<body>
<trans-unit id="domain_model.button_title" resname="domain_model.button_title">
<source>To the job advertisement</source>
<target state="translated">Zur Stellenanzeige</target>
</trans-unit>
</body>
</file>
</xliff>
That’s all there is to it, and the translation is now displayed correctly on the website. Seen at our web agency on a TYPO3 9.5 website.
