Script to migrate an existing settings.definition.yaml to a xlf file:
create-xlf.php
<?php
declare(strict_types=1);
require 'vendor/autoload.php';
use Symfony\Component\Yaml\Yaml;
$filename = $_SERVER['argv'][1];
$product = $_SERVER['argv'][2];
$destination = $_SERVER['argv'][3];
$xml = new DOMDocument('1.0', 'UTF-8');
$xml->formatOutput = true;
$xliff = $xml->createElement('xliff');
$xliff->setAttribute('version', '1.2');
$xliff->setAttribute('xmlns', 'urn:oasis:names:tc:xliff:document:1.2');
$file = $xml->createElement('file');
$file->setAttribute('source-language', 'en');
$file->setAttribute('datatype', 'plaintext');
$file->setAttribute('original', 'EXT:' . $product . '/Resources/Private/Language/' . $destination);
$file->setAttribute('date', strftime('%Y-%m-%dT%H:00:00Z'));
$file->setAttribute('product-name', $product);
$header = $xml->createElement('header');
$file->appendChild($header);
$body = $xml->createElement('body');
$data = Yaml::parseFile($filename);
foreach ($data['settings'] as $key => $setting) {
$index = 'settings.' . $key;
$unit = $xml->createElement('trans-unit');
$unit->setAttribute('id', $index);
$unit->setAttribute('resname', $index);
$source = $xml->createElement('source');
$source->textContent = $setting['label'];
$unit->appendChild($source);
$body->appendChild($unit);
if ($setting['description'] ?? '') {
$index = 'settings.description.' . $key;
$unit = $xml->createElement('trans-unit');
$unit->setAttribute('id', $index);
$unit->setAttribute('resname', $index);
$source = $xml->createElement('source');
$source->textContent = $setting['description'];
$unit->appendChild($source);
$body->appendChild($unit);
}
}
$file->appendChild($body);
$xliff->appendChild($file);
$xml->appendChild($xliff);
$resultingFile = 'typo3/sysext/' . $product . '/Resources/Private/Language/' . $destination;
file_put_contents($resultingFile, $xml->saveXML());
php create-xlf.php typo3/sysext/fluid_styled_content/Configuration/Sets/FluidStyledContent/settings.definitions.yaml fluid_styled_content locallang_set.xlf
sed -i -e "/^[ ]*label:/d" -e "/^[ ]*description:/d" typo3/sysext/fluid_styled_content/Configuration/Sets/FluidStyledContent/settings.definitions.yaml