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 #16

Merged
merged 10 commits into from
Jul 1, 2024
6 changes: 2 additions & 4 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"
- "8.3"
dependencies:
- "lowest"
- "highest"
steps:
- name: Checkout repo
uses: actions/checkout@v2
Expand All @@ -29,4 +27,4 @@ jobs:
run: composer install

- name: GrumPHP
run: ./vendor/bin/grumphp run
run: ./vendor/bin/grumphp run
4 changes: 2 additions & 2 deletions Api/Data/TranslationInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,14 +69,14 @@ public function setFrontend($frontend);
/**
* Retrieve existing extension attributes object or create a new one.
*
* @return \Phpro\Translations\Api\Data\TranslationExtensionInterface|null
* @return TranslationExtensionInterface|null
*/
public function getExtensionAttributes();

/**
* Set an extension attributes object.
*
* @param \Phpro\Translations\Api\Data\TranslationExtensionInterface $extensionAttributes
* @param TranslationExtensionInterface $extensionAttributes
* @return $this
*/
public function setExtensionAttributes(
Expand Down
10 changes: 5 additions & 5 deletions Api/TranslationRepositoryInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ interface TranslationRepositoryInterface
/**
* Save Translation
*
* @param \Phpro\Translations\Api\Data\TranslationInterface $translation
* @param Data\TranslationInterface $translation
* @throws \Magento\Framework\Exception\LocalizedException
* @return \Phpro\Translations\Api\Data\TranslationInterface
* @return Data\TranslationInterface
*/
public function save(
Data\TranslationInterface $translation
Expand All @@ -24,16 +24,16 @@ public function save(
*
* @param string $translationId
* @throws \Magento\Framework\Exception\LocalizedException
* @return \Phpro\Translations\Api\Data\TranslationInterface
* @return Data\TranslationInterface
*/
public function getById($translationId);

/**
* Retrieve Translation matching the specified criteria.
*
* @param \Magento\Framework\Api\SearchCriteriaInterface $searchCriteria
* @param SearchCriteriaInterface $searchCriteria
* @throws \Magento\Framework\Exception\LocalizedException
* @return \Phpro\Translations\Api\Data\TranslationSearchResultsInterface
* @return Data\TranslationSearchResultsInterface
*/
public function getList(
SearchCriteriaInterface $searchCriteria
Expand Down
2 changes: 1 addition & 1 deletion Block/Adminhtml/Translation/Edit/GenericButton.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ abstract class GenericButton
protected $context;

/**
* @param \Magento\Backend\Block\Widget\Context $context
* @param Context $context
*/
public function __construct(Context $context)
{
Expand Down
11 changes: 9 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,14 @@
## [1.2.2] - 2022-10-14
### Added
- Hyva support: remove requirejs from head.additional
-

## [1.3.0] - 2024-03-28
### Updated
- PHP ^8.1 compatibility
- PHP ^8.1 compatibility

## [1.4.0] - 2024-06-05
### Updated
- Set minimum PHP version to 8.3
### Bugfix
- Fix return types console commands
- Locales are not found if set in env.php and not in core_config_table
5 changes: 4 additions & 1 deletion Console/Command/Export.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ 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
{
try {
$locales = $input->getArgument(self::ARGUMENT_LOCALES);
Expand All @@ -61,6 +61,9 @@ protected function execute(InputInterface $input, OutputInterface $output): void
$output->writeln('<info>Done!</info>');
} catch (\Exception $e) {
$output->writeln('<error>' . $e->getMessage() . '</error>');
return Command::FAILURE;
}

return Command::SUCCESS;
}
}
5 changes: 4 additions & 1 deletion Console/Command/GenerateFrontendTranslations.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ 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
{
try {
$storeId = (int)$input->getArgument('storeId');
Expand All @@ -62,7 +62,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>');
return Command::FAILURE;
}

return Command::SUCCESS;
}

/**
Expand Down
5 changes: 4 additions & 1 deletion Console/Command/Import.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ 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
{
try {
$csvFile = $input->getArgument(self::ARGUMENT_CSV_FILE);
Expand Down Expand Up @@ -84,6 +84,9 @@ protected function execute(InputInterface $input, OutputInterface $output): void
$output->writeln('<info>Done!</info>');
} catch (\Exception $e) {
$output->writeln('<error>' . $e->getMessage() . '</error>');
return Command::FAILURE;
}

return Command::SUCCESS;
}
}
5 changes: 4 additions & 1 deletion Console/Command/ImportFull.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ 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
{
try {
$csvFile = $input->getArgument(self::ARGUMENT_CSV_FILE);
Expand All @@ -80,6 +80,9 @@ protected function execute(InputInterface $input, OutputInterface $output): void
$output->writeln('<info>Done!</info>');
} catch (\Exception $e) {
$output->writeln('<error>' . $e->getMessage() . '</error>');
return Command::FAILURE;
}

return Command::SUCCESS;
}
}
42 changes: 25 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,33 @@ 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();
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>');
return Command::FAILURE;
}

$output->writeln('<info>Keys successfully created.</info>');
return Command::SUCCESS;
}
}
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
19 changes: 10 additions & 9 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,18 @@
}
],
"require": {
"php": "~7.4.0||^8.1",
"php": "^8.3",
"magento/framework": "^102.0|^103.0",
"magento/module-backend": "^101.0|^102.0",
"magento/module-ui": "^101.0|^102.0"
},
"require-dev": {
"friendsofphp/php-cs-fixer": "~3.4.0",
"magento/magento-coding-standard": "21",
"friendsofphp/php-cs-fixer": "~3.59.0",
"magento/magento-coding-standard": "^33",
"php-parallel-lint/php-parallel-lint": "^1.3",
"phpro/grumphp-shim": "^1.5",
"phpunit/phpunit": "^8.5",
"squizlabs/php_codesniffer": "~3.4"
"phpro/grumphp-shim": "^2.6",
"phpunit/phpunit": "^9.5",
"squizlabs/php_codesniffer": "~3.7"
},
"autoload": {
"psr-4": {
Expand All @@ -42,15 +42,16 @@
"sort-packages": true,
"allow-plugins": {
"phpro/grumphp-shim": true,
"magento/composer-dependency-version-audit-plugin": true
"magento/composer-dependency-version-audit-plugin": true,
"dealerdirect/phpcodesniffer-composer-installer": true
}
},
"scripts": {
"post-install-cmd": [
"([ $COMPOSER_DEV_MODE -eq 0 ] || vendor/bin/phpcs --config-set installed_paths ../../magento/magento-coding-standard,../../phpcompatibility/php-compatibility/PHPCompatibility)"
"([ $COMPOSER_DEV_MODE -eq 0 ] || vendor/bin/phpcs --config-set installed_paths ../../magento/magento-coding-standard/,../../magento/php-compatibility-fork)"
],
"post-update-cmd": [
"([ $COMPOSER_DEV_MODE -eq 0 ] || vendor/bin/phpcs --config-set installed_paths ../../magento/magento-coding-standard,../../phpcompatibility/php-compatibility/PHPCompatibility)"
"([ $COMPOSER_DEV_MODE -eq 0 ] || vendor/bin/phpcs --config-set installed_paths ../../magento/magento-coding-standard/,../../magento/php-compatibility-fork)"
]
}
}
4 changes: 2 additions & 2 deletions registration.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php declare(strict_types=1);
\Magento\Framework\Component\ComponentRegistrar::register(
\Magento\Framework\Component\ComponentRegistrar::MODULE,
Magento\Framework\Component\ComponentRegistrar::register(
Magento\Framework\Component\ComponentRegistrar::MODULE,
'Phpro_Translations',
__DIR__
);
Loading