piebie
piebie

Reputation: 2672

Is there a language-agnostic way to add a pause in VoiceOver readout?

I have a SwiftUI view that needs a custom accessibility label applied to it. That label reads a couple of strings at once, and I would like to have VoiceOver pause between them.

I'm currently placing a comma between the strings in the accessibilityLabel(_:) modifier to get VoiceOver to pause between them. However, a colleague mentioned that this may not behave the same in other languages.

Is there a way to explicitly tell VoiceOver to pause in an accessibility label that doesn't have localization risks?

struct ExampleView: View {

  private let string1 = "Example string #1"
  private let string2 = "Example string #2"

  var body: some View {
    Color.red
      .accessibilityLabel("\(string1), \(string2)")
  }
}

Upvotes: 0

Views: 468

Answers (1)

QuentinC
QuentinC

Reputation: 14872

You shouldn't try to insert commas or whatevers manually between several strings. Instead, the string used as label should be in your translation system, so that the correct punctuation or separator is properly used in all languages in which your app is translated.

I don't know swift, but basically, don't do that:

label = one + ", " + two + ", " + three;

Which will be incorrect in languags not using commas, but prefer something like:

label = format(translate("some.label"), one, two, three)

Where "some.label" is a key inside a translation file, mapping to something like "{}, {}, {}" in english, but maybe "{}; {}; {}" in another language.

Upvotes: 0

Related Questions