[sword-devel] swlocale question

Manfred Bergmann bergmannmd at web.de
Fri Sep 4 00:53:52 MST 2009

On 04.09.2009, at 04:42, Matthew Talbert wrote:

>> There is some interesting code in setDefaultLocaleName.  If you do a
>> blame on this, you might find who can help you with the logic.  Don't
>> have time right now to check but the comments are beyond my logic of
>> system locales, so it's not likely me (unless I reformatted it).
>> Anyway, as Jonathan Marsden mentioned earlier, if you are parsing  
>> system
>> locale strings and trying to set and appropriate SWORD locale from  
>> such,
>> we could sure use that logic in the engine for everyone to take
>> advantage of.
> OK, here's the code we came up with (Karl wrote it). This is based off
> the environment variable LANG which is typically in the form of, say,
> ar_EG for Arabic/Egyptian or fa_IR for Persian/Iran. So basically what
> we do is get the list of available locales, then look for an exact
> match. If we find one, we're done. If not, then we look for a match of
> the first 5 characters. This should be the right thing nearly all of
> the time, for those locales which actually have 5 characters. If it
> doesn't find a match with 5 characters, it looks for a match of 2
> characters. While this might be incorrect some of the time, it will
> probably be correct most of the time. If we don't find anything after
> all of this, we just give up.
> 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. If
> everyone thinks this is the right approach, then I can try to get it
> into a suitable form for inclusion.

Unfortunately on OS X the LANG var doesn't seem to get set also not  
any other environment variable that would help determine the system  
In OS X system preferences you have a preferred list of languages. The  
first one is used as current system language but this is not reflected  
to terminal environment.
Since SWORD library is not available as installable package on OS X  
like on Linux we package a compiled binary of it including the  
locales.d folder and look manually if there is a locale file for the  
current system language.
Hmm, looks like MacSword has to further do it's own thing here.


More information about the sword-devel mailing list