[sword-devel] Locale Name Lookup
Troy A. Griffitts
scribe at crosswire.org
Sat Jan 2 01:43:01 MST 2010
When bundling up 1.6.1, I wanted to include something from the fruits of
the discussions regarding locale name lookup.
Chris had checked in scripts to the sword-tools repo to pull the locale
spec data and munge it down to nice lists.
Without adding any new official API calls because of a 1.6.x release, I
decided to merely bundle this data as a locale file under the name
'locales'. The data included is very raw and the format is not what
will officially be supported going forward, but at least it's bundled
for use as-is, if you'd like to take advantage of it for now.
Since this is not a locale per se, we do not return this from a request
to: LocaleMgr::getAvailableLocales(), which should mean that everything
works the same as before, just like locales.conf doesn't exist, unless
you ask for it by name.
Data format is simple and there are entries for both the localized and
English names, e.g.:
There is no guarantee the current dataset includes either entry, so you
should check that the locale code actually got translated to the name.
This example code should result in something useful:
SWBuf localeCode = "de"; // German for example
LocaleMgr *lm = LocaleMgr::getSystemLocaleMgr();
// let's try to grab both the localized and English names
SWBuf localeName = lm->translate(localeCode, "locales");
SWBuf localeEnglishName = lm->translate(localeCode+".en", "locales");
// let's be sure both entries were obtained, otherwise fallback.
if (localeEnglishName == (localeCode+".en")) localeEnglishName = localeName;
else if (localeName == localeCode) localeName = localeEnglishName;
We'll do something official for a 1.7.0 release, but the data is bundled
and accessible in 1.6.1 if you'd like to use it.
More information about the sword-devel