* Source/NSUserDefaults.m:

- Refactoring of the code to read the system language list
  into a separate function, systemLanguages().
- Add support for the LANGUAGE environment variable, a GNU extension.
  It holds a colon-separated list of locales, and is intended to let
  the user specify a list of their preferred languages in order.
  For example, the language settings GUI in Ubuntu modifies the
  LANGUAGE variable.

  More info here:
  http://www.gnu.org/software/gettext/manual/gettext.html#The-LANGUAGE-variable
- When populating NSLanguages, "expand" locales into a list of
  related variants, formed by stripping off region suffixes. This
  ensures that if a user's environment is set to a regional version
  of a language (say CanadaFrench) but an application is only
  traslated into French, the plain French translation will still be used.

  e.g. if the system locales are {fr_CA, en_CA}, expand the list to
  {fr_CA, fr, en_CA, en}.
* Headers/GNUstepBase/GSLocale.h:
* Source/GSLocale.m:
New functions GSLocaleVariants and GSLanguagesFromLocale


git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@33910 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
ericwa 2011-09-29 19:00:46 +00:00
parent eebba60c4b
commit 6352d91406
4 changed files with 135 additions and 28 deletions

View file

@ -178,44 +178,69 @@ writeDictionary(NSDictionary *dict, NSString *file)
return NO;
}
/**
* Returns the list of languages retrieved from the operating system, in
* decreasing order of preference. Returns an empty array if the information
* could not be retrieved.
*/
static NSArray *
systemLanguages()
{
NSMutableArray *names = [NSMutableArray arrayWithCapacity: 10];
// Add the languages listed in the LANGUAGE environment variable
// (a non-POSIX GNU extension)
{
NSString *env = [[[NSProcessInfo processInfo] environment]
objectForKey: @"LANGUAGE"];
if (env != nil && [env length] > 0)
{
NSArray *array = [env componentsSeparatedByString: @":"];
NSEnumerator *enumerator = [array objectEnumerator];
NSString *locale;
while (nil != (locale = [enumerator nextObject]))
{
[names addObjectsFromArray: GSLanguagesFromLocale(locale)];
}
}
}
// If LANGUAGES did not yield any languages, try LC_MESSAGES
#ifdef HAVE_LOCALE_H
#ifdef LC_MESSAGES
if ([names count] == 0)
{
NSString *locale = GSSetLocale(LC_MESSAGES, nil);
if (locale != nil)
{
[names addObjectsFromArray: GSLanguagesFromLocale(locale)];
}
}
#endif
#endif
return names;
}
static NSMutableArray *
newLanguages(NSArray *oldNames)
{
NSMutableArray *newNames;
NSEnumerator *enumerator;
NSString *language;
NSString *locale = nil;
#ifdef HAVE_LOCALE_H
#ifdef LC_MESSAGES
locale = GSSetLocale(LC_MESSAGES, nil);
#endif
#endif
newNames = [NSMutableArray arrayWithCapacity: 5];
if (oldNames == nil && locale != nil)
if (oldNames == nil || [oldNames count] == 0)
{
NSString *locLang = GSLanguageFromLocale(locale);
if (nil != locLang)
{
oldNames = [NSArray arrayWithObject: locLang];
}
#ifdef __MINGW__
if (oldNames == nil)
{
/* Check for language as the first part of the locale string */
NSRange under = [locale rangeOfString: @"_"];
if (under.location)
{
oldNames = [NSArray arrayWithObject:
[locale substringToIndex: under.location]];
}
}
#endif
oldNames = systemLanguages();
}
if (oldNames == nil)
// If the user default was not set, and the system languages couldn't
// be retrieved, try the GNUstep environment variable LANGUAGES
if (oldNames == nil || [oldNames count] == 0)
{
NSString *env;