typo3tca

TYPO3 TCA with language dependant default value?


I need a language dependant default value for a text(area) input field. If I use the usual 'LLL:EXT:' syntax, it does not get resolved. The placeholder (and label and description, of course) gets resolved properly.

'some_column' => [
    'label' => 'LLL:EXT:myext/Resources/Private/Language/locallang_db.xlf:some_column',
    'description' => 'LLL:EXT:myext/Resources/Private/Language/locallang_db.xlf:some_column.description',
        'config' => [
            'type' => 'text',
            'cols' => 40,
            'rows' => 3,
            'placeholder' => 'LLL:EXT:myext/Resources/Private/Language/locallang_db.xlf:some_column.placeholder',
            'default' => 'LLL:EXT:myext/Resources/Private/Language/locallang_db.xlf:some_column.default'
        ]
    ]
]

The default value in this field is then "LLL:EXT:myext/Resources/Private/Language/locallang_db.xlf:some_column.default" instead of the related string in locallang_db.xlf.

How can this be achieved?


Solution

  • That is not possible out of the box.

    TCA default value are simply used and passed to the database on persisting for new records OR when the field is not provided in a DataHandler call.

    The TCA default value is considerable a software based default-value comparable to a database table column default value. You cannot declare that dynamically either (with a simple value). Values are not put through the "translation" system by TYPO3, at least not by default. Some extension may take retrieved record data and call translation on these dataset when they now it is translatable. But it would not make sense to pass for example a json field data or a php serialized data field into the language translation system - or eventually binary data in case someone is writing for example image or file data to the database / blob / binary fields (I hope not !!!).

    Why should a "default" value than passt to the translation system. And the next thing is, if you only take the BE user language into account for a not language awae field - you may still want to write the "key" to the field and "translate" it on output (frontend) to use the "frontend user language" or "frontend site language" instead ? Why should the value than be saved directly translated.

    TYPO3 provides at least some level of dynamic default values:

    But that does not take the "language" of a record (or page) into account, and as Julian already mentioned as comment there are multiple competing possible "expectations", all not good in all conditions.

    But even if there is no simple configuration way, there are still ways to archive that, but these needs to be implemented and depends on the exact use-case and what needs to be done: