Global Domination
Flash Player is an international affair. Thus, the Player would like to automatically detect which language it should use when presenting localized textual information. According to this page, one way to detect the user's preferred language is to examine the LANG environment variable. That seems to have wide acceptance. However, I noticed that on my Gentoo system, that string is not set by default (in fact, none of the default environment variables indicate "en").
This is why I wanted to solicit feedback: Is LANG the best method? Are there alternative methods I should use in conjunction with LANG?
Another issue: Input method editor (IME). What facilities are available, stable, and hopefully more or less standard for this?
Comments
I run gentoo as well. I think that this is the best method, but just as a precaution, you should enable EN as a default language for you and I. OR possibly ask the person if a language could not be found.
Posted by: Lunarcloud | June 21, 2006 09:19 AM
The usual way to do this to first check LC_ALL variable and if non-existent check LANG variable. Btw Flash Player needs a Turkish translation and we ( Pardus Linux Team ) would like to help about it. You can use email me or find cartman in #ffmpeg/#mplayerdev :-)
P.S: LC_ALL/LANG can be in two flavours 1) tr_TR means Turkish with default encoding (iso-8859-9) and 2) tr_TR.UTF-8 means Turkish with UTF-8 encoding.
Posted by: cartman | June 21, 2006 09:28 AM
Most distributions do have $LANG set, though, so this is more of an annoyance than a problem. Does anyone know of a distribution other than gentoo that doesnt set it? For those that don't have it set, I don't think it would be that much of an inconvenience to have the installer ask them.
Posted by: mark pinto | June 21, 2006 10:16 AM
The LANG variable is used in many Linux distributions to set the system encoding
In my Ubuntu box for example an echo $LANG returns:
fr_FR.UTF-8
But for other distributions, I think it would be nice to check, if possible, the User-Agent of the internet browser to check what language the user is using.
Posted by: Skateinmars | June 21, 2006 10:23 AM
The correct way to handle it is to :
look to LC_ALL, and follow what is here if it is set, if not, look to LC_MESSAGES and use what is there if it is set, and only then look to LANG, and follow it. Not that the function of locale.h (part of libc) do this as it should be done that is setlocale(LC_MESSAGES, NULL) return the language you should use for messages to the user.
Posted by: vanicat | June 21, 2006 10:30 AM
Yes, LANG and LC_ALL are the right way to do it. And I think that if LC_MESSAGES is set it overrides both. And yes in Gentoo locale is not set by default. As far as I know you need to set it yourself like many other things in Gentoo. Instructions for localizations in Gentoo are here:
http://www.gentoo.org/doc/en/guide-localization.xml
Posted by: Jure Repinc | June 21, 2006 10:47 AM
Hey!, I think defaulting to utf-8 unless LANG is specified would be great! I think it's common for it not to be set on gentoo UNLESS you have a different language than english. in anycase I know in japan SHIFT-JIS is still used quite often which is not compilent with utf-8 in a sence. I would say en.UTF-8 would be nice otherwise look and just ask the first time suggesting what you've found. Good luck!
Posted by: Mr.Arf!Arf! | June 21, 2006 11:03 AM
The 'locale' command (on Ubuntu at least) gives all the locale information. It might be worth delving into it's ubiquity or -- failing that -- the source to see where it gets the info.
Posted by: Tom | June 21, 2006 11:12 AM
man setlocale describes the variables pretty well, IIRC, including order of looking at them. If you really need to know the language (as opposed to e.g. using gettext with current locale), you may find this useful: have a look at wxLocale::GetSystemLanguage() method from wxWidgets toolkit (http://www.wxwidgets.org). I don't suggest you cut&paste the code, obviously, but the method used works very well. And if you wanted to reuse the code, you can, the license explicitly permits distribution of your app's binaries with no restrictions...
Posted by: vx | June 21, 2006 11:40 AM
Use Gtk. Gtk is what XUL use on Linux for Firefox, and Gtk will provide everything you need for the problem mentionned above. Okay that include ditching Motif, but who use that anymore. Even Acroread got rid of it.
Posted by: Hub | June 21, 2006 01:26 PM
You can check the locale simply by examining LC_MESSAGES or LANG if it is not set.
If you can, and in this case it is quite simple to do so, avoid using Gtk or any other specific toolkit, as it adds unneeded dependencies, and overhead. Not everybody on linux use niether Gnome. nor Gtk at all.
Posted by: Roie | June 21, 2006 03:42 PM
Seems perfectly natural that the browser language should be also the language of the flash plugin.
It's a question of integrity.
So yeah, I think you should check the browser language.
Posted by: Mariusz Potocki | June 21, 2006 06:00 PM
Although some have suggested defaulting to utf-8 locale, the correct default locale is "POSIX", which is english and ASCII-only. The fallback of LC_ALL -> LC_MESSAGES -> LANG is correct, but note that that's only for message strings - there are a lot of locale variables; you can get a list from running 'locale'. See the POSIX spec, or the Single Unix Specification (section seven) for more details. You can read the SuS at http://www.unix.org/version3/online.html
As for input methods, the most portable method would be to implement the XIM protocol. Optionally you could use the uim or scim libraries or something as well, but usually those have XIM wrappers.
Posted by: bd_ | June 21, 2006 08:19 PM
Hello!
On debian systems we have by default the following environment variables that points the system language:
cyrax@opteron12.nsa:/opt$ env | grep pt_BR
LC_ALL=pt_BR
LC_MESSAGES=pt_BR
LANG=pt_BR
LANGUAGE=pt_BR
So, you see that we found LANG, LANGUAGE, LC_ALL and LC_MESSAGES.
LC_* are provenient from locales and I think that Is not platform-wide, but I could be wrong.
LANG is a LSB default (i think so, as it is present on almost all Distros that I know, but strangely not on Gentoo...)
Altought, I think that is a VERY GOOD IDEA to follow the language setted on the browser, not on the O.S. as the user will install the player on the "Browser Environment", so probably he will want everything around it (extensions, themes, plugins, ...) on the same language.
It is really easy to get the location/language variables from Firefox (and I think that is true for all Mozilla browsers).
For Konqueror you can simply grab it from KDE.
Also, if you don't want to code such a Language detection that must handle several types of browsers and environments to guess the language, just ask the user on the installation... it will not be a shame! :)
Cheers and Good Luck!
off_the_records("Are there any predictions for a beta?!?!? Are you getting Flash Videos OK??? Will it be a 8.x or a 9.x release??? I think you should put some pressure on Adobe to release those info to the Linux community. thousands of people are hoping for that!");
Posted by: Ygor Lemos | June 21, 2006 09:01 PM
Hi,
I can't find any contact information, but I REALLY want to report a seriour bug that happens on Gack-based browsers like Firefox, Mozilla, Flock, etc...
When you have a Flash animation in a site, the object stays on top of everything, and we can't override it even using CSS Z-Index.
I think this probably be a bug on Firefox but as it happens strictly with Flash I really think that you should contact the Mozilla Staff and try to figure out togheter with them a solution for this problem.
Just enter on Adobe site (from FF on Linux) and see the top-menu getting overriden by the Flash animation above it, the menu just stays behind it forever compromising the site navigability.
Cheers and Good Luck!
Posted by: Ygor Lemos | June 21, 2006 09:23 PM
Is there a way for the plugin to know what language the browser has? One can figure out the language the same way as a web page do.
Posted by: Jonas | June 22, 2006 02:44 AM
As a matter of fact, it is possible for a plugin to obtain the browser's user agent string with NPN_UserAgent(): http://devedge-temp.mozilla.org/library/manuals/2002/plugin/1.0/npn_api19.html
So that remains an option, or perhaps an auxiliary source of information.
Posted by: Mike Melanson | June 22, 2006 09:13 AM
For the empiric study :)
LANG was set as default on
*Fedora Core 5
*Fedora Core 4
*Nokia 770 (Debian) (only lang_COUNTRY without Encoding)
Posted by: Fabian | June 23, 2006 04:10 AM
Data for your studies:
System: Fedora Core 5 standard installation.
System language: German, UTF-8
Important variables:
$ echo $LC_ALL
$ echo $LC_MESSAGES
$ echo $LANG
de_DE.UTF-8
$ locale
LANG=de_DE.UTF-8
LC_CTYPE="de_DE.UTF-8"
LC_NUMERIC="de_DE.UTF-8"
LC_TIME="de_DE.UTF-8"
LC_COLLATE="de_DE.UTF-8"
LC_MONETARY="de_DE.UTF-8"
LC_MESSAGES="de_DE.UTF-8"
LC_PAPER="de_DE.UTF-8"
LC_NAME="de_DE.UTF-8"
LC_ADDRESS="de_DE.UTF-8"
LC_TELEPHONE="de_DE.UTF-8"
LC_MEASUREMENT="de_DE.UTF-8"
LC_IDENTIFICATION="de_DE.UTF-8"
LC_ALL=
Posted by: liquidat | June 26, 2006 11:15 AM
for US-Englisch there's also "C" used, instead of "en_US". That's because this is the default language, if no language packs are installed.
Posted by: Kai F. Lahmann | June 26, 2006 05:23 PM
It should be striken again that the correct way to do it is by using the libc's setlocale function (esp. with the LC_MESSAGES flag), _not_ by directly inspecting environment variables.
Posted by: Ilya Konstantinov | June 27, 2006 12:01 AM
LANG variable is the best way to determined the locale.
However there's standard libc low-level functions to get and set the locale. Please see : http://www.gnu.org/software/libc/manual/html_node/Setting-the-Locale.html#Setting-the-Locale
Please note that when you have LANG=C , this means Posix and you should fall back to English
Posted by: FACORAT Fabrice | June 27, 2006 10:14 AM
Please, don't examine environment variables directly. man 7 locale for a primer on handling locales in C. And most linux environments use en.UTF-8 as the default encoding (as UTF-8 is a superset of ASCII and encoded strings don't have null bytes in them).
Posted by: Tassos Bassoukos | June 28, 2006 05:36 AM
I don't agree with the majority of the above comments.
IGNORE LOCALE COMPLETELY!
Use the header the browser sends to the web server : "Accept-Language"
On my firefox install, it defaults to "en-us,en;q=0.5"
Get your web logs to log this header, you'll see that most non-english speakers have this set correctly.
Not only does it allow 'fallback' if a language isn't avaiable, but it will be in sync with the browser itself, AND it's a CROSS-PLATFORM mechanism you can use in the generic flash code for all browsers.
I'd bet £0.01 that more linux installs have this set correctly than they do the unix locale.
Posted by: Jamie | June 28, 2006 11:27 PM
I have to disagree with Jamie. The right way to detect a locale is described in a previous comment by Tassos Bassoukos.
If you only want to use the detected locale for interface of the flash player itself, then it has nothing to do with the preferred language for webpages (browser itself may or may not be localized too, right?).
Posted by: RQ | June 30, 2006 08:05 AM
Macromedia Flash Player is another excellent Flash Player
Posted by: cucu | July 4, 2006 12:20 AM
Can you make it so in Soviet Russia, Flash Player plays YOU?
Posted by: George | July 25, 2006 07:34 AM
Flash does not necessarily run in a browser. It is also used for many other purposes as a standalone player. Making the localisation process depend on a browser will break it for standalone.
Posted by: Joshua Mostafa | October 11, 2006 03:55 PM
I sorry...but you all have missed another possible GUI option for getting the locale! Right-click menus! Sure, you can look at the enviorment variables, or look at locale in C, but a user could just right-click on a flash animation, and then choose (something like this) Locale/Language -> en_US (or en_UK, es_MX, etc). Should be easy enough.
Combo of ask-at-install and this right-click menu is something I'd see working very well. My own opinion!
Posted by: Zenix | October 13, 2006 03:00 PM