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

Language autodetection in all urls #875

Closed
juanfran-granados opened this issue Aug 26, 2020 · 8 comments
Closed

Language autodetection in all urls #875

juanfran-granados opened this issue Aug 26, 2020 · 8 comments
Labels
core Core functionalities, including the admin section enhancement New feature or request

Comments

@juanfran-granados
Copy link

Hello,

First of all, thanks for going on with this development. I currently work with qTranslate-x in a WordPress Multisite and I would like to discuss something we've been doing for years, language autodetection in all urls.

We commented the condition related to being at the home page (qtranslate_core.php):

if ( ! $lang && $q_config['detect_browser_language']
         && ( ! isset( $_SERVER['HTTP_REFERER'] ) || strpos( $_SERVER['HTTP_REFERER'], $url_info['host'] ) === false )//external referrer or no referrer
	 // This condition.
         //&& ( empty( $url_info['wp-path'] ) || $url_info['wp-path'] == '/' ) // home page is requested
    ) {
        $lang                     = qtranxf_http_negotiate_language();
        $url_info['lang_browser'] = $lang;
    }

And then we handled the url translation (we are using also qtranslate-slug) in the filter qtranslate_language_detect_redirect. It's been working in 800 sites for years, with not knwown problem.

Maybe there is a better approach to what I'm doing. At least, I would like to know if you are open to add an option to switch on/off the home condition. With that, I won't need to comment that line of code.

Thanks!

@herrvigg herrvigg added the core Core functionalities, including the admin section label Sep 5, 2020
@herrvigg
Copy link
Collaborator

That's a good question.

I don't know why there is this condition. There must have been good historical reasons. Maybe the fear was that you would get different language results depending on the URL you are requesting, which could make the language switch too often, but i don't think this would create some infinite redirections.

Maybe we can enable for all paths as you suggest and see what happens. It wouldn't be hard to revert in any case.

@herrvigg herrvigg added the enhancement New feature or request label Sep 20, 2020
@herrvigg
Copy link
Collaborator

The underlying function we use is this: https://php.uz/manual/en/function.http-negotiate-language.php

I don't think this is related to the current URL at all but only to the browser settings.

Maybe there was a concern about performance. Having the check on the home page made it more explicit and restricted. If we remove the path check, this code would be run on every URL request for the front side. But would that be a problem? I don't think so.

@herrvigg
Copy link
Collaborator

In the original qTranslate (before qTranslate-X), this check didn't exist. The change was done in 2015 in pre-release 3.2.8 but i can't find any explanation yet about this change...

Here is the commit introducing this check:
qTranslate-Team/qtranslate-x@94d69cd#diff-de264f66703d65150603d9c49ffd2a6f

@herrvigg
Copy link
Collaborator

I just pushed a fix to master. We can experiment a bit here before next release. I keep the ticket open until then.

@juanfran-granados
Copy link
Author

Thanks @herrvigg!! I plan to test it next week.

The only issue we've detected having this logic enabled in all pages is that in W3TC we needed to check late init in page cache. That makes qTranslate execute language auto detect prior to W3TC page cache logic.

@herrvigg
Copy link
Collaborator

herrvigg commented Oct 3, 2020

we needed to check late init in page

What does this mean? How do you do that?

I used W3TC a long time ago but finally removed it, i found it to be slow and creating more problems more than it solves.

@juanfran-granados
Copy link
Author

Settings

We needed to check this late caching setting in order to let qTranslate execute before W3TC page cache logic starts.

@herrvigg
Copy link
Collaborator

Released in 3.9.1.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
core Core functionalities, including the admin section enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants