qtranslate-xt icon indicating copy to clipboard operation
qtranslate-xt copied to clipboard

language needs to be shown in url

Open andreysneg opened this issue 3 years ago • 3 comments

How disable message - "language needs to be shown in url " ?

Payment gateway Paysera.com dont work and send error:

'
Warning: assert(): language needs to be shown in url - cancelled by can_redirect, url_info={ "cookie_front_or_admin_found": false, "scheme": "https", "host": "kruvid24.ee", "path": "/", "query": "wc-api=wc_gateway_paysera", "original_url": "/?wc-api=wc_gateway_paysera", "path-base": "", "doing_front_end": true, "wp-path": "/", "doredirect": "language needs to be shown in url - cancelled by can_redirect", "language": "et", "set_cookie": true } failed in /home/kruvidee/public_html/wp-content/plugins/qtranslate-xt-master/qtranslate_core.php on line 105
OK'

andreysneg avatar Sep 17 '21 13:09 andreysneg

In theory, the assert can be commented. But this means we are in a bad state that could lead to all kind of issues. I left such asserts intentionally to understand better this kind of issues.

This error means:

  • the "expected language" is not in the URL and a redirection would be required to set the language state properly,
  • but... the redirection is not allowed because the request is on admin pages, AJAX, WP_CLI, CRON or REST.

Your request appears as "doing_front_end: true" but who is triggering this? Maybe the problem comes from "cookie_front_or_admin_found": false.

herrvigg avatar Sep 18 '21 09:09 herrvigg

It surely comes from the missing cookie. In that case it will try to detect the language from the browser or HTTP_REFERER, or take the default language. The error means that the resulting language does not match the URL settings. Let's say you have en as default language and the language detection finds et as shown here. Then the expected URL is /et/?wc-api=wc_gateway_paysera.

I suppose you have the front cookies enabled but why isn't the cookie set in that case? This may depend on how this request is triggered. Maybe that should be considered as a REST request? Currently it's not.

herrvigg avatar Sep 18 '21 09:09 herrvigg

I think . Instead of this message "Language needs to be shown in url" plugin must automaticaly add Default language to url and all.

Url /?wc-api=wc_gateway_paysera - make Payment plugin and impossible change this.
I had this error with other plugins too .

Now i turned on - Detect the language of the browser and redirect accordingly. Let's see what happens.

If i comment line 446 in qtranslate_core.php what will happen ? $url_info['doredirect'] = 'language needs to be shown in url';

or do this: $url_info['doredirect'] = '' ;

or replace line 446 to: $url_info['lang_browser'] = $q_config['default_language'];;

I just need no errors to appear.

andreysneg avatar Sep 18 '21 11:09 andreysneg

Related to #1326.

herrvigg avatar Apr 17 '23 21:04 herrvigg

Fix released in 3.14.2.

herrvigg avatar Apr 19 '23 21:04 herrvigg