Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

auto create translation files #45

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions src/Bundles/Storage/INI/IniStorage.php
Original file line number Diff line number Diff line change
Expand Up @@ -172,4 +172,9 @@ public function buildFileContentBuffer(Locale $locale, array &$contentBuffer, st

return $translationCount;
}

public function getContentFileTemplate(): string
{
return file_get_contents(__DIR__ . DIRECTORY_SEPARATOR . 'Template' . DIRECTORY_SEPARATOR . 'StorageFileTemplate.ini') ?: '';
}
}
Empty file.
5 changes: 5 additions & 0 deletions src/Bundles/Storage/JSON/JsonStorage.php
Original file line number Diff line number Diff line change
Expand Up @@ -105,4 +105,9 @@ public function saveTranslation(Translation $translation, Locale $locale): Stora

return new StorageSaveResult(1, 1);
}

public function getContentFileTemplate(): string
{
return file_get_contents(__DIR__ . DIRECTORY_SEPARATOR . 'Template' . DIRECTORY_SEPARATOR . 'StorageFileTemplate.json') ?: '';
}
}
1 change: 1 addition & 0 deletions src/Bundles/Storage/JSON/Template/StorageFileTemplate.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{}
5 changes: 5 additions & 0 deletions src/Bundles/Storage/PHP/PhpStorage.php
Original file line number Diff line number Diff line change
Expand Up @@ -122,4 +122,9 @@ public function saveTranslation(Translation $translation, Locale $locale): Stora

return new StorageSaveResult(1, 1);
}

public function getContentFileTemplate(): string
{
return file_get_contents(__DIR__ . DIRECTORY_SEPARATOR . 'Template' . DIRECTORY_SEPARATOR . 'StorageFileTemplate.php') ?: '';
}
}
5 changes: 5 additions & 0 deletions src/Bundles/Storage/PHP/Template/StorageFileTemplate.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?php

declare(strict_types=1);

return [];
5 changes: 5 additions & 0 deletions src/Bundles/Storage/PO/PoStorage.php
Original file line number Diff line number Diff line change
Expand Up @@ -263,4 +263,9 @@ private function getBlocks(array $lines): array

return $blocks;
}

public function getContentFileTemplate(): string
{
return file_get_contents(__DIR__ . DIRECTORY_SEPARATOR . 'Template' . DIRECTORY_SEPARATOR . 'StorageFileTemplate.po') ?: '';
}
}
Empty file.
5 changes: 5 additions & 0 deletions src/Bundles/Storage/RESX/ResxStorage.php
Original file line number Diff line number Diff line change
Expand Up @@ -133,4 +133,9 @@ private function writeResxFile(string $filename, array $translations): int

return $totalCount;
}

public function getContentFileTemplate(): string
{
return file_get_contents(__DIR__ . "/Template/StorageFileTemplate.resx") ?: '';
}
}
11 changes: 11 additions & 0 deletions src/Bundles/Storage/RESX/Template/StorageFileTemplate.resx
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?xml version="1.0" encoding="utf-8"?>
<root xmlns="http://schemas.microsoft.com/winfx/2006/xaml">
<!-- Example
<data name="Hello">
<value>Hallo</value>
</data>
<data name="Logo" type="System.Drawing.Bitmap, System.Drawing">
<value>Image content not needed</value>
</data>
-->
</root>
5 changes: 5 additions & 0 deletions src/Bundles/Storage/Shopware6/Shopware6Storage.php
Original file line number Diff line number Diff line change
Expand Up @@ -227,4 +227,9 @@ private function getXmlAdapter(array $locales): ShopwareXmlInterface

throw new Exception('No Shopware XML Adapter found for configuration with tag: ' . $xml->getName());
}

public function getContentFileTemplate(): string
{
return '';
}
}
11 changes: 11 additions & 0 deletions src/Bundles/Storage/StorageFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -115,4 +115,15 @@ public function getStorageByFormat(string $name, TranslationSet $set): StorageIn

throw new ConfigurationException('No storage found for name: ' . $name);
}

public function getStorageFileTemplate(string $filename): string
{
foreach ($this->storages as $storage) {
if (strtolower($storage->getStorageName()) === strtolower(pathinfo($filename, PATHINFO_EXTENSION))) {
return $storage->getContentFileTemplate();
}
}

throw new ConfigurationException('No file template storage found for file: ' . $filename);
}
}
7 changes: 7 additions & 0 deletions src/Bundles/Storage/StorageInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,4 +67,11 @@ public function saveTranslationLocale(Locale $locale, string $filename): Storage
* waiting for certain processes to complete.
*/
public function saveTranslation(Translation $translation, Locale $locale): StorageSaveResult;

/**
* Get the content file template to create automate files.
*
* @return string The content file template.
*/
public function getContentFileTemplate(): string;
}
5 changes: 5 additions & 0 deletions src/Bundles/Storage/Strings/StringsStorage.php
Original file line number Diff line number Diff line change
Expand Up @@ -155,4 +155,9 @@ private function getTranslationFromLine(string $line): ?Translation

return null;
}

public function getContentFileTemplate(): string
{
return file_get_contents(__DIR__ . '/Template/StorageFileTemplate.strings') ?: '';
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
/*
* Example:
* "views.components.textelementinput.placeholder" = "Geben Sie Ihren Text ein";
*/
Empty file.
5 changes: 5 additions & 0 deletions src/Bundles/Storage/YAML/YamlStorage.php
Original file line number Diff line number Diff line change
Expand Up @@ -96,4 +96,9 @@ public function saveTranslation(Translation $translation, Locale $locale): Stora

return new StorageSaveResult(1, 1);
}

public function getContentFileTemplate(): string
{
return file_get_contents(__DIR__ . DIRECTORY_SEPARATOR . 'Template' . DIRECTORY_SEPARATOR . 'StorageFileTemplate.yaml') ?: '';
}
}
2 changes: 1 addition & 1 deletion src/Commands/AvailableServicesCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public function execute(InputInterface $input, OutputInterface $output): int

$configFile = $this->getConfigFile($input);

$configLoader = new ConfigurationLoader(new XmlLoader());
$configLoader = new ConfigurationLoader(new XmlLoader(), $io);
$configLoader->load($configFile);

# -----------------------------------------------------------------
Expand Down
2 changes: 1 addition & 1 deletion src/Commands/ExportCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ public function execute(InputInterface $input, OutputInterface $output): int

# -----------------------------------------------------------------

$configLoader = new ConfigurationLoader(new XmlLoader());
$configLoader = new ConfigurationLoader(new XmlLoader(), $io);

$config = $configLoader->load($configFile);

Expand Down
2 changes: 1 addition & 1 deletion src/Commands/FixKeysCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public function execute(InputInterface $input, OutputInterface $output): int

# -----------------------------------------------------------------

$configLoader = new ConfigurationLoader(new XmlLoader());
$configLoader = new ConfigurationLoader(new XmlLoader(), $io);
$config = $configLoader->load($configFile);


Expand Down
2 changes: 1 addition & 1 deletion src/Commands/FixMessCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public function execute(InputInterface $input, OutputInterface $output): int

# -----------------------------------------------------------------

$configLoader = new ConfigurationLoader(new XmlLoader());
$configLoader = new ConfigurationLoader(new XmlLoader(), $io);
$config = $configLoader->load($configFile);


Expand Down
2 changes: 1 addition & 1 deletion src/Commands/FixSpellingCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ public function execute(InputInterface $input, OutputInterface $output): int

# -----------------------------------------------------------------

$configLoader = new ConfigurationLoader(new XmlLoader());
$configLoader = new ConfigurationLoader(new XmlLoader(), $io);
$config = $configLoader->load($configFile);

$spellChecker = SpellCheckerFactory::getInstance()->fromService($service, $input->getOptions());
Expand Down
2 changes: 1 addition & 1 deletion src/Commands/FixStructureCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public function execute(InputInterface $input, OutputInterface $output): int

# -----------------------------------------------------------------

$configLoader = new ConfigurationLoader(new XmlLoader());
$configLoader = new ConfigurationLoader(new XmlLoader(), $io);
$config = $configLoader->load($configFile);


Expand Down
2 changes: 1 addition & 1 deletion src/Commands/ImportCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ public function execute(InputInterface $input, OutputInterface $output): int
}


$configLoader = new ConfigurationLoader(new XmlLoader());
$configLoader = new ConfigurationLoader(new XmlLoader(), $io);
$config = $configLoader->load($configFile);


Expand Down
2 changes: 1 addition & 1 deletion src/Commands/ListTranslationKeysCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public function execute(InputInterface $input, OutputInterface $output): int

# -----------------------------------------------------------------

$configLoader = new ConfigurationLoader(new XmlLoader());
$configLoader = new ConfigurationLoader(new XmlLoader(), $io);
$config = $configLoader->load($configFile);


Expand Down
2 changes: 1 addition & 1 deletion src/Commands/ListTranslationsCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public function execute(InputInterface $input, OutputInterface $output): int

# -----------------------------------------------------------------

$configLoader = new ConfigurationLoader(new XmlLoader());
$configLoader = new ConfigurationLoader(new XmlLoader(), $io);
$config = $configLoader->load($configFile);


Expand Down
2 changes: 1 addition & 1 deletion src/Commands/MigrateCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public function execute(InputInterface $input, OutputInterface $output): int

# -----------------------------------------------------------------

$configLoader = new ConfigurationLoader(new XmlLoader());
$configLoader = new ConfigurationLoader(new XmlLoader(), $io);
$config = $configLoader->load($configFile);

foreach ($config->getTranslationSets() as $set) {
Expand Down
2 changes: 1 addition & 1 deletion src/Commands/ScanUsageCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ public function execute(InputInterface $input, OutputInterface $output): int

# -----------------------------------------------------------------

$configLoader = new ConfigurationLoader(new XmlLoader());
$configLoader = new ConfigurationLoader(new XmlLoader(), $io);
$config = $configLoader->load($configFile);

$scanner = ScannerFactory::getInstance()->getScanner($scannerName);
Expand Down
2 changes: 1 addition & 1 deletion src/Commands/StatusCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public function execute(InputInterface $input, OutputInterface $output): int

# -----------------------------------------------------------------

$configLoader = new ConfigurationLoader(new XmlLoader());
$configLoader = new ConfigurationLoader(new XmlLoader(), $io);
$config = $configLoader->load($configFile);


Expand Down
2 changes: 1 addition & 1 deletion src/Commands/TranslateCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ public function execute(InputInterface $input, OutputInterface $output): int

# -----------------------------------------------------------------

$configLoader = new ConfigurationLoader(new XmlLoader());
$configLoader = new ConfigurationLoader(new XmlLoader(), $io);
$config = $configLoader->load($configFile);


Expand Down
2 changes: 1 addition & 1 deletion src/Commands/ValidateAllCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ public function execute(InputInterface $input, OutputInterface $output): int
# -----------------------------------------------------------------
# -----------------------------------------------------------------

$configLoader = new ConfigurationLoader(new XmlLoader());
$configLoader = new ConfigurationLoader(new XmlLoader(), $io);
$config = $configLoader->load($configFile);


Expand Down
2 changes: 1 addition & 1 deletion src/Commands/ValidateCoverageCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public function execute(InputInterface $input, OutputInterface $output): int

# -----------------------------------------------------------------

$configLoader = new ConfigurationLoader(new XmlLoader());
$configLoader = new ConfigurationLoader(new XmlLoader(), $io);
$config = $configLoader->load($configFile);

$covSuccess = $coverageCLI->execute($config);
Expand Down
2 changes: 1 addition & 1 deletion src/Commands/ValidateMessCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public function execute(InputInterface $input, OutputInterface $output): int
# -----------------------------------------------------------------
# -----------------------------------------------------------------

$configLoader = new ConfigurationLoader(new XmlLoader());
$configLoader = new ConfigurationLoader(new XmlLoader(), $io);
$config = $configLoader->load($configFile);

$validatorResult = $validatorCLI->execute($config->getTranslationSets());
Expand Down
2 changes: 1 addition & 1 deletion src/Commands/ValidateSimilarityCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ public function execute(InputInterface $input, OutputInterface $output): int
# -----------------------------------------------------------------
# -----------------------------------------------------------------

$configLoader = new ConfigurationLoader(new XmlLoader());
$configLoader = new ConfigurationLoader(new XmlLoader(), $io);
$config = $configLoader->load($configFile);

$similarityService = new Similarity();
Expand Down
2 changes: 1 addition & 1 deletion src/Commands/ValidateSpellingCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ public function execute(InputInterface $input, OutputInterface $output): int
# -----------------------------------------------------------------
# -----------------------------------------------------------------

$configLoader = new ConfigurationLoader(new XmlLoader());
$configLoader = new ConfigurationLoader(new XmlLoader(), $io);
$config = $configLoader->load($configFile);

$validatorResult = $validatorCLI->execute($config->getTranslationSets());
Expand Down
2 changes: 1 addition & 1 deletion src/Commands/ValidateStructureCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public function execute(InputInterface $input, OutputInterface $output): int
# -----------------------------------------------------------------
# -----------------------------------------------------------------

$configLoader = new ConfigurationLoader(new XmlLoader());
$configLoader = new ConfigurationLoader(new XmlLoader(), $io);
$config = $configLoader->load($configFile);

$translationSetCLI->showConfig($config->getTranslationSets());
Expand Down
10 changes: 8 additions & 2 deletions src/Components/Configuration/ConfigurationLoader.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use Exception;
use PHPUnuhi\Bundles\Storage\StorageFactory;
use PHPUnuhi\Components\Filter\FilterHandler;
use PHPUnuhi\Configuration\Services\CommandPrompt;
use PHPUnuhi\Configuration\Services\ConfigurationValidator;
use PHPUnuhi\Configuration\Services\CoverageLoader;
use PHPUnuhi\Configuration\Services\FilterLoader;
Expand All @@ -15,6 +16,7 @@
use PHPUnuhi\Configuration\Services\ProtectionLoader;
use PHPUnuhi\Configuration\Services\RulesLoader;
use PHPUnuhi\Configuration\Services\StyleLoader;
use PHPUnuhi\Configuration\Services\TranslationFile;
use PHPUnuhi\Exceptions\ConfigurationException;
use PHPUnuhi\Models\Configuration\Attribute;
use PHPUnuhi\Models\Configuration\CaseStyleSetting;
Expand All @@ -27,12 +29,12 @@
use PHPUnuhi\Services\Loaders\Xml\XmlLoaderInterface;
use PHPUnuhi\Traits\XmlTrait;
use SimpleXMLElement;
use Symfony\Component\Console\Style\SymfonyStyle;

class ConfigurationLoader
{
use XmlTrait;


private XmlLoaderInterface $xmlLoader;

private FilterHandler $filterHandler;
Expand All @@ -58,8 +60,9 @@ class ConfigurationLoader

private LocalesPlaceholderProcessor $localesPlaceholderProcessor;

private TranslationFile $translationFile;

public function __construct(XmlLoaderInterface $xmlLoader)
public function __construct(XmlLoaderInterface $xmlLoader, SymfonyStyle $style)
{
$this->xmlLoader = $xmlLoader;

Expand All @@ -72,6 +75,7 @@ public function __construct(XmlLoaderInterface $xmlLoader)
$this->protectionLoader = new ProtectionLoader();
$this->coverageLoader = new CoverageLoader();
$this->localesPlaceholderProcessor = new LocalesPlaceholderProcessor();
$this->translationFile = new TranslationFile(new CommandPrompt($style));
}


Expand Down Expand Up @@ -145,6 +149,8 @@ public function load(string $rootConfigFilename): Configuration
throw new ConfigurationException('Invalid configuration! No translation-sets have been found!');
}

$this->translationFile->autoCreate($config);

$this->configValidator->validateConfig($config);

return $config;
Expand Down
26 changes: 26 additions & 0 deletions src/Components/Configuration/Services/CommandPrompt.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?php

declare(strict_types=1);

namespace PHPUnuhi\Configuration\Services;

use Symfony\Component\Console\Question\Question;
use Symfony\Component\Console\Style\SymfonyStyle;

class CommandPrompt
{
private SymfonyStyle $styler;

public function __construct(SymfonyStyle $styler)
{
$this->styler = $styler;
}

public function askYesNoQuestion(string $question): bool
{
$answer = $this->styler->askQuestion(
new Question($question, 'yes')
);
return preg_match('/^(:?yes|j|y|ja)$/i', $answer) === 1;
}
}
Loading
Loading