Added the "navigationTitle" property to the ContentViewModel view model in the Sample app target to update the navigation title to show the selected locale.
This commit is contained in:
@@ -62,13 +62,13 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"view.recording.navigation.title" : {
|
"view.recording.navigation.title" : {
|
||||||
"comment" : "The title of the navigation bar in the recording view.",
|
"comment" : "The title of the navigation bar in the recording view. %@ is the name of the selected locale — its language name followed by the region flag, e.g. \"English 🇺🇸\".",
|
||||||
"extractionState" : "manual",
|
"extractionState" : "manual",
|
||||||
"localizations" : {
|
"localizations" : {
|
||||||
"en" : {
|
"en" : {
|
||||||
"stringUnit" : {
|
"stringUnit" : {
|
||||||
"state" : "translated",
|
"state" : "translated",
|
||||||
"value" : "Recording"
|
"value" : "Transcribe to %@"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -97,6 +97,14 @@ extension ContentView {
|
|||||||
self.reporter = reporter
|
self.reporter = reporter
|
||||||
self.transcriber = transcriber
|
self.transcriber = transcriber
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// MARK: Computed
|
||||||
|
|
||||||
|
/// The navigation title of ``ContentView``: the localized "Transcribe to …" filled with the name of the selected ``locale``, so
|
||||||
|
/// the title updates on every locale change.
|
||||||
|
var navigationTitle: LocalizedStringResource {
|
||||||
|
.viewRecordingNavigationTitle(name(for: locale))
|
||||||
|
}
|
||||||
|
|
||||||
// MARK: Methods
|
// MARK: Methods
|
||||||
|
|
||||||
|
|||||||
@@ -62,7 +62,7 @@ struct ContentView: View {
|
|||||||
maxWidth: .infinity,
|
maxWidth: .infinity,
|
||||||
maxHeight: .infinity
|
maxHeight: .infinity
|
||||||
)
|
)
|
||||||
.navigationTitle(.viewRecordingNavigationTitle)
|
.navigationTitle(model.navigationTitle)
|
||||||
#if !os(macOS)
|
#if !os(macOS)
|
||||||
.navigationBarTitleDisplayMode(.inline)
|
.navigationBarTitleDisplayMode(.inline)
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -256,6 +256,38 @@ struct ContentViewModelTests {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// MARK: Navigation Title
|
||||||
|
|
||||||
|
@MainActor
|
||||||
|
@Suite("Navigation title")
|
||||||
|
struct NavigationTitle {
|
||||||
|
|
||||||
|
@Test
|
||||||
|
func `navigation title names the selected locale`() {
|
||||||
|
let model = Model(preinstaller: PreinstallingMock())
|
||||||
|
|
||||||
|
model.locale = .english
|
||||||
|
|
||||||
|
#expect(String(localized: model.navigationTitle) == "Transcribe to \(model.name(for: .english))")
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
func `navigation title updates when the locale changes`() {
|
||||||
|
let model = Model(preinstaller: PreinstallingMock())
|
||||||
|
|
||||||
|
model.locale = .english
|
||||||
|
let english = String(localized: model.navigationTitle)
|
||||||
|
|
||||||
|
model.locale = .dutch
|
||||||
|
let dutch = String(localized: model.navigationTitle)
|
||||||
|
|
||||||
|
#expect(english == "Transcribe to \(model.name(for: .english))")
|
||||||
|
#expect(dutch == "Transcribe to \(model.name(for: .dutch))")
|
||||||
|
#expect(english != dutch)
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// MARK: - Constants
|
// MARK: - Constants
|
||||||
|
|||||||
Reference in New Issue
Block a user