Skip to content

Commit 4e63ac7

Browse files
authored
[administration] fix localization based on admin language for GrapesJS (#3680)
1 parent 5d7648a commit 4e63ac7

File tree

2 files changed

+26
-2
lines changed

2 files changed

+26
-2
lines changed

assets/styles/admin/components/in/ckeditor.less

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,3 +49,7 @@
4949
.cke-textarea {
5050
display: none;
5151
}
52+
53+
.cke_combo_text {
54+
width: auto !important;
55+
}

src/Component/CKEditor/CKEditorRendererDecorator.php

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,18 @@
55
namespace Shopsys\FrameworkBundle\Component\CKEditor;
66

77
use FOS\CKEditorBundle\Renderer\CKEditorRendererInterface;
8+
use Symfony\Component\HttpFoundation\RequestStack;
89

910
class CKEditorRendererDecorator implements CKEditorRendererInterface
1011
{
1112
/**
1213
* @param \FOS\CKEditorBundle\Renderer\CKEditorRendererInterface $baseCkEditorRenderer
14+
* @param \Symfony\Component\HttpFoundation\RequestStack $requestStack
1315
*/
14-
public function __construct(protected readonly CKEditorRendererInterface $baseCkEditorRenderer)
15-
{
16+
public function __construct(
17+
protected readonly CKEditorRendererInterface $baseCkEditorRenderer,
18+
protected readonly RequestStack $requestStack,
19+
) {
1620
}
1721

1822
/**
@@ -41,6 +45,8 @@ public function renderJsPath(string $jsPath): string
4145
*/
4246
public function renderWidget(string $id, array $config, array $options = []): string
4347
{
48+
$config['language'] = $this->getRequestLanguage() ?? $config['language'];
49+
4450
return sprintf(
4551
'$("#%s-preview").click(function() {
4652
%s
@@ -104,4 +110,18 @@ public function renderTemplate(string $name, array $template): string
104110
{
105111
return $this->baseCkEditorRenderer->renderTemplate($name, $template);
106112
}
113+
114+
/**
115+
* @return string|null
116+
*/
117+
protected function getRequestLanguage(): ?string
118+
{
119+
$request = $this->requestStack->getCurrentRequest();
120+
121+
if ($request !== null && $request->getLocale() !== '') {
122+
return $request->getLocale();
123+
}
124+
125+
return null;
126+
}
107127
}

0 commit comments

Comments
 (0)