In one of our projects we base on the Accept-Language header and having custom middleware executed before Restlers' Dispatcher we can set request argument language and language aspect based on this header value. But it is ignored by Reslter when it initializes frontend rendering through Loader::initializeFrontendRendering(). We could probably add hook into TypoScriptFrontendController::settingLanguage() function and modify the language aspect there but i think the middleware layer is better place to handle it.
What do you think about changing the Loader::initializeFrontendRendering() function to create the Requets object this way:
so here we fetch the SiteLanguage object from the language request attribute $this->getRequest()->getAttribute('language') and we can easily modify it through middlewares.
Hi Marcin, sorry for my late response. I think also that middleware is the right place to do this. You can create a pull-request for this feature and we have a look for it soon.
What is the proper way to change the request language used by Restler?
From what i see the language used by frontend controller is set in https://github.com/AOEpeople/TYPO3_Restler/blob/main/Classes/System/TYPO3/Loader.php#L213 using the site default language.
In one of our projects we base on the
Accept-Language
header and having custom middleware executed before Restlers' Dispatcher we can set request argumentlanguage
and language aspect based on this header value. But it is ignored by Reslter when it initializes frontend rendering through Loader::initializeFrontendRendering(). We could probably add hook into TypoScriptFrontendController::settingLanguage() function and modify the language aspect there but i think the middleware layer is better place to handle it.What do you think about changing the Loader::initializeFrontendRendering() function to create the Requets object this way:
so here we fetch the
SiteLanguage
object from thelanguage
request attribute$this->getRequest()->getAttribute('language')
and we can easily modify it through middlewares.