-
Notifications
You must be signed in to change notification settings - Fork 119
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #809 from Quetzacoalt91/translations-on-storybook
Make module Translator usable on Storybook
- Loading branch information
Showing
14 changed files
with
202 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
/** | ||
* List all the available locales in the translations/ folder | ||
*/ | ||
declare const TRANSLATION_LOCALES: string[]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
<?php | ||
|
||
namespace App\EventListener; | ||
|
||
use Symfony\Component\HttpKernel\Event\RequestEvent; | ||
|
||
class LocaleListener | ||
{ | ||
/** | ||
* @param RequestEvent $event | ||
* | ||
* @return void | ||
*/ | ||
public function onKernelRequest(RequestEvent $event): void | ||
{ | ||
$request = $event->getRequest(); | ||
|
||
if (isset($event->getRequest()->getPayload()->all('args')['_locale'])) { | ||
$request->setLocale( | ||
$request->getPayload()->all('args')['_locale'] | ||
); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
<?php | ||
|
||
namespace App\Translation; | ||
|
||
use PrestaShop\Module\AutoUpgrade\UpgradeTools\Translator; | ||
use Symfony\Contracts\Translation\TranslatorInterface; | ||
|
||
class TranslatorBridge implements TranslatorInterface | ||
{ | ||
/** @var Translator */ | ||
private $translator; | ||
|
||
public function __construct(Translator $translator) | ||
{ | ||
$this->translator = $translator; | ||
} | ||
|
||
public function trans(string $id, array $parameters = [], ?string $domain = null, ?string $locale = null): string | ||
{ | ||
return $this->translator->trans($id, $parameters, $domain, $locale); | ||
} | ||
|
||
public function getLocale(): string | ||
{ | ||
return $this->translator->getLocale(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
<?php | ||
|
||
namespace App\Translation; | ||
|
||
use PrestaShop\Module\AutoUpgrade\UpgradeTools\Translator; | ||
use Symfony\Component\HttpFoundation\RequestStack; | ||
|
||
class TranslatorFactory | ||
{ | ||
public static function createTranslator(string $translationsFilesPath, RequestStack $request): Translator | ||
{ | ||
return new Translator( | ||
$translationsFilesPath, | ||
$request->getCurrentRequest() ? $request->getCurrentRequest()->getLocale() : null | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<xliff xmlns="urn:oasis:names:tc:xliff:document:1.2" version="1.2"> | ||
<file original="classes/Task/AbstractTask.php" source-language="en" target-language="fr" datatype="plaintext"> | ||
<body> | ||
<trans-unit id="435d516735dbf7f622c7d14585f66840" approved="yes"> | ||
<source>Action %s skipped</source> | ||
<target state="final">L'action %s a été ignorée</target> | ||
<note>Line: 143</note> | ||
</trans-unit> | ||
</body> | ||
</file> | ||
</xliff> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters