Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion Sources/SkipUI/SkipUI/Environment/EnvironmentValues.swift
Original file line number Diff line number Diff line change
Expand Up @@ -479,8 +479,12 @@ extension EnvironmentValues {
}

public var locale: Locale {
get { Locale(LocalConfiguration.current.locales[0]) }
get { builtinValue(key: "_locale", defaultValue: { nil }) as! Locale? ?? Locale(LocalConfiguration.current.locales[0]) }
set {
// Presentations compose in their own Android window, where Compose re-provides
// `LocalConfiguration` from the platform. Track the override in our own composition
// local as well so that it survives into sheets, covers, alerts, and popups.
setBuiltinValue(key: "_locale", value: newValue, defaultValue: { nil })
let action: @Composable () -> Void = {
// Requires a @Composable context to copy LocalConfiguration.current
let configuration = Configuration(LocalConfiguration.current)
Expand Down
27 changes: 27 additions & 0 deletions Tests/SkipUITests/SkipUITests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -633,6 +633,33 @@ final class SkipUITests: SkipUITestCase {
}
}

func testSheetInheritsLocaleFromPresenter() throws {
#if !SKIP
throw XCTSkip("sheet content composes in a separate Android window")
#else
try testUI(view: {
SheetLocaleTestView()
.environment(\.locale, Locale(identifier: "fr"))
.accessibilityIdentifier("test-view")
}, eval: { rule in
rule.waitForIdle()
rule.onAllNodesWithTag("sheet-text").onFirst().assert(hasTextExactly("Terminé"))
})
#endif
}

struct SheetLocaleTestView: View {
@State var isPresented = true

var body: some View {
Text(verbatim: "Sheet Host")
.sheet(isPresented: $isPresented) {
Text("Done", bundle: .module)
.accessibilityIdentifier("sheet-text")
}
}
}

// look up a localized string in the current bundle using the given language
func localizedBundle(_ lang: String) throws -> Bundle {
try XCTUnwrap(Bundle(url: XCTUnwrap(Bundle.module.url(forResource: "Localizable", withExtension: "strings", subdirectory: nil, localization: lang)).deletingLastPathComponent()))
Expand Down
Loading