简体   繁体   English

通过Typoscript将翻译添加到TYPO3扩展

[英]Add translation to TYPO3 Extension via Typoscript

is there a way to substitute/override the default de.locallang.xlf of the extension via Typoscript? 有没有办法通过Typoscript替换/覆盖扩展名的默认de.locallang.xlf? I want to change the text of mindshape_cookie_hint in a way that will survive an update. 我想以一种可以在更新后保存的方式更改mindshape_cookie_hint的文本。

If it is a plugin you can override translations in TypoScript via _LOCAL_LANG which is also what mindshape_cookie_hint suggests in its docs . 如果是插件,则可以通过_LOCAL_LANG覆盖TypoScript中的翻译,这也是mindshape_cookie_hint 在其文档中建议的内容

This requires you to manage your translation strings in TypoScript though which is far from ideal. 这要求您在TypoScript中管理翻译字符串,尽管这远非理想。 A better and more general solution is registering custom translations via locallangXMLOverride . 更好,更通用的解决方案是通过locallangXMLOverride注册自定义翻译 This allows you to manage these translations just like everywhere else. 这样,您就可以像其他地方一样管理这些翻译。

You are looking for this https://wiki.typo3.org/TypoScript_language_additions,_override 您正在寻找这个https://wiki.typo3.org/TypoScript_language_additions,_override

As written by Ghanshyam Bhava in his answer, you can just take a look at the locallang.xlf file in the plugin folder in the file system to have an overview of the keys the extension uses and then write in your TypoScript template: 就像Ghanshyam Bhava在他的答案中所写的那样,您只需看一下文件系统中plugin文件夹中的locallang.xlf文件,就可以locallang.xlf了解扩展程序使用的键,然后在TypoScript模板中进行编写:

plugin.tx_exampleplugin_pi1._LOCAL_LANG.it {

   key1 = value1
   key2 = value2
   ...

} 

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

In a general way, correct me if I am wrong, I think that you have modified the original .xlf file of the plugin; 一般来说,如果我错了,请纠正我,我认为您已经修改了插件的原始.xlf文件; this procedure is not recommended for the reason you are facing: an update would delete your changes. 由于您面临的原因,不建议执行此过程:更新将删除您的更改。

A good way to deal with this problem could be for example using the extension EXT:lfeditor ( https://extensions.typo3.org/extension/lfeditor/ ); 解决此问题的一种好方法是,例如使用扩展名EXT:lfeditor( https://extensions.typo3.org/extension/lfeditor/ ); read carefully its manual. 仔细阅读其手册。

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

I'll take an excerpt from that page: 我将从该页面摘录:

The $GLOBALS['TYPO3_CONF_VARS']['SYS']['locallangXMLOverride'] allows to override both locallang-XML and XLIFF files. $GLOBALS['TYPO3_CONF_VARS']['SYS']['locallangXMLOverride']允许覆盖locallang-XML和XLIFF文件。 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): 对于XLIFF文件,语法如下(放置在扩展程序的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'; 

The first line shows how to override a file in the default language, the second how to override a German ("de") translation. 第一行显示了如何以默认语言覆盖文件,第二行显示了如何覆盖德语(“ de”)翻译。 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> 

With below typoscript you can overwrite individual translations for TYPO3 Extension: 使用以下拼写,您可以覆盖TYPO3扩展的各个翻译:

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

Generally common for every extension. 通常对每个扩展都通用。 Hope this will help you! 希望这个能对您有所帮助!

Greetings! 问候!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM