Active
Project:
Boost
Version:
6.x-1.21
Component:
Internationalization
Priority:
Normal
Category:
Support request
Assigned:
Unassigned
Reporter:
Created:
12 Apr 2010 at 13:25 UTC
Updated:
23 Mar 2013 at 17:20 UTC
Jump to comment: Most recent file
Comments
Comment #1
mikeytown2 commentedBrowser detection would be done at the Apache level or JavaScript level since PHP is not run serving a page from the boost cache.
Apache would use
HTTP_USER_AGENTto give them the correct page on the first requesthttp://www.askapache.com/htaccess/mod_rewrite-variables-cheatsheet.html
http://stackoverflow.com/questions/1005153/auto-detect-mobile-browser-vi...
JavaScript would have to redirect after the page loaded to the correct page.
http://www.quirksmode.org/js/detect.html
Just wondering how does
Path prefix with language fallbackwork exactly? Examples would be helpful.Comment #2
mikeytown2 commentedMore Notes
http://httpd.apache.org/docs/trunk/mod/mod_mime.html#addlanguage
http://api.drupal.org/api/function/language_from_browser/6
http://my.opera.com/cstrep/blog/2010/01/23/my-opera-front-page-caching-a...
http://tech-blog.borychowski.com/index.php/2009/03/htaccess/redirect-acc...
http://stackoverflow.com/questions/1661915/how-to-redirect-based-on-acce...
http://httpd.apache.org/docs/trunk/content-negotiation.html
Comment #3
fthieme commentedforget what I said...
From the settings page:
Path prefix with language fallback. The presentation language is determined by examining the path for a language code or other custom string that matches the path prefix (if any) specified for each language. If a suitable prefix is not identified, the display language is determined by the user's language preferences from the My Account page, or by the browser's language settings. If a presentation language cannot be determined, the default language is used.
Comment #4
mikeytown2 commentedThinking about this issue; I need to replicate Drupal's language_from_browser() in apache. Something that can't be done. lighttpd should be able to & I bet nginx can as well. One thing they both need is the language_list() from Drupal so it knows what languages it can match to.
Looking at this: http://tech-blog.borychowski.com/index.php/2009/03/htaccess/redirect-acc...
Using apache the best one could do is match on the first language & if none was found default to one picked by you. Lets say your site supports German (de) French (fr) and English (en); with English as the default.
These UNTESTED rules would go above the boost rules
Option B
If request doesn't have a language prefix use PHP to select one. This would require a database bootstrap with the these 2 variables from the variable table (language_count & language_default).
PHP Code would kinda look like this UNTESTED code called boost_language.php
The htaccess rules would go above boost and look this this; once again UNTESTED code
Comment #5
seg108 commentedThanks for the detailed suggestions. Option A gives me a redirect loop. Not familiar territory for me, so unsure how to proceed. I adapted only slightly for my languages:
Comment #6
mikeytown2 commentedTry this
Comment #7
seg108 commentedLooping: enenenen
Comment #8
mikeytown2 commentedBeen playing around with this. If you have global redirect on to redirect all urls to the clean version then this might work exactly how it should.
Comment #9
seg108 commented404. With "non-clean to clean" on (global redirect), seeing site, but returns 404 error for all pages. Deslash is off.
Comment #10
mikeytown2 commentedtry this
Also put this in http://drupal.org/project/search404. It will say what the url was trying to access in the textfield (search box) when you hit a 404
Comment #11
fthieme commentedThe problem is, that everything is localized. Some queries aren't prefixed with /en/ or something and will be prefixed by these rules, making them fail.
My last attemt was this:
Comment #12
seg108 commentedHere is solution I am now using for front page only:
Comment #13
giorgosksolution #12 works like a charm
maybe it can be documented in the readme.txt as a workaround for language negotiations
Comment #14
funature commentedi'm also looking for a solution for this problem. #12 is a good one, but there is a problem, if the user's browser language is "et", it will be redirected to /et, but when the user wanna visit the english vision, it will be redirected to /et again, not the english frontpage. that means, when the browser language is not the drupal-default-language, the vistor can not go to the drupal-default-language frontpage.
Comment #15
mikeytown2 commented/en for English would work correct?
Comment #16
funature commentedhttp://www.saaremaaestonia.com/ as example, if you set the language "et" as your browser default language, and you visit http://www.saaremaaestonia.com/, you will be redirected to http://www.saaremaaestonia.com/et, then if you want to visit the english version of the website, it is impossible unless you change the default browser language to english.
Comment #17
mikeytown2 commented/en get's redirected to the root... you could set a cookie via hook_boot and in the htaccess rules check for the cookie. Cookie would be their preferred language.
Comment #18
funature commentedsorry. i don't know how to do that. is there an example?
Comment #19
janton commentedIs there already some smart solution for this?
or also in general how to get browser language detection with path prefix working with boost..
I will try to find a work around, but i'm not really that great of a programmer.
Comment #20
janton commentedok stuppid i did not read the thing about .htacces cookie.
but perhaps i don't need it because straingly i remember it worked already in boost, perhaps this is already implemented?
Comment #21
hamsterbacke42 commented#12 worked for me and I can still switch between languages without any problem
Comment #22
fabianx commentedJust check referer ...
There is even somewhere a generator to generate such .htaccess language code automatically.
I only have the varnish rule here at the moment, but it should be easy to transfer this to .htaccess code:
So just checking for:
RewriteCond %{HTTP:Referer} www\.example\.com [NC]
should do the trick ...
Best Wishes,
Fabian
Comment #23
mrfelton commentedI wonder if anyone has these rules for nginx?
Comment #24
jimyhuang commentedHere is our example at drupal 6, especially for sub directory. This should even works without boost.
Comment #25
gagarine commentedI did a configuration for nginx and D7... It works but I'm not sure is the best way to achieve this.
I created a map
And I set a conditional redirection than check if arguments are empty
Complete config https://gist.github.com/3247690
Comment #26
jalves commentedHey!
#12 worked pretty well!
Why the rule is using temporary redirect (302) shouldn't we use permanent redirect (301)?
I don't really know what is the best but based in same research i made about that code i'm a little bit confused..
Comment #27
kspal commentedQuadruple thanks for this post and especially #12. My sites' homepage are now fast as expected (in D7.20 + boost)
Comment #28
maxilein commentedHere is the solution that worked for me (Drupal 6).
a) browser language detection for front / page while Boost is caching. From #12.
b) I also did want to always have the language prefix for the default language:
In order to make that work I had to take a hack for core (ugly! but in my case harmless. Test! If you use that) I found here: http://eureka.ykyuen.info/2011/06/19/drupal-force-path-prefix-for-defaul...
Then I added this to htaccess:
Patch to language.inc attached. See for comments where to add into htaccess.