---
title: "init(localized:options:table:bundle:locale:comment:including:)"
framework: Foundation
role: symbol
role_heading: Initializer
platforms: [iOS 15.0+, iPadOS 15.0+, Mac Catalyst 15.0+, macOS 12.0+, tvOS 15.0+, visionOS 1.0+, watchOS 8.0+]
path: foundation/attributedstring/3867591-init
---

# init(localized: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.

## Declaration

```swift
init<S>(localized key: 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 : AttributeScope
```

## Parameters

- `key`: The key for a string in the table that `table` identifies.
- `options`: Options that affect the handling of attributes.
- `table`: The bundle’s string table to search. If `table` is `nil` or is an empty string, the method attempts to use the table in `Localizable.strings`. The default is `nil`.
- `bundle`: The bundle to use for looking up strings. If `nil`, an app searches its main bundle. The default is `nil`.
- `locale`: The locale of the localized string to retrieve. If `nil`, this initializer uses the current locale. The default is `nil`.
- `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 [doc://com.apple.foundation/documentation/Foundation/AttributeScopes](foundation/attributescopes.md) key path that identifies an attribute scope to associate with the attributed string.

## Discussion

To create localizable attributed strings, use Markdown syntax in your strings files. The following example shows a string from a Spanish localization:

```other
"_Please visit our [website](https://www.example.com)._" = "_Visita nuestro [sitio web](https://www.example.com)._";
```

You load this string with one of the initializers that takes `localized` as its first parameter, like the following:

```swift
let visitString = AttributedString(localized: "_Please visit our [website](https://www.example.com)._")
```

The resulting attributed string contains an [inlinePresentationIntent](../attributescopes/foundationattributes/inlinepresentationintent.md) attribute to apply the [emphasized](../inlinepresentationintent/emphasized.md) presentation intent over the entire string. It also applies the [link](../attributescopes/foundationattributes/link.md) attribute to the text `sitio web`. User interface frameworks like SwiftUI and UIKit can then use these attributes when presenting the text to the user.

### Applying Automatic Grammar Agreement

To apply the automatic grammar agreement feature when loading a localized string, use Apple’s Markdown extension syntax: `^[text to inflect](inflect: true)`. The following example shows a format string with a Spanish localization for a food-ordering app.

```other
"_Please visit our [website](https://www.example.com)._" = "_Visita nuestro [sitio web](https://www.example.com)._";
```

You load and localize this string as follows:

```swift
let orderString = AttributedString(
     localized: "Add ^[\(quantity) \(foodSizeSelection.localizedName) \(food.localizedName)](inflect: true) to your order")
// "Añadir 2 ensaladas grandes a tu pedido."
```

When the string loads, the automatic grammar agreement feature adjusts the text for `foodSizeSelection` and `food` to match the number and gender of the sentence.

## See Also

### Creating a Localized Attributed String

- [init(localized:options:table:bundle:locale:comment:)](init(localized:options:table:bundle:locale:comment:)-8dlnl.md)
- [init(localized:options:table:bundle:locale:comment:including:)](init(localized:options:table:bundle:locale:comment:including:)-8uknv.md)
- [String.LocalizationValue](../../swift/string/localizationvalue.md)
- [AttributedString.FormattingOptions](formattingoptions.md)
- [init(localized:)](init(localized:).md)
- [init(localized:including:)](init(localized:including:)-2xebo.md)
- [init(localized:including:)](init(localized:including:)-15xc5.md)
- [LocalizedStringResource](../localizedstringresource.md)
