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

Feature/phpro 415 #15

Closed
wants to merge 9 commits into from
2 changes: 0 additions & 2 deletions .github/workflows/grumphp.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,9 @@ jobs:
fail-fast: true
matrix:
php-versions:
- "7.4"
- "8.1"
dependencies:
- "lowest"
- "highest"
steps:
- name: Checkout repo
uses: actions/checkout@v2
Expand Down
7 changes: 6 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,9 @@
-
## [1.3.0] - 2024-03-28
### Updated
- PHP ^8.1 compatibility
- PHP ^8.1 compatibility

## [1.4.0] - 2024-06-05
### Bugfix
- Fix return types console commands
- Locales are not found if set in env.php and not in core_config_table
7 changes: 6 additions & 1 deletion Console/Command/Export.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,10 @@ protected function configure(): void
* @param InputInterface $input
* @param OutputInterface $output
*/
protected function execute(InputInterface $input, OutputInterface $output): void
protected function execute(InputInterface $input, OutputInterface $output): int
{
$exitCode = 0;

try {
$locales = $input->getArgument(self::ARGUMENT_LOCALES);

Expand All @@ -61,6 +63,9 @@ protected function execute(InputInterface $input, OutputInterface $output): void
$output->writeln('<info>Done!</info>');
} catch (\Exception $e) {
$output->writeln('<error>' . $e->getMessage() . '</error>');
$exitCode = 1;
}

return $exitCode;
}
}
7 changes: 6 additions & 1 deletion Console/Command/GenerateFrontendTranslations.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,10 @@ protected function configure(): void
* @param InputInterface $input
* @param OutputInterface $output
*/
protected function execute(InputInterface $input, OutputInterface $output): void
protected function execute(InputInterface $input, OutputInterface $output): int
{
$exitCode = 0;

try {
$storeId = (int)$input->getArgument('storeId');
$statsCollection = $this->generatedTranslations($storeId);
Expand All @@ -62,7 +64,10 @@ protected function execute(InputInterface $input, OutputInterface $output): void
$output->writeln('<info>Please clean full_page and block_html caches manually</info>');
} catch (\Exception $e) {
$output->writeln('<error>' . $e->getMessage() . '</error>');
$exitCode = 1;
}

return $exitCode;
}

/**
Expand Down
7 changes: 6 additions & 1 deletion Console/Command/Import.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,10 @@ protected function configure(): void
* @param InputInterface $input
* @param OutputInterface $output
*/
protected function execute(InputInterface $input, OutputInterface $output): void
protected function execute(InputInterface $input, OutputInterface $output): int
{
$exitCode = 0;

try {
$csvFile = $input->getArgument(self::ARGUMENT_CSV_FILE);
$locale = $input->getArgument(self::ARGUMENT_LOCALE);
Expand Down Expand Up @@ -84,6 +86,9 @@ protected function execute(InputInterface $input, OutputInterface $output): void
$output->writeln('<info>Done!</info>');
} catch (\Exception $e) {
$output->writeln('<error>' . $e->getMessage() . '</error>');
$exitCode = 1;
}

return $exitCode;
}
}
7 changes: 6 additions & 1 deletion Console/Command/ImportFull.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,10 @@ protected function configure(): void
* @param InputInterface $input
* @param OutputInterface $output
*/
protected function execute(InputInterface $input, OutputInterface $output): void
protected function execute(InputInterface $input, OutputInterface $output): int
{
$exitCode = 0;

try {
$csvFile = $input->getArgument(self::ARGUMENT_CSV_FILE);

Expand All @@ -80,6 +82,9 @@ protected function execute(InputInterface $input, OutputInterface $output): void
$output->writeln('<info>Done!</info>');
} catch (\Exception $e) {
$output->writeln('<error>' . $e->getMessage() . '</error>');
$exitCode = 1;
}

return $exitCode;
}
}
44 changes: 27 additions & 17 deletions Console/Command/PrepareKeysCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ public function __construct(
ResolverFactory $optionResolverFactory,
Parser $parser,
TranslationDataManagementInterface $translationDataManagement,
private readonly \Phpro\Translations\Model\Translation\Source\Locales $localeSource,
string $name = null
) {
$this->optionResolverFactory = $optionResolverFactory;
Expand Down Expand Up @@ -64,26 +65,35 @@ protected function configure()
*
* @return void
*/
protected function execute(InputInterface $input, OutputInterface $output): void
protected function execute(InputInterface $input, OutputInterface $output): int
{
$phraseCollector = new PhraseCollector(new Tokenizer());
$adapters = [
'php' => new Php($phraseCollector),
'html' => new Html(),
'js' => new Js(),
'xml' => new Xml(),
];
$optionResolver = $this->optionResolverFactory->create(BP, false);
foreach ($adapters as $type => $adapter) {
$this->parser->addAdapter($type, $adapter);
}
$this->parser->parse($optionResolver->getOptions());
$phraseList = $this->parser->getPhrases();
$exitCode = 0;

try {
$phraseCollector = new PhraseCollector(new Tokenizer());
$adapters = [
'php' => new Php($phraseCollector),
'html' => new Html(),
'js' => new Js(),
'xml' => new Xml(),
];
$optionResolver = $this->optionResolverFactory->create(BP, false);
foreach ($adapters as $type => $adapter) {
$this->parser->addAdapter($type, $adapter);
}
$this->parser->parse($optionResolver->getOptions());
$phraseList = $this->parser->getPhrases();

foreach ($phraseList as $phrase) {
$this->translationDataManagement->prepare($phrase->getPhrase(), $phrase->getTranslation());
}

foreach ($phraseList as $phrase) {
$this->translationDataManagement->prepare($phrase->getPhrase(), $phrase->getTranslation());
$output->writeln('<info>Keys successfully created.</info>');
} catch (\Exception $e) {
$output->writeln('<error>' . $e->getMessage() . '</error>');
$exitCode = 1;
}

$output->writeln('<info>Keys successfully created.</info>');
return $exitCode;
}
}
33 changes: 12 additions & 21 deletions Model/Translation/Source/Locales.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,40 +3,31 @@

namespace Phpro\Translations\Model\Translation\Source;

use Magento\Framework\App\ResourceConnection;
use Magento\Framework\App\Config\ScopeConfigInterface;
use Magento\Framework\Data\OptionSourceInterface;
use Magento\Store\Model\StoreManager;

class Locales implements OptionSourceInterface
{
private const XML_PATH_LOCALE = 'general/locale/code';

/**
* @var ResourceConnection
*/
private $resourceConnection;

public function __construct(ResourceConnection $resourceConnection)
{
$this->resourceConnection = $resourceConnection;
public function __construct(
private readonly ScopeConfigInterface $scopeConfig,
private readonly StoreManager $storeManager,
) {
}

/**
* @inheritDoc
*/
public function toOptionArray()
public function toOptionArray(): array
{
$result = [];
$connection = $this->resourceConnection->getConnection();
$bind = [':config_path' => self::XML_PATH_LOCALE];
$select = $connection
->select()
->from($this->resourceConnection->getTableName('core_config_data'), 'value')
->distinct(true)
->where('path = :config_path');
$rowSet = $connection->fetchAll($select, $bind);
$stores = $this->storeManager->getStores();

foreach ($rowSet as $row) {
$result[] = ['value' => $row['value'], 'label' => $row['value']];
$result = [];
foreach ($stores as $store) {
$locale = $this->scopeConfig->getValue(self::XML_PATH_LOCALE, 'stores', $store->getId());
$result[] = ['value' => $locale, 'label' => $store->getName()];
}

return $result;
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
}
],
"require": {
"php": "~7.4.0||^8.1",
"php": "^8.1",
"magento/framework": "^102.0|^103.0",
"magento/module-backend": "^101.0|^102.0",
"magento/module-ui": "^101.0|^102.0"
Expand Down
Loading