Skip to content

Commit 4aa20a1

Browse files
committed
ACP2E-1999: translation for show and set config
1 parent a1ab8f9 commit 4aa20a1

File tree

4 files changed

+56
-14
lines changed

4 files changed

+56
-14
lines changed

app/code/Magento/Config/Console/Command/ConfigSetCommand.php

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,13 @@
99
use Magento\Config\App\Config\Type\System;
1010
use Magento\Config\Console\Command\ConfigSet\ProcessorFacadeFactory;
1111
use Magento\Deploy\Model\DeploymentConfig\ChangeDetector;
12-
use Magento\Framework\App\DeploymentConfig;
1312
use Magento\Framework\App\Config\ScopeConfigInterface;
13+
use Magento\Framework\App\DeploymentConfig;
14+
use Magento\Framework\App\ObjectManager;
1415
use Magento\Framework\Config\File\ConfigFilePool;
1516
use Magento\Framework\Console\Cli;
17+
use Magento\Framework\Exception\FileSystemException;
18+
use Magento\Framework\Exception\RuntimeException;
1619
use Symfony\Component\Console\Command\Command;
1720
use Symfony\Component\Console\Input\InputArgument;
1821
use Symfony\Component\Console\Input\InputInterface;
@@ -64,6 +67,11 @@ class ConfigSetCommand extends Command
6467
*/
6568
private $deploymentConfig;
6669

70+
/**
71+
* @var LocaleEmulatorInterface
72+
*/
73+
private $localeEmulator;
74+
6775
/**
6876
* @param EmulatedAdminhtmlAreaProcessor $emulatedAreaProcessor Emulator adminhtml area for CLI command
6977
* @param ChangeDetector $changeDetector The config change detector
@@ -74,12 +82,15 @@ public function __construct(
7482
EmulatedAdminhtmlAreaProcessor $emulatedAreaProcessor,
7583
ChangeDetector $changeDetector,
7684
ProcessorFacadeFactory $processorFacadeFactory,
77-
DeploymentConfig $deploymentConfig
85+
DeploymentConfig $deploymentConfig,
86+
LocaleEmulatorInterface $localeEmulator = null
7887
) {
7988
$this->emulatedAreaProcessor = $emulatedAreaProcessor;
8089
$this->changeDetector = $changeDetector;
8190
$this->processorFacadeFactory = $processorFacadeFactory;
8291
$this->deploymentConfig = $deploymentConfig;
92+
$this->localeEmulator = $localeEmulator ??
93+
ObjectManager::getInstance()->get(LocaleEmulatorInterface::class);
8394

8495
parent::__construct();
8596
}
@@ -141,8 +152,10 @@ protected function configure()
141152
*
142153
* @param InputInterface $input
143154
* @param OutputInterface $output
144-
* @since 101.0.0
145155
* @return int|null
156+
* @throws FileSystemException
157+
* @throws RuntimeException
158+
* @since 101.0.0
146159
*/
147160
protected function execute(InputInterface $input, OutputInterface $output)
148161
{
@@ -165,7 +178,6 @@ protected function execute(InputInterface $input, OutputInterface $output)
165178

166179
try {
167180
$message = $this->emulatedAreaProcessor->process(function () use ($input) {
168-
169181
$lock = $input->getOption(static::OPTION_LOCK_ENV)
170182
|| $input->getOption(static::OPTION_LOCK_CONFIG)
171183
|| $input->getOption(static::OPTION_LOCK);
@@ -189,8 +201,9 @@ protected function execute(InputInterface $input, OutputInterface $output)
189201

190202
return Cli::RETURN_SUCCESS;
191203
} catch (\Exception $exception) {
192-
$output->writeln('<error>' . $exception->getMessage() . '</error>');
193-
204+
$this->localeEmulator->emulate(
205+
fn () => $output->writeln(sprintf('<error>%s</error>', __($exception->getMessage())))
206+
);
194207
return Cli::RETURN_FAILURE;
195208
}
196209
}

app/code/Magento/Config/Console/Command/ConfigShowCommand.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
204204
return Cli::RETURN_SUCCESS;
205205
} catch (\Exception $e) {
206206
$this->localeEmulator->emulate(
207-
fn () => $output->writeln(sprintf('<error>%s</error>', __($e->getMessage()))),
207+
fn () => $output->writeln(sprintf('<error>%s</error>', __($e->getMessage())))
208208
);
209209
return Cli::RETURN_FAILURE;
210210
}

app/code/Magento/Config/Console/Command/LocaleEmulator.php

Lines changed: 32 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,25 +12,52 @@
1212
use Magento\Framework\Phrase\RendererInterface;
1313
use Magento\Framework\TranslateInterface;
1414

15+
/**
16+
* Locale emulator for import and export
17+
*/
1518
class LocaleEmulator implements LocaleEmulatorInterface
1619
{
1720
/**
1821
* @var bool
1922
*/
2023
private bool $isEmulating = false;
2124

25+
/**
26+
* @var TranslateInterface
27+
*/
28+
private TranslateInterface $translate;
29+
30+
/**
31+
* @var RendererInterface
32+
*/
33+
private RendererInterface $phraseRenderer;
34+
35+
/**
36+
* @var ResolverInterface
37+
*/
38+
private ResolverInterface $localeResolver;
39+
40+
/**
41+
* @var ResolverInterface
42+
*/
43+
private ResolverInterface $defaultLocaleResolver;
44+
2245
/**
2346
* @param TranslateInterface $translate
2447
* @param RendererInterface $phraseRenderer
2548
* @param ResolverInterface $localeResolver
2649
* @param ResolverInterface $defaultLocaleResolver
2750
*/
2851
public function __construct(
29-
private readonly TranslateInterface $translate,
30-
private readonly RendererInterface $phraseRenderer,
31-
private readonly ResolverInterface $localeResolver,
32-
private readonly ResolverInterface $defaultLocaleResolver,
52+
TranslateInterface $translate,
53+
RendererInterface $phraseRenderer,
54+
ResolverInterface $localeResolver,
55+
ResolverInterface $defaultLocaleResolver,
3356
) {
57+
$this->translate = $translate;
58+
$this->phraseRenderer = $phraseRenderer;
59+
$this->localeResolver = $localeResolver;
60+
$this->defaultLocaleResolver = $defaultLocaleResolver;
3461
}
3562

3663
/**
@@ -50,14 +77,13 @@ public function emulate(callable $callback, ?string $locale = null): mixed
5077
$this->translate->setLocale($locale);
5178
$this->translate->loadData();
5279
try {
53-
$result = $callback();
80+
return $callback();
5481
} finally {
5582
Phrase::setRenderer($initialPhraseRenderer);
5683
$this->localeResolver->setLocale($initialLocale);
5784
$this->translate->setLocale($initialLocale);
5885
$this->translate->loadData();
5986
$this->isEmulating = false;
6087
}
61-
return $result;
6288
}
6389
}

app/code/Magento/Theme/Plugin/LocaleEmulator.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
* Copyright © Magento, Inc. All rights reserved.
44
* See COPYING.txt for license details.
55
*/
6+
declare(strict_types=1);
67

78
namespace Magento\Theme\Plugin;
89

@@ -41,7 +42,9 @@ public function aroundEmulate(
4142
try {
4243
$proceed($callback, $locale);
4344
} finally {
44-
$this->design->setDesignTheme($initialTheme);
45+
if ($initialTheme) {
46+
$this->design->setDesignTheme($initialTheme);
47+
}
4548
}
4649
}
4750
}

0 commit comments

Comments
 (0)