Detecting FF Language?

1 view
Skip to first unread message

msk...@gmail.com

unread,
Oct 6, 2008, 9:40:25 AM10/6/08
to ubiquity...@googlegroups.com
Hello,

I am putting together a command for a belgian friend. The website I am doing this for offers the French or Dutch fork right up front. I was wondering how I can read FF's default language? Any hints?


Thanks in advance..

--
Mayuresh

Fernando Takai

unread,
Oct 6, 2008, 10:15:00 AM10/6/08
to ubiquity...@googlegroups.com
You can see the FF default locale using this:

function cmd_lang(){
   var lang = Application.prefs.get("general.useragent.locale");
   displayMessage(lang.value);
}

There's a way of doing that using Components but i really don't remember right now.

msk...@gmail.com

unread,
Oct 6, 2008, 10:44:27 AM10/6/08
to ubiquity...@googlegroups.com
Thanks, does this come from Ubiquity or FF? Or are they both the same?? :-)
--
Mayuresh

msk...@gmail.com

unread,
Oct 6, 2008, 10:50:06 AM10/6/08
to ubiquity...@googlegroups.com
On second thoughts, I found that. It seems to come from FF config.

Actually that is confusing, since I have my languages set to "en-GB". This seems to come up in "intl.acceptlanguages". Why is this is different from the above?

I guess what I am trying to know is that how do I get the language FF shows things in? I have noted that changing intl.acceptlanguages seems to take me to a different version of google (".co.uk" presently instead of ".com" when it was en-US)
--
Mayuresh

Fernando Takai

unread,
Oct 6, 2008, 11:04:00 AM10/6/08
to ubiquity...@googlegroups.com
Well, intl.acceptlanguages is a comma separated string -- you configured them on preferences.
My list is: en-us,pt-br,pt,en

So, ff will ask first for the american english site, them for the brazilian portuguese one....

I think ff uses first the intl.acceptlanguages and them the useragent, but i'm not an firefox expert (yet).

msk...@gmail.com

unread,
Oct 6, 2008, 11:13:38 AM10/6/08
to ubiquity...@googlegroups.com
I thought so too. And I am not a FF expert either. So it would be nice to have an authoritative answer (Mozilla Staff??) ;-)

- Mayuresh
--
Mayuresh

Fernando Takai

unread,
Oct 6, 2008, 11:27:20 AM10/6/08
to ubiquity...@googlegroups.com
Just trying changing my intl.accept_lanaguages to "pt-br, en-us" and it changes my google homepage to google.com in portuguese - so you can use this property like this:

function cmd_lang(){
   var lang = Application.prefs.get("intl.accept_languages");
   for each(lang in lang.value.split(",")){
     // try to get the site for that lang
   }
}

Or just get the first one and use that.

Blair McBride

unread,
Oct 6, 2008, 7:05:19 PM10/6/08
to ubiquity...@googlegroups.com
The accepted languages list in intl.accept_languages is sent in the
"Accept-Language" HTTP request header, when Firefox requests any
page/file from any server. It sends the whole list all at once - and
the site will figure out what to do (if anything). The order of the
list is important: the closer a language is to the start of the list,
the higher its priority is.

The value stored in general.useragent.locale is only used for the
Firefox user interface (menus, dialogs, etc). Its not sent to servers.

So given Mayuresh's original use case, use intl.accept_languages.
Given you only want to choose between 2 languages, just see which
comes first: "fr" or "nl". Note that its possible for people to have,
for example, "en-US" but not "en" in this list.

- Blair

msk...@gmail.com

unread,
Oct 7, 2008, 2:52:50 AM10/7/08
to ubiquity...@googlegroups.com
Blair,

That was insightful. Thanks!

This has been implemented, see functions _getFirstLanguage(), _isFrench() and _isDutch() at:

http://code.google.com/p/ubiquity-commands/source/browse/trunk/scripts/ebay.ubiq.js

And the diff on my ticket has been attached to the ticket ;-)

- Mayuresh
--
Mayuresh

msk...@gmail.com

unread,
Oct 7, 2008, 2:53:40 AM10/7/08
to ubiquity...@googlegroups.com
Emm, the diff on the ticket has been "updated" (that's what happens when you try to type faster than you think).
--
Mayuresh
Reply all
Reply to author
Forward
0 new messages