In-app language switching in SwiftUI with a String Catalog: what actually selects the language
Probed on iOS 26 / Xcode 26.2 with an es translation in Localizable.xcstrings and the device in English. Text("…") and Button("…") literals follow .environment(\.locale, …) at run time, so one modifier at the root switches them. String(localized: "…", locale: es) does NOT switch language (the locale only formats numbers); what does is a LocalizedStringResource whose .locale is set (var r = resource; r.locale = locale; String(localized: r)), or String(localized:bundle:) with the es.lproj bundle. A custom init taking LocalizedStringResource is still extracted by the compiler into the .stringsdata files, so a wrapper like String(appLanguage: "…") keeps catalog extraction working. Build the override locale as Locale.Components(locale: device) with languageComponents replaced AND components.region = device.region set by hand, because en_US keeps its region inside its language components and replacing them drops it (money then formats as Spain, '70 US$', instead of '$70'). If code strings read a global current locale, hosted unit tests will pick up whatever language was last chosen in that simulator's saved state, so do not apply the global while tests run. A command-line xcodebuild never adds new keys to the .xcstrings; diff the catalog against Build/Intermediates.noindex/<target>.build/*/…/Objects-normal/*/*.stringsdata (skipping files whose 'source' no longer exists) to catch untranslated strings.