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?

29 Responses to Global Domination

  1. Lunarcloud says:

    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.

  2. cartman says:

    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.

  3. mark pinto says:

    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.

  4. Skateinmars says:

    The LANG variable is used in many Linux distributions to set the system encodingIn my Ubuntu box for example an echo $LANG returns:fr_FR.UTF-8But 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.

  5. vanicat says:

    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.

  6. Jure Repinc says:

    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

  7. Mr.Arf!Arf! says:

    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!

  8. Tom says:

    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.

  9. vx says:

    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…

  10. Hub says:

    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.

  11. Roie says:

    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.

  12. 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.

  13. bd_ says:

    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.htmlAs 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.

  14. Ygor Lemos says:

    Hello!On debian systems we have by default the following environment variables that points the system language:cyrax@opteron12.nsa:/opt$ env | grep pt_BRLC_ALL=pt_BRLC_MESSAGES=pt_BRLANG=pt_BRLANGUAGE=pt_BRSo, 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!”);

  15. Ygor Lemos says:

    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!

  16. Jonas says:

    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.

  17. 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.htmlSo that remains an option, or perhaps an auxiliary source of information.

  18. Fabian says:

    For the empiric study :)LANG was set as default on*Fedora Core 5*Fedora Core 4*Nokia 770 (Debian) (only lang_COUNTRY without Encoding)

  19. liquidat says:

    Data for your studies:System: Fedora Core 5 standard installation.System language: German, UTF-8Important variables:$ echo $LC_ALL$ echo $LC_MESSAGES$ echo $LANGde_DE.UTF-8$ localeLANG=de_DE.UTF-8LC_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=

  20. Kai F. Lahmann says:

    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.

  21. Ilya Konstantinov says:

    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.

  22. 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-LocalePlease note that when you have LANG=C , this means Posix and you should fall back to English

  23. 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).

  24. Jamie says:

    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.

  25. RQ says:

    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?).

  26. cucu says:

    Macromedia Flash Player is another excellent Flash Player

  27. George says:

    Can you make it so in Soviet Russia, Flash Player plays YOU?

  28. 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.

  29. Zenix says:

    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!