<!--
{
  "availability" : [
    "iOS: 15.0.0 -",
    "iPadOS: 15.0.0 -",
    "macCatalyst: 15.0.0 -",
    "macOS: 12.0.0 -",
    "tvOS: 15.0.0 -",
    "visionOS: 1.0.0 -",
    "watchOS: 8.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "Foundation",
  "identifier" : "/documentation/Foundation/AttributedString/init(localized:options:table:bundle:locale:comment:)-8dlnl",
  "metadataVersion" : "0.1.0",
  "role" : "Initializer",
  "symbol" : {
    "kind" : "Initializer",
    "modules" : [
      "Foundation"
    ],
    "preciseIdentifier" : "s:10Foundation16AttributedStringV9localized7options5table6bundle6locale7commentACSSAAE17LocalizationValueV_AC17FormattingOptionsVSSSgSo8NSBundleCSgAA6LocaleVSgs06StaticC0VSgtcfc"
  },
  "title" : "init(localized:options:table:bundle:locale:comment:)"
}
-->

# init(localized:options:table:bundle:locale:comment:)

Creates an attributed string by looking up a localized string from the app’s bundle.

```
init(localized key: String.LocalizationValue, options: AttributedString.FormattingOptions = [], table: String? = nil, bundle: Bundle? = nil, locale: Locale? = nil, comment: StaticString? = nil)
```

## 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.

## 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`](/documentation/Foundation/AttributeScopes/FoundationAttributes/inlinePresentationIntent) attribute to apply the [`emphasized`](/documentation/Foundation/InlinePresentationIntent/emphasized) presentation intent over the entire string. It also applies the [`link`](/documentation/Foundation/AttributeScopes/FoundationAttributes/link) 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
"Add ^[%lld %@ %@](inflect: true) to your order" = "Añadir ^[%1$lld %3$@ %2$@](inflect: true) a tu pedido";
```

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.

---

Copyright &copy; 2026 Apple Inc. All rights reserved. | [Terms of Use](https://www.apple.com/legal/internet-services/terms/site.html) | [Privacy Policy](https://www.apple.com/privacy/privacy-policy)