Skip to content

Instantly share code, notes, and snippets.

@elkraneo
Created January 3, 2024 11:13
Show Gist options
  • Select an option

  • Save elkraneo/f1969ba42808b59bc39a7e7a290ae426 to your computer and use it in GitHub Desktop.

Select an option

Save elkraneo/f1969ba42808b59bc39a7e7a290ae426 to your computer and use it in GitHub Desktop.
import SwiftUI
let someText = "Qu’est-ce que c’est?"
struct ContentView: View {
let nsAttributedStringFR = NSAttributedString(
string: someText,
attributes: [
.languageIdentifier: "fr-FR"
// This appears to have no effect
// .accessibilitySpeechIPANotation: "fr-FR",
// .accessibilitySpeechLanguage: "fr-FR",
]
)
var attributedStringFR: AttributedString {
var attributedString = AttributedString(someText)
attributedString.languageIdentifier = "fr-FR"
// This appears to have no effect
// attributedString[AttributeScopes.AccessibilityAttributes.IPANotationAttribute.self] = "fr-FR"
// attributedString.accessibilitySpeechPhoneticNotation = "fr-FR"
return attributedString
}
var body: some View {
VStack {
// Speaks in the default voice language
Text(someText)
// Pronounced correctly in French
Text(AttributedString(nsAttributedStringFR))
// Pronounced correctly in French
Text(attributedStringFR)
// The first portion is read with the default, and the rest is correctly pronounced in French.
Text(AttributedString(someText) + " — " + attributedStringFR)
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment