From 9957cf41d1158bd9458e2e23b9a8f037f805f61d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adam=20W=C3=B3js?= Date: Tue, 28 May 2024 05:44:35 +0200 Subject: [PATCH 1/8] Added translation extractor for custom tags --- .../IbexaFieldTypeRichTextExtension.php | 4 +- src/bundle/Resources/config/translation.yaml | 8 ++ .../translations/custom_tags.en.xliff | 111 ++++++++++++++++++ .../OnlineEditorCustomTagExtractor.php | 108 +++++++++++++++++ 4 files changed, 230 insertions(+), 1 deletion(-) create mode 100644 src/bundle/Resources/translations/custom_tags.en.xliff create mode 100644 src/lib/Translation/Extractor/OnlineEditorCustomTagExtractor.php diff --git a/src/bundle/DependencyInjection/IbexaFieldTypeRichTextExtension.php b/src/bundle/DependencyInjection/IbexaFieldTypeRichTextExtension.php index f67cc30f..cb08a91e 100644 --- a/src/bundle/DependencyInjection/IbexaFieldTypeRichTextExtension.php +++ b/src/bundle/DependencyInjection/IbexaFieldTypeRichTextExtension.php @@ -184,7 +184,9 @@ private function prependJMSTranslation(ContainerBuilder $container): void 'output_dir' => __DIR__ . '/../Resources/translations/', 'output_format' => 'xliff', 'excluded_dirs' => ['Behat', 'Tests', 'node_modules'], - 'extractors' => [], + 'extractors' => [ + 'ibexa.field_type.richtext.translation_extractor.custom_tags', + ], ], ], ]); diff --git a/src/bundle/Resources/config/translation.yaml b/src/bundle/Resources/config/translation.yaml index 60afbec6..e3e64180 100644 --- a/src/bundle/Resources/config/translation.yaml +++ b/src/bundle/Resources/config/translation.yaml @@ -9,3 +9,11 @@ services: $siteAccessList: '%ibexa.site_access.list%' tags: - { name: jms_translation.extractor, alias: ez_online_editor_attributes } + + Ibexa\FieldTypeRichText\Translation\Extractor\OnlineEditorCustomTagExtractor: + arguments: + $customTags: '%ibexa.field_type.richtext.custom_tags%' + $domain: '%ibexa.field_type.richtext.custom_tags.translation_domain%' + $filter: ['ezyoutube', 'eztwitter', 'ezfacebook'] + tags: + - { name: jms_translation.extractor, alias: ibexa.field_type.richtext.translation_extractor.custom_tags } diff --git a/src/bundle/Resources/translations/custom_tags.en.xliff b/src/bundle/Resources/translations/custom_tags.en.xliff new file mode 100644 index 00000000..fb4423e0 --- /dev/null +++ b/src/bundle/Resources/translations/custom_tags.en.xliff @@ -0,0 +1,111 @@ + + + +
+ + The source node in most cases contains the sample message as written by the developer. If it looks like a dot-delimitted string such as "form.label.firstname", then the developer has not provided a default message. +
+ + + Post URL + Post URL + key: ezrichtext.custom_tags.ezfacebook.attributes.post_url.label + + + Width + Width + key: ezrichtext.custom_tags.ezfacebook.attributes.width.label + + + Embed Facebook post + Embed Facebook post + key: ezrichtext.custom_tags.ezfacebook.description + + + Facebook + Facebook + key: ezrichtext.custom_tags.ezfacebook.label + + + Cards + Cards + key: ezrichtext.custom_tags.eztwitter.attributes.cards.label + + + Conversation + Conversation + key: ezrichtext.custom_tags.eztwitter.attributes.conversation.label + + + Do not target + Do not target + key: ezrichtext.custom_tags.eztwitter.attributes.dnt.label + + + Language code + Language code + key: ezrichtext.custom_tags.eztwitter.attributes.lang.label + + + Link color + Link color + key: ezrichtext.custom_tags.eztwitter.attributes.link_color.label + + + Theme + Theme + key: ezrichtext.custom_tags.eztwitter.attributes.theme.label + + + Tweet URL + Tweet URL + key: ezrichtext.custom_tags.eztwitter.attributes.tweet_url.label + + + Width + Width + key: ezrichtext.custom_tags.eztwitter.attributes.width.label + + + Embed X (Twitter) post + Embed X (Twitter) post + key: ezrichtext.custom_tags.eztwitter.description + + + X (Twitter) + X (Twitter) + key: ezrichtext.custom_tags.eztwitter.label + + + Autoplay + Autoplay + key: ezrichtext.custom_tags.ezyoutube.attributes.autoplay.label + + + Height + Height + key: ezrichtext.custom_tags.ezyoutube.attributes.height.label + + + Video URL + Video URL + key: ezrichtext.custom_tags.ezyoutube.attributes.video_url.label + + + Width + Width + key: ezrichtext.custom_tags.ezyoutube.attributes.width.label + + + Embed YouTube video + Embed YouTube video + key: ezrichtext.custom_tags.ezyoutube.description + + + YouTube + YouTube + key: ezrichtext.custom_tags.ezyoutube.label + + +
+
diff --git a/src/lib/Translation/Extractor/OnlineEditorCustomTagExtractor.php b/src/lib/Translation/Extractor/OnlineEditorCustomTagExtractor.php new file mode 100644 index 00000000..f7629816 --- /dev/null +++ b/src/lib/Translation/Extractor/OnlineEditorCustomTagExtractor.php @@ -0,0 +1,108 @@ + */ + private array $customTags; + + private string $domain; + + /** @var string[] */ + private array $filter; + + /** + * @param array $customTags + * @param string[] $filter + */ + public function __construct(array $customTags, string $domain, array $filter = []) + { + $this->customTags = $customTags; + $this->domain = $domain; + $this->filter = $filter; + } + + public function extract(): MessageCatalogue + { + $catalogue = new MessageCatalogue(); + foreach ($this->customTags as $tagName => $config) { + if (!in_array($tagName, $this->filter, true)) { + continue; + } + + $this->addCustomTagLabelMessage($catalogue, $tagName); + $this->addCustomTagDescriptionMessage($catalogue, $tagName); + + /** @var string[] $attributes */ + $attributes = array_keys($config['attributes'] ?? []); + foreach ($attributes as $attributeName) { + $this->addAttributeLabelMessage($catalogue, $tagName, $attributeName); + } + } + + return $catalogue; + } + + private function addCustomTagLabelMessage(MessageCatalogue $catalogue, string $tagName): void + { + $message = $this->createMessage( + sprintf(self::CUSTOM_TAG_LABEL, $tagName), + $tagName + ); + + $catalogue->add($message); + } + + private function addCustomTagDescriptionMessage(MessageCatalogue $catalogue, string $tagName): void + { + $message = $this->createMessage( + sprintf(self::CUSTOM_TAG_DESCRIPTION, $tagName), + $tagName + ); + + $catalogue->add($message); + } + + private function addAttributeLabelMessage( + MessageCatalogue $catalogue, + string $tagName, + string $attributeName + ): void { + $message = $this->createMessage( + sprintf(self::ATTRIBUTE_LABEL_KEY, $tagName, $attributeName), + $attributeName + ); + + $catalogue->add($message); + } + + private function createMessage(string $id, string $desc): XliffMessage + { + $message = new XliffMessage($id, $this->domain); + $message->setNew(false); + $message->setMeaning($desc); + $message->setDesc($desc); + $message->setLocaleString($desc); + $message->addNote('key: ' . $id); + + return $message; + } +} From 63195a113fc6e7cb47206f0fb8b4c03c04a57baf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adam=20W=C3=B3js?= Date: Tue, 28 May 2024 07:36:46 +0200 Subject: [PATCH 2/8] Added translation extractor for custom tags choices --- .../IbexaFieldTypeRichTextExtension.php | 3 +- src/bundle/Resources/config/translation.yaml | 17 +++- .../translations/custom_tags.en.xliff | 20 +++++ .../Extractor/ChoiceAttributeExtractor.php | 81 +++++++++++++++++++ ...agExtractor.php => CustomTagExtractor.php} | 60 +++++--------- .../Extractor/MessageCatalogueBuilder.php | 60 ++++++++++++++ .../OnlineEditorCustomAttributesExtractor.php | 2 +- 7 files changed, 196 insertions(+), 47 deletions(-) create mode 100644 src/lib/Translation/Extractor/ChoiceAttributeExtractor.php rename src/lib/Translation/Extractor/{OnlineEditorCustomTagExtractor.php => CustomTagExtractor.php} (52%) create mode 100644 src/lib/Translation/Extractor/MessageCatalogueBuilder.php diff --git a/src/bundle/DependencyInjection/IbexaFieldTypeRichTextExtension.php b/src/bundle/DependencyInjection/IbexaFieldTypeRichTextExtension.php index cb08a91e..0da004ce 100644 --- a/src/bundle/DependencyInjection/IbexaFieldTypeRichTextExtension.php +++ b/src/bundle/DependencyInjection/IbexaFieldTypeRichTextExtension.php @@ -185,7 +185,8 @@ private function prependJMSTranslation(ContainerBuilder $container): void 'output_format' => 'xliff', 'excluded_dirs' => ['Behat', 'Tests', 'node_modules'], 'extractors' => [ - 'ibexa.field_type.richtext.translation_extractor.custom_tags', + 'ibexa.translation_extractor.field_type.ezrichtext.custom_tags', + 'ibexa.translation_extractor.field_type.ezrichtext.custom_tags.choices', ], ], ], diff --git a/src/bundle/Resources/config/translation.yaml b/src/bundle/Resources/config/translation.yaml index e3e64180..2db60195 100644 --- a/src/bundle/Resources/config/translation.yaml +++ b/src/bundle/Resources/config/translation.yaml @@ -5,15 +5,26 @@ services: public: false Ibexa\FieldTypeRichText\Translation\Extractor\OnlineEditorCustomAttributesExtractor: + deprecated: 'Since ibexa/fieldtype-richtext 4.6.7 The "%service_id%" service is deprecated, will be removed in 5.0.0' arguments: $siteAccessList: '%ibexa.site_access.list%' tags: - { name: jms_translation.extractor, alias: ez_online_editor_attributes } - Ibexa\FieldTypeRichText\Translation\Extractor\OnlineEditorCustomTagExtractor: + Ibexa\FieldTypeRichText\Translation\Extractor\CustomTagExtractor: arguments: $customTags: '%ibexa.field_type.richtext.custom_tags%' $domain: '%ibexa.field_type.richtext.custom_tags.translation_domain%' - $filter: ['ezyoutube', 'eztwitter', 'ezfacebook'] + $whitelist: ['ezyoutube', 'eztwitter', 'ezfacebook'] tags: - - { name: jms_translation.extractor, alias: ibexa.field_type.richtext.translation_extractor.custom_tags } + - name: jms_translation.extractor + alias: ibexa.translation_extractor.field_type.ezrichtext.custom_tags + + Ibexa\FieldTypeRichText\Translation\Extractor\ChoiceAttributeExtractor: + arguments: + $customTags: '%ibexa.field_type.richtext.custom_tags%' + $domain: '%ibexa.field_type.richtext.custom_tags.translation_domain%' + $whitelist: ['ezyoutube', 'eztwitter', 'ezfacebook'] + tags: + - name: jms_translation.extractor + alias: ibexa.translation_extractor.field_type.ezrichtext.custom_tags.choices diff --git a/src/bundle/Resources/translations/custom_tags.en.xliff b/src/bundle/Resources/translations/custom_tags.en.xliff index fb4423e0..7c0dfabe 100644 --- a/src/bundle/Resources/translations/custom_tags.en.xliff +++ b/src/bundle/Resources/translations/custom_tags.en.xliff @@ -26,11 +26,21 @@ Facebook key: ezrichtext.custom_tags.ezfacebook.label + + Hidden + Hidden + key: ezrichtext.custom_tags.eztwitter.attributes.cards.choice.hidden.label + Cards Cards key: ezrichtext.custom_tags.eztwitter.attributes.cards.label + + None + None + key: ezrichtext.custom_tags.eztwitter.attributes.conversation.choice.none.label + Conversation Conversation @@ -51,6 +61,16 @@ Link color key: ezrichtext.custom_tags.eztwitter.attributes.link_color.label + + Dark + Dark + key: ezrichtext.custom_tags.eztwitter.attributes.theme.choice.dark.label + + + Light + Light + key: ezrichtext.custom_tags.eztwitter.attributes.theme.choice.light.label + Theme Theme diff --git a/src/lib/Translation/Extractor/ChoiceAttributeExtractor.php b/src/lib/Translation/Extractor/ChoiceAttributeExtractor.php new file mode 100644 index 00000000..e3069a07 --- /dev/null +++ b/src/lib/Translation/Extractor/ChoiceAttributeExtractor.php @@ -0,0 +1,81 @@ + */ + private array $customTags; + + private string $domain; + + /** @var string[] */ + private array $whitelist; + + /** + * @param array $customTags Custom tags definitions + * @param string $domain Target translation domain + * @param string[] $whitelist Whitelist of custom tags to extract + */ + public function __construct(array $customTags, string $domain, array $whitelist = []) + { + $this->customTags = $customTags; + $this->domain = $domain; + $this->whitelist = $whitelist; + } + + public function extract(): MessageCatalogue + { + $catalogue = new MessageCatalogueBuilder($this->domain); + foreach ($this->customTags as $tagName => $customTag) { + if (!in_array($tagName, $this->whitelist, true)) { + continue; + } + + $attributes = $customTag['attributes'] ?? []; + foreach ($attributes as $attributeName => $attribute) { + $type = $attribute['type'] ?? null; + if ($type !== self::CHOICE_ATTRIBUTE_TYPE) { + continue; + } + + foreach ($attribute['choices'] as $choice) { + if (empty($choice)) { + continue; + } + + $this->addChoiceLabelMessage($catalogue, $tagName, $attributeName, $choice); + } + } + } + + return $catalogue->getCatalogue(); + } + + private function addChoiceLabelMessage( + MessageCatalogueBuilder $catalogue, + string $tagName, + string $attributeName, + string $choice + ): void { + $catalogue->addMessage( + sprintf(self::CHOICE_LABEL_KEY, $tagName, $attributeName, $choice), + $choice + ); + } +} diff --git a/src/lib/Translation/Extractor/OnlineEditorCustomTagExtractor.php b/src/lib/Translation/Extractor/CustomTagExtractor.php similarity index 52% rename from src/lib/Translation/Extractor/OnlineEditorCustomTagExtractor.php rename to src/lib/Translation/Extractor/CustomTagExtractor.php index f7629816..7bb59501 100644 --- a/src/lib/Translation/Extractor/OnlineEditorCustomTagExtractor.php +++ b/src/lib/Translation/Extractor/CustomTagExtractor.php @@ -8,18 +8,17 @@ namespace Ibexa\FieldTypeRichText\Translation\Extractor; -use JMS\TranslationBundle\Model\Message\XliffMessage; use JMS\TranslationBundle\Model\MessageCatalogue; use JMS\TranslationBundle\Translation\ExtractorInterface; /** * Generates translation strings for custom tags. */ -final class OnlineEditorCustomTagExtractor implements ExtractorInterface +final class CustomTagExtractor implements ExtractorInterface { private const CUSTOM_TAG_LABEL = 'ezrichtext.custom_tags.%s.label'; private const CUSTOM_TAG_DESCRIPTION = 'ezrichtext.custom_tags.%s.description'; - private const ATTRIBUTE_LABEL_KEY = 'ezrichtext.custom_tags.%s.attributes.%s.label'; + private const ATTRIBUTE_LABEL = 'ezrichtext.custom_tags.%s.attributes.%s.label'; /** @var array */ private array $customTags; @@ -27,24 +26,25 @@ final class OnlineEditorCustomTagExtractor implements ExtractorInterface private string $domain; /** @var string[] */ - private array $filter; + private array $whitelist; /** - * @param array $customTags - * @param string[] $filter + * @param array $customTags Custom tags definitions + * @param string $domain Target translation domain + * @param string[] $whitelist Whitelist of custom tags to extract */ - public function __construct(array $customTags, string $domain, array $filter = []) + public function __construct(array $customTags, string $domain, array $whitelist = []) { $this->customTags = $customTags; $this->domain = $domain; - $this->filter = $filter; + $this->whitelist = $whitelist; } public function extract(): MessageCatalogue { - $catalogue = new MessageCatalogue(); + $catalogue = new MessageCatalogueBuilder($this->domain); foreach ($this->customTags as $tagName => $config) { - if (!in_array($tagName, $this->filter, true)) { + if (!in_array($tagName, $this->whitelist, true)) { continue; } @@ -58,51 +58,27 @@ public function extract(): MessageCatalogue } } - return $catalogue; + return $catalogue->getCatalogue(); } - private function addCustomTagLabelMessage(MessageCatalogue $catalogue, string $tagName): void + private function addCustomTagLabelMessage(MessageCatalogueBuilder $catalogue, string $tagName): void { - $message = $this->createMessage( - sprintf(self::CUSTOM_TAG_LABEL, $tagName), - $tagName - ); - - $catalogue->add($message); + $catalogue->addMessage(sprintf(self::CUSTOM_TAG_LABEL, $tagName), $tagName); } - private function addCustomTagDescriptionMessage(MessageCatalogue $catalogue, string $tagName): void + private function addCustomTagDescriptionMessage(MessageCatalogueBuilder $catalogue, string $tagName): void { - $message = $this->createMessage( - sprintf(self::CUSTOM_TAG_DESCRIPTION, $tagName), - $tagName - ); - - $catalogue->add($message); + $catalogue->addMessage(sprintf(self::CUSTOM_TAG_DESCRIPTION, $tagName), $tagName); } private function addAttributeLabelMessage( - MessageCatalogue $catalogue, + MessageCatalogueBuilder $catalogue, string $tagName, string $attributeName ): void { - $message = $this->createMessage( - sprintf(self::ATTRIBUTE_LABEL_KEY, $tagName, $attributeName), + $catalogue->addMessage( + sprintf(self::ATTRIBUTE_LABEL, $tagName, $attributeName), $attributeName ); - - $catalogue->add($message); - } - - private function createMessage(string $id, string $desc): XliffMessage - { - $message = new XliffMessage($id, $this->domain); - $message->setNew(false); - $message->setMeaning($desc); - $message->setDesc($desc); - $message->setLocaleString($desc); - $message->addNote('key: ' . $id); - - return $message; } } diff --git a/src/lib/Translation/Extractor/MessageCatalogueBuilder.php b/src/lib/Translation/Extractor/MessageCatalogueBuilder.php new file mode 100644 index 00000000..8355afea --- /dev/null +++ b/src/lib/Translation/Extractor/MessageCatalogueBuilder.php @@ -0,0 +1,60 @@ +domain = $domain; + $this->catalogue = new MessageCatalogue(); + } + + public function getDomain(): string + { + return $this->domain; + } + + public function reset(): void + { + $this->catalogue = new MessageCatalogue(); + } + + public function getCatalogue(): MessageCatalogue + { + return $this->catalogue; + } + + public function addMessage(string $id, string $desc): void + { + $this->catalogue->add($this->createMessage($id, $desc)); + } + + private function createMessage(string $id, string $desc): XliffMessage + { + $message = new XliffMessage($id, $this->domain); + $message->setNew(false); + $message->setMeaning($desc); + $message->setDesc($desc); + $message->setLocaleString($desc); + $message->addNote('key: ' . $id); + + return $message; + } +} diff --git a/src/lib/Translation/Extractor/OnlineEditorCustomAttributesExtractor.php b/src/lib/Translation/Extractor/OnlineEditorCustomAttributesExtractor.php index 63f64479..fdca10a6 100644 --- a/src/lib/Translation/Extractor/OnlineEditorCustomAttributesExtractor.php +++ b/src/lib/Translation/Extractor/OnlineEditorCustomAttributesExtractor.php @@ -15,7 +15,7 @@ use JMS\TranslationBundle\Translation\ExtractorInterface; /** - * Generates translation strings for limitation types. + * @deprecated 4.6.7 The "OnlineEditorCustomAttributesExtractor" class is deprecated, will be removed in 5.0. */ final class OnlineEditorCustomAttributesExtractor implements ExtractorInterface { From 8e426a838b2f02494ddd02d56f85b6681576eef2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adam=20W=C3=B3js?= Date: Tue, 28 May 2024 07:38:11 +0200 Subject: [PATCH 3/8] Use X instead of Twitter --- src/bundle/Resources/translations/custom_tags.en.xliff | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/bundle/Resources/translations/custom_tags.en.xliff b/src/bundle/Resources/translations/custom_tags.en.xliff index 7c0dfabe..4a26639d 100644 --- a/src/bundle/Resources/translations/custom_tags.en.xliff +++ b/src/bundle/Resources/translations/custom_tags.en.xliff @@ -87,13 +87,13 @@ key: ezrichtext.custom_tags.eztwitter.attributes.width.label - Embed X (Twitter) post - Embed X (Twitter) post + Embed X post + Embed X post key: ezrichtext.custom_tags.eztwitter.description - X (Twitter) - X (Twitter) + X + X key: ezrichtext.custom_tags.eztwitter.label From d8e8c917fbdcf18cda35ffdb14215b6159be141a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adam=20W=C3=B3js?= Date: Tue, 28 May 2024 09:37:49 +0200 Subject: [PATCH 4/8] Fixed translation test --- tests/integration/IbexaTestKernel.php | 12 ++++++++++-- .../IbexaTestKernelForTranslationTest.php | 18 ++++++++++++++++++ tests/integration/TranslationTest.php | 5 +++++ 3 files changed, 33 insertions(+), 2 deletions(-) create mode 100644 tests/integration/IbexaTestKernelForTranslationTest.php diff --git a/tests/integration/IbexaTestKernel.php b/tests/integration/IbexaTestKernel.php index 1c26428a..3c416e3c 100644 --- a/tests/integration/IbexaTestKernel.php +++ b/tests/integration/IbexaTestKernel.php @@ -32,7 +32,7 @@ use Symfony\Component\Notifier\NotifierInterface; use Symfony\WebpackEncoreBundle\WebpackEncoreBundle; -final class IbexaTestKernel extends BaseIbexaTestKernel +class IbexaTestKernel extends BaseIbexaTestKernel { public function registerBundles(): iterable { @@ -72,11 +72,19 @@ protected static function getExposedServicesById(): iterable yield 'ibexa.cache_pool' => TagAwareAdapterInterface::class; } + protected function skipOverridingCustomTagConfig(): bool + { + return false; + } + public function registerContainerConfiguration(LoaderInterface $loader): void { parent::registerContainerConfiguration($loader); - $loader->load(__DIR__ . '/../lib/_settings/common.yaml'); + if (!$this->skipOverridingCustomTagConfig()) { + $loader->load(__DIR__ . '/../lib/_settings/common.yaml'); + } + $loader->load(__DIR__ . '/Resources/config.yaml'); $loader->load(static function (ContainerBuilder $container): void { $container->setDefinition( diff --git a/tests/integration/IbexaTestKernelForTranslationTest.php b/tests/integration/IbexaTestKernelForTranslationTest.php new file mode 100644 index 00000000..5f0feb12 --- /dev/null +++ b/tests/integration/IbexaTestKernelForTranslationTest.php @@ -0,0 +1,18 @@ + Date: Tue, 28 May 2024 10:11:19 +0200 Subject: [PATCH 5/8] Update src/bundle/Resources/config/translation.yaml Co-authored-by: Konrad Oboza --- src/bundle/Resources/config/translation.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/bundle/Resources/config/translation.yaml b/src/bundle/Resources/config/translation.yaml index 2db60195..91810a9b 100644 --- a/src/bundle/Resources/config/translation.yaml +++ b/src/bundle/Resources/config/translation.yaml @@ -5,7 +5,7 @@ services: public: false Ibexa\FieldTypeRichText\Translation\Extractor\OnlineEditorCustomAttributesExtractor: - deprecated: 'Since ibexa/fieldtype-richtext 4.6.7 The "%service_id%" service is deprecated, will be removed in 5.0.0' + deprecated: 'Since ibexa/fieldtype-richtext 4.6.7 the "%service_id%" service is deprecated, will be removed in 5.0.0' arguments: $siteAccessList: '%ibexa.site_access.list%' tags: From 458e5fff13cfcd2127613d8c72ff891b59480cae Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adam=20W=C3=B3js?= Date: Tue, 28 May 2024 12:27:40 +0200 Subject: [PATCH 6/8] Applied M. Adamczyk and J. Koralewicz code review suggestions --- src/bundle/Resources/config/translation.yaml | 4 ++-- src/bundle/Resources/translations/custom_tags.en.xliff | 4 ++-- src/lib/Translation/Extractor/CustomTagExtractor.php | 10 +++++----- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/src/bundle/Resources/config/translation.yaml b/src/bundle/Resources/config/translation.yaml index 91810a9b..42c800cf 100644 --- a/src/bundle/Resources/config/translation.yaml +++ b/src/bundle/Resources/config/translation.yaml @@ -15,7 +15,7 @@ services: arguments: $customTags: '%ibexa.field_type.richtext.custom_tags%' $domain: '%ibexa.field_type.richtext.custom_tags.translation_domain%' - $whitelist: ['ezyoutube', 'eztwitter', 'ezfacebook'] + $allowlist: ['ezyoutube', 'eztwitter', 'ezfacebook'] tags: - name: jms_translation.extractor alias: ibexa.translation_extractor.field_type.ezrichtext.custom_tags @@ -24,7 +24,7 @@ services: arguments: $customTags: '%ibexa.field_type.richtext.custom_tags%' $domain: '%ibexa.field_type.richtext.custom_tags.translation_domain%' - $whitelist: ['ezyoutube', 'eztwitter', 'ezfacebook'] + $allowlist: ['ezyoutube', 'eztwitter', 'ezfacebook'] tags: - name: jms_translation.extractor alias: ibexa.translation_extractor.field_type.ezrichtext.custom_tags.choices diff --git a/src/bundle/Resources/translations/custom_tags.en.xliff b/src/bundle/Resources/translations/custom_tags.en.xliff index 4a26639d..59b3afc5 100644 --- a/src/bundle/Resources/translations/custom_tags.en.xliff +++ b/src/bundle/Resources/translations/custom_tags.en.xliff @@ -47,8 +47,8 @@ key: ezrichtext.custom_tags.eztwitter.attributes.conversation.label - Do not target - Do not target + Don't target + Don't target key: ezrichtext.custom_tags.eztwitter.attributes.dnt.label diff --git a/src/lib/Translation/Extractor/CustomTagExtractor.php b/src/lib/Translation/Extractor/CustomTagExtractor.php index 7bb59501..599a4b2b 100644 --- a/src/lib/Translation/Extractor/CustomTagExtractor.php +++ b/src/lib/Translation/Extractor/CustomTagExtractor.php @@ -26,25 +26,25 @@ final class CustomTagExtractor implements ExtractorInterface private string $domain; /** @var string[] */ - private array $whitelist; + private array $allowlist; /** * @param array $customTags Custom tags definitions * @param string $domain Target translation domain - * @param string[] $whitelist Whitelist of custom tags to extract + * @param string[] $allowlist Whitelist of custom tags to extract */ - public function __construct(array $customTags, string $domain, array $whitelist = []) + public function __construct(array $customTags, string $domain, array $allowlist = []) { $this->customTags = $customTags; $this->domain = $domain; - $this->whitelist = $whitelist; + $this->allowlist = $allowlist; } public function extract(): MessageCatalogue { $catalogue = new MessageCatalogueBuilder($this->domain); foreach ($this->customTags as $tagName => $config) { - if (!in_array($tagName, $this->whitelist, true)) { + if (!in_array($tagName, $this->allowlist, true)) { continue; } From 0bc19446f56274497e5e86c61cd0ed38447504bc Mon Sep 17 00:00:00 2001 From: Andrew Longosz Date: Tue, 28 May 2024 12:45:32 +0200 Subject: [PATCH 7/8] Refactored config not to override prepended custom tags --- .gitignore | 1 + tests/integration/IbexaTestKernel.php | 12 ++---------- .../IbexaTestKernelForTranslationTest.php | 18 ------------------ tests/integration/Resources/override.yaml | 5 +++++ tests/integration/TranslationTest.php | 5 ----- 5 files changed, 8 insertions(+), 33 deletions(-) delete mode 100644 tests/integration/IbexaTestKernelForTranslationTest.php create mode 100644 tests/integration/Resources/override.yaml diff --git a/.gitignore b/.gitignore index fa0fdd7a..b816031e 100644 --- a/.gitignore +++ b/.gitignore @@ -3,3 +3,4 @@ /.php_cs.cache node_modules/ yarn.lock +/var diff --git a/tests/integration/IbexaTestKernel.php b/tests/integration/IbexaTestKernel.php index 3c416e3c..d41662d5 100644 --- a/tests/integration/IbexaTestKernel.php +++ b/tests/integration/IbexaTestKernel.php @@ -32,7 +32,7 @@ use Symfony\Component\Notifier\NotifierInterface; use Symfony\WebpackEncoreBundle\WebpackEncoreBundle; -class IbexaTestKernel extends BaseIbexaTestKernel +final class IbexaTestKernel extends BaseIbexaTestKernel { public function registerBundles(): iterable { @@ -72,19 +72,11 @@ protected static function getExposedServicesById(): iterable yield 'ibexa.cache_pool' => TagAwareAdapterInterface::class; } - protected function skipOverridingCustomTagConfig(): bool - { - return false; - } - public function registerContainerConfiguration(LoaderInterface $loader): void { parent::registerContainerConfiguration($loader); - if (!$this->skipOverridingCustomTagConfig()) { - $loader->load(__DIR__ . '/../lib/_settings/common.yaml'); - } - + $loader->load(__DIR__ . '/Resources/override.yaml'); $loader->load(__DIR__ . '/Resources/config.yaml'); $loader->load(static function (ContainerBuilder $container): void { $container->setDefinition( diff --git a/tests/integration/IbexaTestKernelForTranslationTest.php b/tests/integration/IbexaTestKernelForTranslationTest.php deleted file mode 100644 index 5f0feb12..00000000 --- a/tests/integration/IbexaTestKernelForTranslationTest.php +++ /dev/null @@ -1,18 +0,0 @@ - Date: Tue, 28 May 2024 12:49:24 +0200 Subject: [PATCH 8/8] Changed property name to allowlist in ChoiceAttributeExtractor --- .../Translation/Extractor/ChoiceAttributeExtractor.php | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/lib/Translation/Extractor/ChoiceAttributeExtractor.php b/src/lib/Translation/Extractor/ChoiceAttributeExtractor.php index e3069a07..81d2f272 100644 --- a/src/lib/Translation/Extractor/ChoiceAttributeExtractor.php +++ b/src/lib/Translation/Extractor/ChoiceAttributeExtractor.php @@ -25,25 +25,25 @@ final class ChoiceAttributeExtractor implements ExtractorInterface private string $domain; /** @var string[] */ - private array $whitelist; + private array $allowlist; /** * @param array $customTags Custom tags definitions * @param string $domain Target translation domain - * @param string[] $whitelist Whitelist of custom tags to extract + * @param string[] $allowlist Whitelist of custom tags to extract */ - public function __construct(array $customTags, string $domain, array $whitelist = []) + public function __construct(array $customTags, string $domain, array $allowlist = []) { $this->customTags = $customTags; $this->domain = $domain; - $this->whitelist = $whitelist; + $this->allowlist = $allowlist; } public function extract(): MessageCatalogue { $catalogue = new MessageCatalogueBuilder($this->domain); foreach ($this->customTags as $tagName => $customTag) { - if (!in_array($tagName, $this->whitelist, true)) { + if (!in_array($tagName, $this->allowlist, true)) { continue; }