diff --git a/Apps/Attendi/View Models/ContentViewModel.swift b/Apps/Attendi/View Models/ContentViewModel.swift index cb2ad8a..773f73f 100644 --- a/Apps/Attendi/View Models/ContentViewModel.swift +++ b/Apps/Attendi/View Models/ContentViewModel.swift @@ -48,11 +48,18 @@ extension ContentView { // MARK: Methods /// Loads the locales the transcriber supports into ``locales``, sorted by their localized names, and aligns ``locale`` with the - /// supported equivalent of its current value so the locale picker starts with a valid selection. + /// supported equivalent of its current value — falling back to the supported equivalent of a default locale when none exists — + /// so the locale picker starts with a valid selection. func load() async { locales = await SpeechTranscriber.supportedLocales.sorted { name(for: $0).localizedStandardCompare(name(for: $1)) == .orderedAscending } + + if let equivalent = await SpeechTranscriber.supportedLocale(equivalentTo: locale) { + locale = equivalent + } else if let fallback = await SpeechTranscriber.supportedLocale(equivalentTo: .byDefault) { + locale = fallback + } } /// Returns the localized name of a locale for the locale picker. @@ -62,7 +69,8 @@ extension ContentView { func name( for locale: Locale ) -> String { - Locale.current + Locale + .current .localizedString( forIdentifier: locale.identifier )?.localizedCapitalized @@ -86,3 +94,10 @@ extension ContentView { } } + +// MARK: - Constants + +private extension Locale { + /// The locale to fall back to when the transcriber supports no equivalent of the user's current locale. + static let byDefault: Locale = .init(identifier: "en_US") +}