[sword-devel] swlocale question

Jonathan Marsden jmarsden at fastmail.fm
Thu Sep 3 23:51:36 MST 2009


Matthew Talbert wrote:

> This code could, and probably should, be incorporated into the engine.
> It deals nicely with locales presented in the typical *nix way. For
> Windows, you would have to convert the locale into a *nix style
> format. We're using a glib-provided function for that already. I
> wouldn't know how to go about parsing straight Windows locales.

It looks like you can call GetUserDefaultUILanguage() -- see
http://msdn.microsoft.com/en-us/library/dd318137%28VS.85%29.aspx

That returns a LANGID which is a numeric code.  There seems to be a
(very recently published) conversion table from the language part of
this at
http://download.microsoft.com/download/9/5/E/95EF66AF-9026-4BB0-A41D-A4F81802D92C/%5BMS-LCID%5D.pdf

That (if you are willing to include a table like that in your code,
because I can't find an existing MS library function to do the
conversion!) gets you an RFC4646 language code, which I think is what
you are after.   http://www.ietf.org/rfc/rfc4646.txt

And yes, what you are doing with the language codes from the LANG
variable seems reasonable to me.  Two things to think about:

(1) Is it worth removing a period and everything after it (a character
encoding), rather than the "first 5 characters" restriction?  If a LANG
value such as

  AR.utf-8

is valid, then the "5 character" rule gets you AR.ut when you should
really be comparing just AR.  I think such a construction is
theoretically valid, but there are no such locales in
/usr/share/i18n/SUPPORTED on my machine here.

(2) Rather than only looking at LANG, you might want to check
LC_MESSAGES, then LC_ALL if LC_MESSAGES is empty/unset, then LANG if
LC_MESSAGES is empty/unset, to be consistent with the way setlocale()
does things in the Unix world.  man 3 setlocale.

Both of these deal with corner cases which are fairly unlikely in
practice, but I think you/we should at least be aware of them and
(perhaps) actively decide not to deal with them, rather than be unaware
of them, and so *accidentally* ignore them :)

Lastly, while on this topic: Does SWORD respect the LOCPATH variable
when finding locale information?  Should it?

Jonathan



More information about the sword-devel mailing list