Plugin

Developer
Supported

Browser Sniff

ExpressionEngine 2

Back to this add-on's main page
View Other Add-ons From Laisvunas

     

You must be logged in to post.

Browser language sniff

Feature Request

gizmothecat
gizmothecat

Hi,

could you add the possibility to get the browser language?

Best Regards

Alex

Laisvunas
# 1
Developer
Laisvunas

Hi,

Browser sends in the headers the list of preferred languages and numbers indicating how much each language is preferred.

Do you need to output:

1) the most preferred language?

2) or all preferred languages in order of how much each is preferred?

3) or to output “yes/no” in case certain language is/is not among preferred languages?

Laisvunas
# 2
Developer
Laisvunas

Hi again,

It seems, that the best approach would be to output “negotiated language” using http_negotiate_language function of the pecl_http package, isn’t it?

Laisvunas
# 3
Developer
Laisvunas

Hi again,

I relesed version 2.2 of Browser Sniff plugin.

In this version there is new variable “browser_sniff_negotiated_language” and new parameter - “available languages”.

Use it as follows (first laguage in pipe delimited list is default site’s language):

{exp:browser_sniff available_languages="fi|se|en"}

{if browser_sniff_negotiated_language 
== "se"}

here goes content 
for Swedish speakers

{if
:elseif browser_sniff_negotiated_language == "en"}

here goes content 
for English speakers

{if
:else}

here goes 
default content in Finnish

{
/if}

{
/exp:browser_sniff} 
gizmothecat
# 4
gizmothecat

Thank you for that!

I will give it a try to see if it works well for my case.

Regards

Alex

Juan Carlos
# 5
Juan Carlos

Hi,

Is there a way to get this stored as a variable? it works pretty well but i don’t know how this can scale and it would be more efficient to store it once per visitor or session.

Regards,

Laisvunas
# 6
Developer
Laisvunas

Hi,

You can store any variable Browser Sniff outputs using Cookie Plus plugin.

E.g. you can use the code as this (notice parameter “parse”!)

{exp:browser_sniff available_languages="fi|se|en" parse="inward"}

{exp
:cookie_plus:set name="lang" value="{browser_sniff_negotiated_language}" seconds="36000"}

{
/exp:browser_sniff}