Created
January 3, 2024 11:13
-
-
Save elkraneo/f1969ba42808b59bc39a7e7a290ae426 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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