🦴 Translating Static Strings – The XLF Chronicles
To get started, you'll need an XLF file—a fancy XML-based file that holds your language magic. Place it in your extension like so:
EXT:extension_name/Resources/Private/Language/locallang.xlf
Wanna add German? Just prefix it like a dino scientist: de.locallang.xlf
Here’s what your standard locallang.xlf
might look like (rawr!):
<xliff version="1.0">
<file source-language="en" datatype="plaintext" original="messages" product-name="extension_name">
<body>
<trans-unit id="page.header">
<source>Header</source>
</trans-unit>
<trans-unit id="page.footer">
<source>Footer</source>
</trans-unit>
</body>
</file>
</xliff>
And now, the German version (aka Dino-Deutsch 🦕🇩🇪):
<xliff version="1.0">
<file source-language="en" target-language="de" datatype="plaintext" original="messages" product-name="extension_name">
<body>
<trans-unit id="page.header">
<source>Header</source>
<target>Kopfzeile</target>
</trans-unit>
<trans-unit id="page.footer">
<source>Footer</source>
<target>Fußzeile</target>
</trans-unit>
</body>
</file>
</xliff>
To use them in your Fluid templates, bring in the mighty f:translate
ViewHelper:
<f:translate key="page.header" />
<f:translate key="page.header" extensionName="extension_name" />
<f:translate key="LLL:EXT:extension_name/Resources/Private/Language/locallang.xlf:page.header" />
Want dynamic translations with arguments? Like:
<source>Read more about %s</source>
You'd use:
<f:translate key="page.readmore" arguments="{0: 'Why TYPO3 is a T-Rexcellent CMS'}" />
In PHP:
\TYPO3\CMS\Extbase\Utility\LocalizationUtility::translate(
'page.readmore',
'extension_name',
['Why TYPO3 is a T-Rexcellent CMS']
);
🧠 Backend and Third-Party Translations – Enter: Crowdin the Dino Wrangler
Ever wonder how the core and famous extensions speak so many languages? That’s because they use Crowdin—a translation platform where the whole dino community helps out.
People suggest translations, proofreaders approve them, and TYPO3 sweeps them up in periodic releases.
To fetch the translation packs:
- 🦖 Go to Admin Tools → Maintenance → Manage Language Packs
- 🦕 Choose your language and click "Download"
🛠️ What If Crowdin Doesn’t Have Your Dino-Dialect?
No worries! That’s why we built the extension hd_translator. It lets you override and edit translations directly in the TYPO3 backend like a translation T-Rex in a china shop.
Other override options include:
TypoScript
plugin.tx_extensionname._LOCAL_LANG.de.page.readmore = Mehr über %s lesen
PHP Override
$GLOBALS['TYPO3_CONF_VARS']['SYS']['locallangXMLOverride']['EXT:extension_name/Resources/Private/Language/locallang.xlf'][] = '/var/www/html/translations/locallang.xlf';
🦕 Translating Pages and Content
You can't put content on a page that doesn’t exist in the desired language. First step: translate the page!
- Open the Page module
- Switch to Language Comparison
- If a translation is missing, TYPO3 will show “Create a new translation of this page”
- Pick the language and save your settings
You can now switch languages using the selector near the top toolbar.