Swifternalization

This is the main class of Swifternalization library. It exposes methods that can be used to get localized strings.

The framework uses json files and work with them. There are two types of files. First is expressions.json that contains shared expressions used among other localizable json files. The other files are files with translation for specific languages. Each file is just for one language. E.g. you can have base.json, en.json, pl.json which are accordingly used for Base, English and Polish localizations.

Before calling any method that return localized string call configure:.

  • Call the method to configure Swifternalization.

    Declaration

    Swift

    public class func configure(bundle: NSBundle = NSBundle.mainBundle())

    Parameters

    bundle

    A bundle when expressions.json and other files are located.

  • Get localized value for a key.

    Declaration

    Swift

    public class func localizedString(key: String, fittingWidth: Int? = nil, defaultValue: String? = nil, comment: String? = nil) -> String

    Parameters

    key

    A key to which localized string is assigned.

    fittingWidth

    A max width that value should fit to. If there is no value specified the full-length localized string is returned. If a passed fitting width is greater than highest available then a value for highest available width is returned.

    defaultValue

    A default value that is returned when there is no localized value for passed key.

    comment

    A comment about the key and localized value. Just for developer use for describing key-value pair.

    Return Value

    localized string if found, otherwise defaultValue is returned if specified or key if defaultValue is not specified.

  • Get localized value for a key and string value.

    Declaration

    Swift

    public class func localizedString(key: String, stringValue: String, fittingWidth: Int? = nil, defaultValue: String? = nil, comment: String? = nil) -> String

    Parameters

    key

    A key to which localized string is assigned.

    stringValue

    A value that is matched by expressions.

    fittingWidth

    A max width that value should fit to. If there is no value specified the full-length localized string is returned. If a passed fitting width is greater than highest available then a value for highest available width is returned.

    defaultValue

    A default value that is returned when there is no localized value for passed key.

    comment

    A comment about the key and localized value. Just for developer use for describing key-value pair.

    Return Value

    localized string if found, otherwise defaultValue is returned if specified or key if defaultValue is not specified.

  • Get localized value for a key and string value.

    Declaration

    Swift

    public class func localizedString(key: String, intValue: Int, fittingWidth: Int? = nil, defaultValue: String? = nil, comment: String? = nil) -> String

    Parameters

    key

    A key to which localized string is assigned.

    intValue

    A value that is matched by expressions.

    fittingWidth

    A max width that value should fit to. If there is no value specified the full-length localized string is returned. If a passed fitting width is greater than highest available then a value for highest available width is returned.

    defaultValue

    A default value that is returned when there is no localized value for passed key.

    comment

    A comment about the key and localized value. Just for developer use for describing key-value pair.

    Return Value

    localized string if found, otherwise defaultValue is returned if specified or key if defaultValue is not specified.