diff --git a/Classes/Http/TranslationRequestMiddleware.php b/Classes/Http/TranslationRequestMiddleware.php index a91b47e..207d073 100644 --- a/Classes/Http/TranslationRequestMiddleware.php +++ b/Classes/Http/TranslationRequestMiddleware.php @@ -8,7 +8,6 @@ use GuzzleHttp\Psr7\Response; use Neos\Cache\Exception as CacheException; use Neos\Cache\Exception\InvalidDataException; use Neos\Cache\Frontend\StringFrontend; -use Neos\Flow\Annotations as Flow; use Neos\Flow\I18n\Detector; use Neos\Flow\I18n\Service; use Neos\Flow\I18n\Xliff\Service\XliffFileProvider; diff --git a/Classes/ViewHelpers/ParameterNameViewHelper.php b/Classes/ViewHelpers/ParameterNameViewHelper.php new file mode 100644 index 0000000..62f806d --- /dev/null +++ b/Classes/ViewHelpers/ParameterNameViewHelper.php @@ -0,0 +1,22 @@ +parameterName; + } +} diff --git a/Classes/ViewHelpers/UriViewHelper.php b/Classes/ViewHelpers/UriViewHelper.php new file mode 100644 index 0000000..fb2a3be --- /dev/null +++ b/Classes/ViewHelpers/UriViewHelper.php @@ -0,0 +1,22 @@ +reactOnPath; + } +} diff --git a/README.md b/README.md index 7a11702..6475265 100644 --- a/README.md +++ b/README.md @@ -8,6 +8,9 @@ Other solutions, which would generate files available for usage in client scope, 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, where the request path equals `DigiComp.FlowTranslationEndpoint.reactOnPath` (Default: "/xliff-units"), and search for unit patterns in the `DigiComp.FlowTranslationEndpoint.getParameterName` (Default: "idPatterns"). +"idPatterns" is built with following syntax: +`packageName:catalogName|SEARCH_REGEX, ANOTHER PATTERN...` + For example: ```` GET /xliff-units?idPatterns=Neos.Flow:Main|authentication.* @@ -30,12 +33,17 @@ would return all translation keys from the main unit of `Neos.Flow` starting wit To let the middleware know, in which langauge the translated units should be, you should set the correct `Accept-Language`-Header with your request, which you obtained from the `lang` attribute of the `html` element. +Given your HTML head looks like that: +```html + +``` + Your JavaScript could look like that: ```javascript async function translate(idPatterns) { - const uri = new URL('/xliff-units', document.location); - uri.searchParams.set('idPatterns', idPatterns); + const uri = new URL(document.documentElement.dataset.xliffUri, document.location); + uri.searchParams.set(document.documentElement.dataset.xliffParameter, idPatterns); const response = await fetch(uri, {headers: { 'Accept': 'application/json', 'Accept-Language': document.documentElement.lang,