TYPO3 News扩展多语言:安全自定义德语“Read More”翻译方法
Great question—let’s break this down clearly. First off: never directly edit the translation files inside the News extension itself. Any changes you make there will get overwritten the next time you update the extension, which is a huge hassle. Instead, you want to use TYPO3's built-in language override system to add your custom translations safely.
Here’s a step-by-step guide to do this properly:
1. Use Your Site Package (Best Practice)
If you don’t already have a site package extension set up, I highly recommend creating one first—it’s the standard way to keep all your customizations (templates, translations, config) separate from third-party extensions. Assuming you have one (let’s call it your_site_package), follow these steps:
2. Create Custom Language File Structure
Inside your site package, create this directory structure if it doesn’t exist:
typo3conf/ext/your_site_package/Resources/Private/Language/
3. Add the German Translation File
Create a file named de.locallang.xlf in that directory. Now, find the exact translation key for "read more" in the News extension’s original language file. Navigate to /typo3conf/ext/news/Resources/Private/Language/de.locallang.xlf and look for a <trans-unit> with the ID readmore (this is the common key for the "read more" link in list views).
Copy that trans-unit into your custom de.locallang.xlf file, then adjust the <target> value to your desired German translation. For example:
<?xml version="1.0" encoding="UTF-8"?> <xliff version="1.0"> <file source-language="en" target-language="de" datatype="plaintext" original="messages" date="2024-05-20" product-name="your_site_package"> <header/> <body> <trans-unit id="readmore" resname="readmore"> <source>Read more</source> <target>Mehr erfahren</target> <!-- Replace with your preferred translation --> </trans-unit> </body> </file> </xliff>
4. Tell TYPO3 to Use Your Custom Translation
Open your site package’s ext_localconf.php file and add this line to override the News extension’s German language file with yours:
$GLOBALS['TYPO3_CONF_VARS']['SYS']['locallangXMLOverride']['de']['EXT:news/Resources/Private/Language/locallang.xlf'][] = 'EXT:your_site_package/Resources/Private/Language/de.locallang.xlf';
Make sure to replace your_site_package with the actual name of your site package extension.
5. Clear Cache & Test
Finally, go to the TYPO3 backend, clear all caches (System > Maintenance > Flush Caches), then refresh your frontend list view. Your custom "read more" translation should now appear.
Quick Note:
If the "read more" text is coming from a different key (e.g., a plugin-specific view), double-check the News extension’s language files to find the correct trans-unit ID. The process stays the same—just copy that specific ID into your custom file.
内容的提问来源于stack exchange,提问作者RacoonOnMoon

