Implemented the Persisting the selected locale across launches on the ContentView view in the Sample app target.

This commit is contained in:
2026-07-05 21:04:29 +02:00
parent 58a6ec217f
commit cbb5703751
5 changed files with 99 additions and 13 deletions
@@ -8,7 +8,8 @@ extension ContentView {
/// The observable model that drives ``ContentView``.
///
/// The model owns the recording and transcribing services attached to the recording feature, along with the ``locale`` the feature
/// transcribes in, picked in the view's toolbar from the supported ``locales`` that ``load()`` fetches. It also holds the transcription
/// transcribes in, picked in the view's toolbar from the supported ``locales`` that ``load(identifier:)`` fetches restoring the
/// locale the view persisted across launches, when one exists. It also holds the transcription
/// currently presented in the view's modal sheet: ``received(_:)`` presents the transcription of a processed recording, and
/// ``dismissed()`` clears it when the sheet closes.
///
@@ -30,7 +31,7 @@ extension ContentView {
/// The transcription currently presented in the modal sheet, or `nil` when none is shown.
var transcription: Transcription?
/// The locales the transcriber supports, sorted by their localized names, or empty while ``load()`` has not finished yet.
/// The locales the transcriber supports, sorted by their localized names, or empty while ``load(identifier:)`` has not finished yet.
private(set) var locales: [Locale]
/// The service that captures the audio from a microphone.
@@ -88,10 +89,20 @@ extension ContentView {
// MARK: Methods
/// Loads the locales the transcriber supports resolved through the preinstalling service into ``locales``, sorted by their
/// localized names, and aligns ``locale`` with the 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. It then kicks off the
/// preinstallation of the aligned locale's speech model assets.
func load() async {
/// localized names, and aligns ``locale`` with the supported equivalent of its current value restored first from the given
/// persisted identifier when one exists, and falling back to the supported equivalent of a default locale when no equivalent
/// exists so the locale picker starts with a valid selection. It then kicks off the preinstallation of the aligned locale's
/// speech model assets.
///
/// - Parameter identifier: The identifier of the locale persisted across launches, or an empty string when none has been
/// persisted yet.
func load(
identifier: String
) async {
if !identifier.isEmpty {
locale = .init(identifier: identifier)
}
locales =
await preinstaller
.supportedLocales()