Skip to content

Commit

Permalink
Guess ext name from path
Browse files Browse the repository at this point in the history
  • Loading branch information
Tuurlijk committed Dec 21, 2018
1 parent 9793292 commit 6b0acc1
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 4 deletions.
2 changes: 1 addition & 1 deletion bin/typo3migrate
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ foreach ([__DIR__ . '/../../../autoload.php', __DIR__ . '/../../../../autoload.p

use MichielRoos\TYPO3Migrate\Console\Application;

$app = new Application('TYPO3Migrate', '1.3.1');
$app = new Application('TYPO3Migrate', '1.4.0');
$app->add(new \MichielRoos\TYPO3Migrate\Command\ConvertFluidNamespacesCommand());
$app->add(new \MichielRoos\TYPO3Migrate\Command\Xml2XlfCommand());
$app->run();
26 changes: 23 additions & 3 deletions src/TYPO3Migrate/Command/Xml2XlfCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
}

$pathInfo = pathinfo($xml);
$productName = $this->getExtKeyFromPath($xml);

$filesystem = new Filesystem();
foreach ($data as $language => $languageData) {
Expand All @@ -125,7 +126,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
echo 'An error occurred while creating the translation file at ' . $exception->getPath();
exit;
}
$filesystem->dumpFile($xlfFile, $this->getXlf($data, $language));
$filesystem->dumpFile($xlfFile, $this->getXlf($data, $language, $productName));
$output->writeln(sprintf('Wrote <comment>%s</comment> labels to: <info>%s</info>', $language, $xlfFile));
}
}
Expand Down Expand Up @@ -157,7 +158,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
* @param $language
* @return string
*/
protected function getXlf($data, $language = 'default'): string
protected function getXlf($data, $language = 'default', $productName = 'typo3migrate')
{
$isTranslation = false;
if ($language !== 'default') {
Expand All @@ -176,7 +177,7 @@ protected function getXlf($data, $language = 'default'): string
$file->setAttribute('datatype', 'plaintext');
$file->setAttribute('original', 'messages');
$file->setAttribute('data', strftime('%Y-%m-%dT%H-%M-%S'));
$file->setAttribute('product-name', 'typo3migration');
$file->setAttribute('product-name', $productName);
$header = $xml->createElement('header');
$file->appendChild($header);
$body = $xml->createElement('body');
Expand All @@ -203,4 +204,23 @@ protected function getXlf($data, $language = 'default'): string
$xml->formatOutput = true;
return $xml->saveXML();
}

/**
* Return the extension key from the path
*
* @param $path
* @return string
*/
protected function getExtKeyFromPath($path)
{
$extensionName = '';
while ($dir = basename($path)) {
if ($dir === 'ext') {
return $extensionName;
}
$extensionName = $dir;
$path = \dirname($path);
}
return $extensionName;
}
}

0 comments on commit 6b0acc1

Please sign in to comment.