diff --git a/Classes/Http/ReplaceGetTranslationRequest.php b/Classes/Http/TransformTranslationRequestMiddleware.php similarity index 85% rename from Classes/Http/ReplaceGetTranslationRequest.php rename to Classes/Http/TransformTranslationRequestMiddleware.php index 4b2f6d4..c43395c 100644 --- a/Classes/Http/ReplaceGetTranslationRequest.php +++ b/Classes/Http/TransformTranslationRequestMiddleware.php @@ -9,7 +9,7 @@ use Psr\Http\Message\ServerRequestInterface; use Psr\Http\Server\MiddlewareInterface; use Psr\Http\Server\RequestHandlerInterface; -class ReplaceGetTranslationRequest implements MiddlewareInterface +class TransformTranslationRequestMiddleware implements MiddlewareInterface { /** * @var string @@ -26,11 +26,6 @@ class ReplaceGetTranslationRequest implements MiddlewareInterface */ protected string $translateGetParam; - /** - * @param string $headerName - * @param string|null $reactOnPath - * @param string $translateGetParam - */ public function __construct(string $headerName, ?string $reactOnPath, string $translateGetParam) { $this->headerName = $headerName; diff --git a/Classes/Http/TranslationMiddleware.php b/Classes/Http/TranslationRequestMiddleware.php similarity index 98% rename from Classes/Http/TranslationMiddleware.php rename to Classes/Http/TranslationRequestMiddleware.php index 78d4b2e..d25bc3d 100644 --- a/Classes/Http/TranslationMiddleware.php +++ b/Classes/Http/TranslationRequestMiddleware.php @@ -17,7 +17,7 @@ use Psr\Http\Message\ServerRequestInterface; use Psr\Http\Server\MiddlewareInterface; use Psr\Http\Server\RequestHandlerInterface; -class TranslationMiddleware implements MiddlewareInterface +class TranslationRequestMiddleware implements MiddlewareInterface { /** * @var string diff --git a/Configuration/Objects.yaml b/Configuration/Objects.yaml index 14ebadb..196f3a3 100644 --- a/Configuration/Objects.yaml +++ b/Configuration/Objects.yaml @@ -1,5 +1,5 @@ -DigiComp:TransformTranslationRequest: - className: "DigiComp\\FlowTranslationEndpoint\\Http\\ReplaceGetTranslationRequest" +DigiComp.FlowTranslationEndpoint:TransformTranslationRequestMiddleware: + className: "DigiComp\\FlowTranslationEndpoint\\Http\\TransformTranslationRequestMiddleware" arguments: 1: setting: "DigiComp.FlowTranslationEndpoint.headerName" @@ -8,17 +8,25 @@ DigiComp:TransformTranslationRequest: 3: setting: "DigiComp.FlowTranslationEndpoint.replaceRoutedEndpoint.translateGetParam" -DigiComp:TranslationResponseCache: +DigiComp.FlowTranslationEndpoint:TranslationResponseCache: className: "Neos\\Cache\\Frontend\\StringFrontend" - factoryObjectName: Neos\Flow\Cache\CacheManager - factoryMethodName: getCache + factoryObjectName: "Neos\\Flow\\Cache\\CacheManager" + factoryMethodName: "getCache" arguments: 1: - value: DigiComp_FlowTranslationEndpoint_Responses + value: "DigiComp_FlowTranslationEndpoint_Responses" -DigiComp\FlowTranslationEndpoint\Http\TranslationMiddleware: +DigiComp.FlowTranslationEndpoint:TranslationRequestMiddleware: + className: "DigiComp\\FlowTranslationEndpoint\\Http\\TranslationRequestMiddleware" + autowiring: true arguments: 1: setting: "DigiComp.FlowTranslationEndpoint.headerName" + 2: + object: "Neos\\Flow\\I18n\\Service" + 3: + object: "Neos\\Flow\\I18n\\Xliff\\Service\\XliffFileProvider" + 4: + object: "Neos\\Flow\\I18n\\Detector" 5: - object: "DigiComp:TranslationResponseCache" + object: "DigiComp.FlowTranslationEndpoint:TranslationResponseCache" diff --git a/Configuration/Settings.yaml b/Configuration/Settings.yaml index 374483e..727af5a 100644 --- a/Configuration/Settings.yaml +++ b/Configuration/Settings.yaml @@ -4,10 +4,10 @@ Neos: middlewares: translationReplace: position: "before translation" - middleware: "DigiComp:TransformTranslationRequest" + middleware: "DigiComp.FlowTranslationEndpoint:TransformTranslationRequestMiddleware" translation: position: "start 100" - middleware: "DigiComp\\FlowTranslationEndpoint\\Http\\TranslationMiddleware" + middleware: "DigiComp.FlowTranslationEndpoint:TranslationRequestMiddleware" DigiComp: FlowTranslationEndpoint: diff --git a/README.md b/README.md index 0c0294d..632bf41 100644 --- a/README.md +++ b/README.md @@ -6,7 +6,7 @@ This package is designed to help bringing needed translations to javascript comp Other solutions, which would generate files available for usage in client scope, have the disadvantage that one would have to repeat the relativ complex overriding and merging logic of Flow. With this endpoint you can get the same content, as you would get, if you call the translation service with your translation id. -The main components are a `CurrentHtmlLangViewHelper`, which is intended to be used to fill the `lang` attribute of the `html` tag, so the frontend knows, which language is currently active (and is good practice anyway) and a `TranslationMiddleware`, which will respond to any request, which have a `X-Translation-Request` header, carrying a pattern of translation ids which should be returned. +The main components are a `CurrentHtmlLangViewHelper`, which is intended to be used to fill the `lang` attribute of the `html` tag, so the frontend knows, which language is currently active (and is good practice anyway) and a `TranslationRequestMiddleware`, which will respond to any request, which have a `X-Translation-Request` header, carrying a pattern of translation ids which should be returned. For example: ```` @@ -45,4 +45,4 @@ async function translate(idPatterns) { } ``` -If, for whatever reason, you prefer to have a "traditional" single endpoint, which works without a custom header, you can set `DigiComp.FlowTranslationEndpoint.replaceRoutedEndpoint.reactOnPath`. At this point a middleware translates all incoming requests and the GET parameter `idPatterns` (you can change the name in Settings.yaml). +If, for whatever reason, you prefer to have a "traditional" single endpoint, which works without a custom header, you can set `DigiComp.FlowTranslationEndpoint.replaceRoutedEndpoint.reactOnPath`. At this point a second middleware (`TransformGetTranslationRequestMiddleware`) transforms all incoming requests and the GET parameter `idPatterns` (you can change names in Settings.yaml).