Monday, April 29, 2013

NSBundle preferredLocalizationsFromArray example ios


preferredLocalizationsFromArray:

Returns one or more localizations from the specified list that a bundle object would use to locate resources for the current user.
+ (NSArray *)preferredLocalizationsFromArray:(NSArray *)localizationsArray
Parameters
localizationsArray
An array of NSString objects, each of which specifies the name of a localization that the bundle supports.
Return Value of [NSBundle preferredLocalizationsFromArray]
An array of NSString objects containing the preferred localizations. These strings are ordered in the array according to the current user's language preferences and are taken from the strings in the localizationsArray parameter.
Discussion of [NSBundle preferredLocalizationsFromArray]
This method does not return all localizations in preference order but only those from whichNSBundle would get localized content, typically either a single non-region-specific localization or a region-specific localization followed by a corresponding non-region-specific localization as a fallback.[NSBundle preferredLocalizationsFromArray]
However, clients who want all localizations in preference order can make repeated calls, each time taking the top localizations out of the list of localizations passed in.
Example of [NSBundle preferredLocalizationsFromArray]
NSArray* availableLocalizations = [[NSBundle mainBundle] localizations];    
NSArray* userPrefered = [NSBundle preferredLocalizationsFromArray:availableLocalizations forPreferences:[NSLocale preferredLanguages]];
NSString *filePath = [[NSBundle mainBundle] pathForResource:@"index" ofType:@"html" inDirectory:@"view" forLocalization:[userPrefered objectAtIndex:0]];