Class: NSLocale

Inherits:
NSObject show all

Overview

Locales encapsulate information about linguistic, cultural, and technological conventions and standards. Examples of information encapsulated by a locale include the symbol used for the decimal separator in numbers and the way dates are formatted.

Class Method Summary (collapse)

Instance Method Summary (collapse)

Methods inherited from NSObject

#!, #!=, #!~, #, #==, #===, #=~, #Rational, #__callee__, #__method__, #__send__, #__type__, `, alloc, allocWithZone:, #autoContentAccessingProxy, autoload, autoload?, autorelease_pool, #awakeAfterUsingCoder:, binding, block_given?, caller, cancelPreviousPerformRequestsWithTarget:, cancelPreviousPerformRequestsWithTarget:selector:object:, catch, class, classFallbacksForKeyedArchiver, #classForCoder, #classForKeyedArchiver, classForKeyedUnarchiver, #clone, conformsToProtocol:, #copy, copyWithZone:, #dealloc, #define_singleton_method, description, display, #doesNotRecognizeSelector:, #dup, #enum_for, #eql?, #equal?, #extend, fail, #finalize, format, #forwardInvocation:, #forwardingTargetForSelector:, framework, #freeze, #frozen?, getpass, gets, global_variables, #init, initialize, #initialize_clone, #initialize_copy, #initialize_dup, #inspect, instanceMethodForSelector:, instanceMethodSignatureForSelector:, #instance_eval, #instance_exec, #instance_of?, #instance_variable_defined?, #instance_variable_get, #instance_variable_set, #instance_variables, instancesRespondToSelector:, isSubclassOfClass:, #is_a?, iterator?, #kind_of?, lambda, load, load_bridge_support_file, load_plist, local_variables, loop, #method, #methodForSelector:, #methodSignatureForSelector:, #methods, #mutableCopy, mutableCopyWithZone:, new, #nil?, open, p, #performSelector:onThread:withObject:waitUntilDone:, #performSelector:onThread:withObject:waitUntilDone:modes:, #performSelector:withObject:afterDelay:, #performSelector:withObject:afterDelay:inModes:, #performSelectorInBackground:withObject:, #performSelectorOnMainThread:withObject:waitUntilDone:, #performSelectorOnMainThread:withObject:waitUntilDone:modes:, print, printf, #private_methods, proc, #protected_methods, #public_method, #public_methods, #public_send, putc, puts, raise, rand, readline, readlines, #replacementObjectForCoder:, #replacementObjectForKeyedArchiver:, require, resolveClassMethod:, resolveInstanceMethod:, #respond_to?, #respond_to_missing?, select, #send, setVersion:, #singleton_methods, sprintf, srand, superclass, #taint, #tainted?, #tap, test, throw, #to_plist, #to_s, trace_var, trap, #trust, #untaint, untrace_var, #untrust, #untrusted?, version

Constructor Details

This class inherits a constructor from NSObject

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class NSObject

Class Method Details

+ (Object) autoupdatingCurrentLocale

Returns the current logical locale for the current user. Settings you get from this locale do change as the user’s settings change (contrast with currentLocale).Note that if you cache values based on the locale or related information, those caches will of course not be automatically updated by the updating of the locale object. You can recompute caches upon receipt of the notification (NSCurrentLocaleDidChangeNotification) that gets sent out for locale changes (see Notification Programming Topics to learn how to register for and receive notifications).

Returns:

  • (Object)

    The current logical locale for the current user. The locale is formed from the settings for the current user’s chosen system locale overlaid with any custom settings the user has specified in System Preferences.The object always reflects the current state of the current user’s locale settings.

+ (Array) availableLocaleIdentifiers

Returns an array of NSString objects, each of which identifies a locale available on the system.

Returns:

  • (Array)

    An array of NSString objects, each of which identifies a locale available on the system.

+ (String) canonicalLanguageIdentifierFromString(string)

Returns a canonical language identifier by mapping an arbitrary locale identification string to the canonical identifier.

Parameters:

  • string (String)

    A string representation of an arbitrary locale identifier.

Returns:

  • (String)

    A string that represents the canonical language identifier for the specified arbitrary locale identifier.

+ (String) canonicalLocaleIdentifierFromString(string)

Returns the canonical identifier for a given locale identification string.

Parameters:

  • string (String)

    A locale identification string.

Returns:

  • (String)

    The canonical identifier for an the locale identified by string.

+ (NSLocaleLanguageDirection) characterDirectionForLanguage(isoLangCode)

Returns the character direction for the specified ISO language code.

Parameters:

  • isoLangCode (String)

    The ISO language code.

Returns:

  • (NSLocaleLanguageDirection)

    Returns the character direction for the language. See “NSLocaleLanguageDirection” for possible values. If the appropriate direction can’t be determined NSLocaleLanguageDirectionUnknown is returned.

+ (Array) commonISOCurrencyCodes

Returns an array of common ISO currency codes Common codes may include, for example, AED, AUD, BZD, DKK, EUR, GBP, JPY, KES, MXN, OMR, STD, USD, XCD, and ZWD.

Returns:

  • (Array)

    An array of NSString objects that represents common ISO currency codes.

+ (Hash) componentsFromLocaleIdentifier(string)

Returns a dictionary that is the result of parsing a locale ID. For example: the locale ID "en_US@calendar=japanese" yields a dictionary with three entries: NSLocaleLanguageCode=en, NSLocaleCountryCode=US, and NSLocaleCalendar=NSJapaneseCalendar.

Parameters:

  • string (String)

    A locale ID, consisting of language, script, country, variant, and keyword/value pairs, for example, “en_US@calendar=japanese”.

Returns:

  • (Hash)

    A dictionary that is the result of parsing string as a locale ID. The keys are the constant NSString constants corresponding to the locale ID components, and the values correspond to constants where available. For the complete set of dictionary keys, see “Constants.”

+ (Object) currentLocale

Returns the logical locale for the current user. Settings you get from this locale do not change as a user’s Preferences are changed so that your operations are consistent. Typically you perform some operations on the returned object and then allow it to be disposed of. Moreover, since the returned object may be cached, you do not need to hold on to it indefinitely. Contrast with autoupdatingCurrentLocale.

Returns:

  • (Object)

    The logical locale for the current user. The locale is formed from the settings for the current user’s chosen system locale overlaid with any custom settings the user has specified in System Preferences.

+ (Array) ISOCountryCodes

Returns an array of NSString objects that represents all known legal country codes. Note that many of country codes do not have any supporting locale data in OS X.

Returns:

  • (Array)

    An array of NSString objects that represents all known legal country codes.

+ (Array) ISOCurrencyCodes

Returns an array of NSString objects that represents all known legal ISO currency codes. Note that some of the currency codes may not have any supporting locale data in OS X.

Returns:

  • (Array)

    An array of NSString objects that represents all known legal ISO currency codes.

+ (Array) ISOLanguageCodes

Returns an array of NSString objects that represents all known legal ISO language codes. Note that many of the language codes do not have any supporting locale data in OS X.

Returns:

  • (Array)

    An array of NSString objects that represents all known legal ISO language codes.

+ (NSLocaleLanguageDirection) lineDirectionForLanguage(isoLangCode)

Returns the line direction for the specified ISO language code.

Parameters:

  • isoLangCode (String)

    The ISO language code.

Returns:

  • (NSLocaleLanguageDirection)

    Returns the line direction for the language. See “NSLocaleLanguageDirection” for possible values. If the appropriate direction can’t be determined NSLocaleLanguageDirectionUnknown is returned.

+ (String) localeIdentifierFromComponents(dict)

Returns a locale identifier from the components specified in a given dictionary. This reverses the actions of componentsFromLocaleIdentifier:, so for example the dictionary NSLocaleCountryCode="US", NSLocaleCalendar=NSJapaneseCalendar becomes "en_US@calendar=japanese".

Parameters:

  • dict (Hash)

    A dictionary containing components that specify a locale. For valid dictionary keys, see “Constants.”

Returns:

  • (String)

    A locale identifier created from the components specified in dict.

+ (String) localeIdentifierFromWindowsLocaleCode(lcid)

Returns a locale identifier from a Windows locale code.

Parameters:

  • lcid (Integer)

    The Windows locale code.

Returns:

  • (String)

    The locale identifier.

+ (Array) preferredLanguages

Returns the user's language preference order as an array of strings.

Returns:

  • (Array)

    The user's language preference order as an array of NSString objects, each of which is a canonicalized IETF BCP 47 language identifier.

+ (Object) systemLocale

Returns the “root”, canonical locale, that contains fixed “backstop” settings that provide values for otherwise undefined keys.

Returns:

  • (Object)

    The “root”, canonical locale, that contains fixed “backstop” settings that provide values for otherwise undefined keys.

+ (Integer) windowsLocaleCodeFromLocaleIdentifier(localeIdentifier)

Returns a Window locale code from the locale identifier.

Parameters:

  • localeIdentifier (String)

    The locale identifier.

Returns:

  • (Integer)

    The Windows locale code.

Instance Method Details

- (String) displayNameForKey(key, value:value)

Returns the display name for the given value. Not all locale property keys have values with display name values.You can use the NSLocaleIdentifier key to get the name of a locale in the language of another locale, as illustrated in the following examples. The first uses the fr_FR locale.returnsThe following example uses the en_GB locale.returns

Parameters:

  • key (Object)

    Specifies which of the locale property keys value is (see “Constants”),

  • value (Object)

    A value for key.

Returns:

  • (String)

    The display name for value.

- (Object) initWithLocaleIdentifier(string)

Initializes the receiver using a given locale identifier.

Parameters:

  • string (String)

    The identifier for the new locale.

Returns:

  • (Object)

    The initialized locale.

- (String) localeIdentifier

Returns the identifier for the receiver. Equivalent to sending objectForKey: with key NSLocaleIdentifier.

Returns:

  • (String)

    The identifier for the receiver. This may not be the same string that the locale was created with, since NSLocale may canonicalize it.

- (Object) objectForKey(key)

Returns the object corresponding to the specified key.

Parameters:

  • key (Object)

    The key for which to return the corresponding value. For valid values of key, see “Constants.”

Returns:

  • (Object)

    The object corresponding to key.