init(localized:defaultValue:options:table:bundle:locale:comment:including:)
Creates an attributed string by looking up a localized string from the app’s bundle, including an attribute scope that a key path identifies, using a default value if necessary.
Declaration
init<S>(localized key: StaticString, defaultValue: String.LocalizationValue, options: AttributedString.FormattingOptions = [], table: String? = nil, bundle: Bundle? = nil, locale: Locale? = nil, comment: StaticString? = nil, including scope: KeyPath<AttributeScopes, S.Type>) where S : AttributeScopeParameters
- key:
The key for a string in the table that
tableidentifies. - defaultValue:
The localized string for the development locale. For other locales, the string uses this value if a localized string for
keyisn’t found in the table. - options:
Options that affect the handling of attributes.
- table:
The bundle’s string table to search. If
tableisnilor is an empty string, the method attempts to use the table inLocalizable.strings. The default isnil. - bundle:
The bundle to use for looking up strings. If
nil, an app searches its main bundle. The default isnil. - locale:
The locale of the localized string to retrieve. If
nil, this initializer uses the current locale. The default isnil. - comment:
The comment to place above the key-value pair in the strings file. This parameter provides the translator with some context about the localized string’s presentation to the user.
- scope:
An Attributescopes key path that identifies an attribute scope to associate with the attributed string.
Discussion
Use this initializer instead of init(localized:options:table:bundle:locale:comment:including:) if you prefer to use a symbolic string key, rather than use the development language’s string as the key.