首页 > 解决方案 > 使用 locallang.xlf 以typo3 形式翻译自定义validationErrorMessages

问题描述

我使用 locallang.xlf 来翻译我的表单(typo3 9.5.5,formextension)。

我的 customform.yaml:

       renderables:
          -
            properties:
              fluidAdditionalAttributes:
                required: required
              validationErrorMessages:
                -
                  code: 1221560910
                  message: 'My Custom Message'
                  code: 1221560718
                  message: 'My Custom Message'
                -
                  code: 1347992400
                  message: 'My Custom Message'
                -
                  code: 1347992400
                  message: 'My Custom Message'
              options:
                products: 'Products'
                miscellaneous: 'Sonstiges'
              prependOptionLabel: 'Please Specify'
            type: SingleSelect
            identifier: subject
            label: 'Your Subject:'
            validators:
              -
                identifier: NotEmpty
          -

我的 locallang.xlf:

        <trans-unit id="element.subject.properties.prependOptionLabel">
            <source>Please Specify --Works!</source>
        </trans-unit>
        <trans-unit id="element.subject.properties.options.products">
                <source>Products --Works!</source>
        </trans-unit>
    <trans-unit id="element.subject.properties.validationErrorMessages.message">
            <source>Custom Message -Doesn't work!</source>
        </trans-unit>

除了validationErrorMessages之外,它可以使用精确的翻译密钥。有谁知道如何翻译这些?

标签: formsvalidationtypo3translationtypo3-9.x

解决方案


您可以将以下翻译键用于验证错误代码。1221559976EmailAddress验证器的代码:

<trans-unit id="validation.error.1221559976">
    <source>Please enter valid email address. Thanks!</source>
    <target>Bitte gebe eine gültige E-Mail-Adresse ein. Danke!</target>
</trans-unit>
<trans-unit id="MyContactForm.validation.error.1221559976">
    <source>Please enter valid email address. Thank you very much!</source>
    <target>Bitte gebe eine gültige E-Mail-Adresse ein. Vielen herzlichen Dank!</target>
</trans-unit>

后者将覆盖第一个,因为它包含表单标识符,因此更具体。

请记住,如果您已经在表单定义中设置了自定义消息,那么这两个翻译键都将不起作用!

这意味着,必须删除以下示例的最后三行:

renderables:
  -
    defaultValue: ''
    identifier: email
    label: Email
    type: Text
    properties:
      fluidAdditionalAttributes:
        placeholder: 'Email address'
      ### Don't set this if you want to translate the message:
      #validationErrorMessages:
      #  - code: 1221559976
      #    message: 'Please enter a valid email address, dear.'

推荐阅读