Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handling sys_lanugage_uid in rest calls #46

Closed
rorentz opened this issue Sep 6, 2018 · 9 comments
Closed

Handling sys_lanugage_uid in rest calls #46

rorentz opened this issue Sep 6, 2018 · 9 comments

Comments

@rorentz
Copy link

rorentz commented Sep 6, 2018

It is more a question than an issue.
What is the best way to realize routes for getting objects in the localized way.
Calling for example a route /rest/getnews gives me all news objects for sys_language_uid = 0.
How do i get the localized objects?

I am looking forward for an answer.

By the way, i like your extension very much !!!!

@cundd
Copy link
Owner

cundd commented Sep 6, 2018

There are different ways:

a) Add L= to the request URI
b) Send the Accept-Language header and configure the mapping in plugin.tx_rest.settings.languages. (e.g. Accept-Language: de and TS plugin.tx_rest.settings.languages.de = 1)

@rorentz
Copy link
Author

rorentz commented Sep 6, 2018

Great, working with the Accept-Language header i like.
When i debug $GLOBALS['TSFE']->sys_language_uid; in the controller, where the repository call happens, i then get the value1. But when i receive the extbase object from the repository the one with sys_language_uid = 0 is returned.

Am i missing some setup ?

May be to you have a working example?

@cundd
Copy link
Owner

cundd commented Sep 6, 2018

I've got only single language installations of REST at the moment.

Could the problem have to do with https://forge.typo3.org/issues/57272 or does the localization work outside the REST extension?

@rorentz
Copy link
Author

rorentz commented Oct 3, 2018

I will give it a try. Thank you very much!

@rorentz
Copy link
Author

rorentz commented Nov 6, 2018

Okay, for domain objects it works, but the LocalizationUtility does not respect the language and show the default labels.

The solution would be to add the following in the Bootstrap.php:

`
/**
* Configure the system to use the requested language UID
*
* @param TypoScriptFrontendController $frontendController
*/
private function setRequestedLanguage(TypoScriptFrontendController $frontendController)
{
// Set language if defined
$requestedLanguageUid = GeneralUtility::_GP('L') !== null
? intval(GeneralUtility::_GP('L'))
: $this->getRequestedLanguageUid($frontendController);

    if (null !== $requestedLanguageUid) {
        $frontendController->config['config']['sys_language_uid'] = $requestedLanguageUid;
        // Add LinkVars and language to work with correct localized labels
        $frontendController->config['config']['linkVars'] = 'L(int)';
        $frontendController->config['config']['language'] = $_SERVER['HTTP_ACCEPT_LANGUAGE'];
    }
}

`

Can you please implement that ? Would be great !

Thank YOU!

cundd added a commit that referenced this issue Feb 7, 2019
@cundd
Copy link
Owner

cundd commented Feb 7, 2019

Hy!

Sorry for the delay. I implemented the changes in eb40715. Can you have a look?

@rorentz
Copy link
Author

rorentz commented Feb 10, 2019

Seems to work!

@cundd cundd closed this as completed Feb 10, 2019
@rorentz
Copy link
Author

rorentz commented May 6, 2019

@cundd : In which version have you included the fix ? I do not really find it in the repo. Thank you so much.

@cundd
Copy link
Owner

cundd commented May 6, 2019

It's only in the git Repository yet. In branch v4

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants