Created
July 9, 2010 17:40
-
-
Save j4johnfox/469758 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- (CPString)bundleLocaleWithUserLanguage:(CPString)aUserLanguage | |
{ | |
var defaultLocale = [self objectForInfoDictionaryKey:@"CPBundleDevelopmentRegion"]; | |
var availableLocales = [self objectForInfoDictionaryKey:@"CPBundleLocalizedResourceKeys"]; | |
var bestMatch, myLocale= nil; | |
UserLanguage = aUserLanguage; | |
// First try matching against the UserLanguage | |
if (UserLanguage && [UserLanguage length]) | |
{ | |
for (var i = 0; i < [availableLocales count]; i++) | |
{ | |
myLocale = availableLocales[i]; | |
if (UserLanguage && (myLocale == UserLanguage)) | |
{ | |
bestMatch = myLocale; | |
break; | |
} | |
} | |
} | |
// No match? Try the browser language | |
if (!bestMatch) | |
{ | |
for (var i = 0; i < [availableLocales count]; i++) | |
{ | |
myLocale = availableLocales[i]; | |
if (myLocale == [self browserLanguage]) | |
{ | |
bestMatch = myLocale; | |
break; | |
} | |
} | |
} | |
// Still nothing? Look for a default, or hope your users understand English. | |
if (!bestMatch) | |
{ | |
bestMatch = ([defaultLocale length]) ? defaultLocale : "en"; | |
} | |
return bestMatch; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment