Localization

open class Localization: NSObject

Localization is a wrapper class for getting a localized string that allows overriding the bundles to search for a given string. To use this class, call one of the localization methods. To override the value returned by one of the bundles, add the string to a bundle higher up in the list order of the allBundles property.

  • List of all the bundles to search for a given localized string.

    Declaration

    Swift

    public static var allBundles: [LocalizationBundle] =
  • Return the localized string for the given key.

    Seealso

    NSLocalizedString

    Declaration

    Swift

    public static func localizedString(_ key: String) -> String

    Parameters

    key

    The key into the Strings file.

    Return Value

    The localized string or the key if not found.

  • Return a localized formatted string for the given key and arguments.

    Declaration

    Swift

    public static func localizedStringWithFormatKey(_ key: String, _ arguments: CVarArg...) -> String

    Parameters

    key

    The key into the Strings file.

    arguments

    The argument list for the localized formatted string.

    Return Value

    The localized string or the key if not found.

  • Join the list of text strings using a localized or.

  • example:

    let groceryList1 = ["apples", "oranges"]
    print (Localization.localizedJoin(groceryList1))  // "apples or oranges"
    
    let groceryList2 = ["apples", "oranges", "bananas", "grapes"]
    print (Localization.localizedJoin(groceryList2))  // "apples, oranges, bananas, or grapes"
    
  • Note

    This function is currently written to support US English. Any other language is untested.

    Declaration

    Swift

    public static func localizedOrJoin(_ textList: [String]) -> String

    Parameters

    textList

    The list of text values to join.

    Return Value

    A localized String with the joined values.

  • Join the list of text strings using a localized and.

  • example:

    let groceryList1 = ["apples", "oranges"]
    print (Localization.localizedJoin(groceryList1))  // "apples and oranges"
    
    let groceryList2 = ["apples", "oranges", "bananas", "grapes"]
    print (Localization.localizedJoin(groceryList2))  // "apples, oranges, bananas, and grapes"
    
  • Note

    This function is currently written to support US English. Any other language is untested.

    Declaration

    Swift

    public static func localizedAndJoin(_ textList: [String]) -> String

    Parameters

    textList

    The list of text values to join.

    Return Value

    A localized String with the joined values.

  • The localized name of this App. This method looks at the plist for the main bundle and returns the most appropriate display name.

    Declaration

    Swift

    public static let localizedAppName : String =
  • Localized button title for a Yes button.

    Declaration

    Swift

    @objc open class func buttonYes() -> String
  • Localized button title for a No button.

    Declaration

    Swift

    @objc open class func buttonNo() -> String
  • Localized button title for an OK button.

    Declaration

    Swift

    @objc open class func buttonOK() -> String
  • Localized button title for a Cancel button.

    Declaration

    Swift

    @objc open class func buttonCancel() -> String
  • Localized button title for a Done button.

    Declaration

    Swift

    @objc open class func buttonDone() -> String
  • Localized button title for a Close button.

    Declaration

    Swift

    @objc open class func buttonClose() -> String
  • Localized button title for a Next button.

    Declaration

    Swift

    @objc open class func buttonNext() -> String
  • Localized button title for a Back button.

    Declaration

    Swift

    @objc open class func buttonBack() -> String
  • Localized button title for an skip button. Default is Prefer not to answer.

    Declaration

    Swift

    @objc open class func buttonSkip() -> String
  • Localized button title for a button to skip a task. Default is I can’t do this now.

    Declaration

    Swift

    @objc open class func buttonSkipTask() -> String
  • Localized button title for a Get Started button.

    Declaration

    Swift

    @objc open class func buttonGetStarted() -> String
  • Localized button title for a Learn more button.

    Declaration

    Swift

    @objc open class func buttonLearnMore() -> String
  • Localized button title for a Pause button.

    Declaration

    Swift

    @objc open class func buttonPause() -> String
  • Localized button title for a Resume button.

    Declaration

    Swift

    @objc open class func buttonResume() -> String