From 3447ad3c2da5ef4548ee6c5dfb2ed42a36b73be7 Mon Sep 17 00:00:00 2001 From: Denny Lubitz Date: Tue, 23 Apr 2024 23:01:09 +0200 Subject: [PATCH 1/3] BUGFIX: Set up site in determined dimension and set up I18n service with the proper locale to also show translations from XLIFF files in correct language. --- Classes/Fusion/Eel/Helper/LocaleHelper.php | 59 ++++++++++++++++++++++ Configuration/Settings.yaml | 2 + README.md | 7 +-- Resources/Private/Fusion/Root.fusion | 3 ++ composer.json | 2 +- 5 files changed, 69 insertions(+), 4 deletions(-) create mode 100644 Classes/Fusion/Eel/Helper/LocaleHelper.php diff --git a/Classes/Fusion/Eel/Helper/LocaleHelper.php b/Classes/Fusion/Eel/Helper/LocaleHelper.php new file mode 100644 index 0000000..b5c2061 --- /dev/null +++ b/Classes/Fusion/Eel/Helper/LocaleHelper.php @@ -0,0 +1,59 @@ +getContext()->getDimensions(); + if (array_key_exists($languageDimensionName, $dimensions) && $dimensions[$languageDimensionName] !== []) { + $currentLocale = new Locale($dimensions[$languageDimensionName][0]); + $this->i18nService->getConfiguration()->setCurrentLocale($currentLocale); + $this->i18nService->getConfiguration()->setFallbackRule(['strict' => false, 'order' => array_reverse($dimensions[$languageDimensionName])]); + } + + return $node; + } + + /** + * All methods are considered safe + * + * @param string $methodName + * @return boolean + */ + public function allowsCallOfMethod($methodName) + { + return true; + } +} \ No newline at end of file diff --git a/Configuration/Settings.yaml b/Configuration/Settings.yaml index 9b6bd33..f57d7cf 100644 --- a/Configuration/Settings.yaml +++ b/Configuration/Settings.yaml @@ -2,6 +2,7 @@ Neos: Fusion: defaultContext: NotFound.Context: MOC\NotFound\Fusion\Eel\Helper\ContextHelper + NotFound.LocaleHelper: MOC\NotFound\Fusion\Eel\Helper\LocaleHelper Neos: fusion: autoInclude: @@ -9,3 +10,4 @@ Neos: MOC: NotFound: uriPathSegment: 404 + languageDimensionName: language \ No newline at end of file diff --git a/README.md b/README.md index 42ccd34..b46583b 100644 --- a/README.md +++ b/README.md @@ -11,16 +11,16 @@ Introduction Neos CMS package that loads a normal editable page for displaying a 404 error. -Compatible with Neos 4.3 - 5.x +Compatible with Neos 8.x Supports multiple content dimensions with URI segments and empty segments for default dimensions. Installation ------------ -```composer require "moc/notfound:^4.0"``` +```composer require "moc/notfound"``` Create a page with the URI segment "404" in the root of your site. If using content dimensions with URI segments, -ensure a page exists in all contexts or through fallbacks. +ensure a page exists in all contexts or through fallbacks. Per default the package assumes the name of the language dimension as "language". Alternatively set the following configuration in ``Settings.yaml``: @@ -28,6 +28,7 @@ Alternatively set the following configuration in ``Settings.yaml``: MOC: NotFound: uriPathSegment: 404 + languageDimensionName: language ``` Note: If you override the configuration in a package's configuration instead of globally, you need to ensure that package is loaded after this package. To do so, add ``"moc/notfound": "*"`` to the package's ``require`` section in it's ``composer.json``. diff --git a/Resources/Private/Fusion/Root.fusion b/Resources/Private/Fusion/Root.fusion index c15f6d9..4c8deeb 100644 --- a/Resources/Private/Fusion/Root.fusion +++ b/Resources/Private/Fusion/Root.fusion @@ -14,6 +14,9 @@ error { @position = 'start' condition = ${statusCode >= 400 && statusCode < 500 && notfoundDocument} renderer = Neos.Fusion:Renderer { + languageDimensionName = ${Configuration.setting('MOC.NotFound.languageDimensionName')} + i18nServiceToProperLocale = ${NotFound.LocaleHelper.setCurrentFromNode(notfoundDocument, this.languageDimensionName)} + @context.site = ${notfoundDocument.context.currentSiteNode} @context.node = ${notfoundDocument} @context.documentNode = ${notfoundDocument} renderPath = '/root' diff --git a/composer.json b/composer.json index ebaf4b5..d1e98f3 100644 --- a/composer.json +++ b/composer.json @@ -16,7 +16,7 @@ } ], "require": { - "neos/neos": ">=4.3" + "neos/neos": ">=8.0" }, "autoload": { "psr-4": { From d64d05c634d836d5c65eeacb29016f6274b35d60 Mon Sep 17 00:00:00 2001 From: Denny Lubitz Date: Tue, 23 Apr 2024 23:13:37 +0200 Subject: [PATCH 2/3] BUGFIX: Set up site in determined dimension and set up I18n service with the proper locale to also show translations from XLIFF files in correct language. --- Classes/Fusion/Eel/Helper/LocaleHelper.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Classes/Fusion/Eel/Helper/LocaleHelper.php b/Classes/Fusion/Eel/Helper/LocaleHelper.php index b5c2061..52a0a10 100644 --- a/Classes/Fusion/Eel/Helper/LocaleHelper.php +++ b/Classes/Fusion/Eel/Helper/LocaleHelper.php @@ -11,7 +11,7 @@ /** * See: https://github.com/neos/neos-development-collection/issues/3190#issuecomment-730361990 - * Thanks to @kdambekalns + * Thanks to kdambekalns * * The LocaleHelper deals with i18n-related things. */ @@ -56,4 +56,4 @@ public function allowsCallOfMethod($methodName) { return true; } -} \ No newline at end of file +} From cb00e0b11ade2980af69da6a8d99f79d786891e8 Mon Sep 17 00:00:00 2001 From: Denny Lubitz Date: Tue, 23 Apr 2024 23:19:47 +0200 Subject: [PATCH 3/3] BUGFIX: Set up site in determined dimension and set up I18n service with the proper locale to also show translations from XLIFF files in correct language. --- Resources/Private/Fusion/Root.fusion | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Resources/Private/Fusion/Root.fusion b/Resources/Private/Fusion/Root.fusion index 4c8deeb..bf16e5c 100644 --- a/Resources/Private/Fusion/Root.fusion +++ b/Resources/Private/Fusion/Root.fusion @@ -15,11 +15,11 @@ error { condition = ${statusCode >= 400 && statusCode < 500 && notfoundDocument} renderer = Neos.Fusion:Renderer { languageDimensionName = ${Configuration.setting('MOC.NotFound.languageDimensionName')} - i18nServiceToProperLocale = ${NotFound.LocaleHelper.setCurrentFromNode(notfoundDocument, this.languageDimensionName)} + @context.i18nServiceToProperLocale = ${NotFound.LocaleHelper.setCurrentFromNode(notfoundDocument, this.languageDimensionName)} @context.site = ${notfoundDocument.context.currentSiteNode} @context.node = ${notfoundDocument} @context.documentNode = ${notfoundDocument} renderPath = '/root' } } -} \ No newline at end of file +}