通过Typoscript为TYPO3扩展添加翻译

4
有没有一种通过Typoscript替换/覆盖扩展的默认de.locallang.xlf的方法?我想以一种在更新后仍能生效的方式更改mindshape_cookie_hint的文本。
3个回答

6
  1. 如果它是一个插件,您可以通过 TypoScript 的 _LOCAL_LANG 重写翻译字符串,例如 mindshape_cookie_hint 在其文档中建议的方式:

    plugin.tx_myext_pi1._LOCAL_LANG.de.list_mode_1 = Der erste Modus
    

    这需要您在 TypoScript 中管理翻译字符串,但远非理想。

  2. 更好、更通用的解决方案是通过locallangXMLOverride注册自定义翻译字符串。这使您可以像所有其他地方一样管理这些翻译字符串。

    从文档中可以了解到:

    ext_localconf.php:

    $GLOBALS['TYPO3_CONF_VARS']['SYS']['locallangXMLOverride']['EXT:cms/locallang_tca.xlf'][] = 
        'EXT:examples/Resources/Private/Language/custom.xlf';
    $GLOBALS['TYPO3_CONF_VARS']['SYS']['locallangXMLOverride'] 
      ['de']['EXT:news/Resources/Private/Language/locallang_modadministration.xlf'][] = 'EXT:examples/Resources/Private/Language/Overrides/de.locallang_modadministration.xlf';
    

    第一行显示如何覆盖默认语言中的文件,第二行显示如何覆盖德语(“de”)翻译。德语语言文件的示例代码如下:

    <?xml version="1.0" encoding="utf-8" standalone="yes" ?>
    <xliff version="1.0">
      <file source-language="en" datatype="plaintext" original="messages" date="2013-03-09T18:44:59Z" product-name="examples">
       <header/>
       <body>
          <trans-unit id="pages.title_formlabel" xml:space="preserve">
             <source>Most important tile</source>
             <target>Wichtigster Titel</target>
          </trans-unit>
       </body>
      </file>
    </xliff>
    

2
TYPO3服务器的链接也会发生变化,如果您能直接在答案中添加必要的信息,那就太好了。Stack Overflow的政策是避免仅包含链接的答案。谢谢! - David
请纠正我,但是locallangXMLOverride解决方案在常规扩展更新后会破坏新的或编辑过的标签键,对吗? - Deivid As
“EDIT:”我刚才测试了一下我的想法,发现即使添加新标签,它也可以工作。TYPO3确实会合并和覆盖标签。这应该是覆盖第三方扩展标签最清洁的方法。 - Deivid As

4
您正在寻找这个链接:https://wiki.typo3.org/TypoScript_language_additions,_override 正如Ghanshyam Bhava在回答中所写,您可以查看文件系统中插件文件夹中的locallang.xlf文件,以了解扩展使用的键,并在TypoScript模板中编写以下内容:
plugin.tx_exampleplugin_pi1._LOCAL_LANG.it {

   key1 = value1
   key2 = value2
   ...

} 

另请参阅https://docs.typo3.org/typo3cms/TyposcriptReference/Setup/Plugin/Index.html#local-lang-lang-key-label-key

一般来说,如果我理解正确的话,您修改了插件的原始.xlf文件;这种做法并不推荐,因为更新会删除您的更改。

解决此问题的一个好方法是使用EXT:lfeditor扩展程序(https://extensions.typo3.org/extension/lfeditor/);仔细阅读其手册。

另一个来源(官方文档):https://docs.typo3.org/typo3cms/CoreApiReference/latest/ApiOverview/Internationalization/ManagingTranslations.html?highlight=locallangxmloverride#custom-translations

我将摘录该页面的一部分:

The $GLOBALS['TYPO3_CONF_VARS']['SYS']['locallangXMLOverride'] allows to override both locallang-XML and XLIFF files. Actually this is not just about translations. Default language files can also be overridden. In the case of XLIFF files, the syntax is as follows (to be placed in an extension's ext_localconf.php file):

$GLOBALS['TYPO3_CONF_VARS']['SYS']['locallangXMLOverride']['EXT:cms/locallang_tca.xlf'][] = 'EXT:examples/Resources/Private/Language/custom.xlf';
$GLOBALS['TYPO3_CONF_VARS']['SYS']['locallangXMLOverride']['de']['EXT:news/Resources/Private/Language/locallang_modadministration.xlf'][] = 'EXT:examples/Resources/Private/Language/Overrides/de.locallang_modadministration.xlf';

The first line shows how to override a file in the default language, the second how to override a German ("de") translation. The German language file looks like this:

<?xml version="1.0" encoding="utf-8" standalone="yes" ?>
<xliff version="1.0">
   <file source-language="en" datatype="plaintext" original="messages" date="2013-03-09T18:44:59Z" product-name="examples">
      <header/>
      <body>
         <trans-unit id="pages.title_formlabel" xml:space="preserve">
            <source>Most important tile</source>
            <target>Wichtigster Titel</target>
         </trans-unit>
      </body>
   </file>
</xliff>

抱歉,Ricardo,有点紧张:另外,TYPO3服务器的链接也会更改,如果您可以直接在答案中添加必要的信息,那将是非常好的。Stack Overflow的政策是避免仅包含链接的答案。谢谢! - David

0

使用下面的Typoscript,您可以覆盖TYPO3扩展的单个翻译:

plugin.tx_myPlugin_pi1._LOCAL_LANG.de.key = value; 
plugin.tx_myPlugin_pi1._LOCAL_LANG.en.key = value;

通常适用于每个扩展。希望这能帮到你!

问候!


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接