Accessibility language - SwiftUI

In SwiftUI, the accessibilitySpeechLanguage key of AttributedString can be used to speak content in a specific language. Multiple AttributedStrings can be embedded inside a single AttributedString by using the + operator to speak content in multiple languages.

let attributedString = AttributedString(
    "Appt",
    attributes: AttributeContainer([
        .accessibilitySpeechLanguage: "nl_NL"
    ])
)

Text(attributedString)

In SwiftUI, you can also easily add localized accessibility features to any view using the accessibilityLabel and accessibilityHint modifiers. These modifiers accept a LocalizedStringKey, making it straightforward to provide localized descriptions and hints for your UI components. This simplifies the process of supporting multiple languages in your app's UI and accessibility technologies.

To effectively follow along with this sample, ensure your project is set up with a Localizable.strings file that includes all of your app's localized texts.

Button(action: {
    // Action here
}) {
    Text("search_title")
}
.accessibilityLabel(Text("search_accessibility_label"))
.accessibilityHint(Text("search_accessibility_hint"))