Play your own Switch games on iPhone/iPad — one-click macOS app, no terminal. | 把 Switch 游戏装进 iPhone:图形界面一键构建,不用命令行。Bring your own game.
Swift apple-siliconcustom-formathomebrewiosipaipadipadosiphonemetalnative-portnintendo-switchnxnativeromfsswitch-games
iOS shell: follow the system language, remove the language picker
v0lumehid399f3e53769
diff --git a/frontend-ios/Demo/Gen/Info.plist b/frontend-ios/Demo/Gen/Info.plistnew file mode 100644index 00000000..b0763805--- /dev/null+++ b/frontend-ios/Demo/Gen/Info.plist@@ -0,0 +1,27 @@+<?xml version="1.0" encoding="UTF-8"?>+<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">+<plist version="1.0">+<dict>+ <key>CFBundleDevelopmentRegion</key>+ <string>$(DEVELOPMENT_LANGUAGE)</string>+ <key>CFBundleExecutable</key>+ <string>$(EXECUTABLE_NAME)</string>+ <key>CFBundleIdentifier</key>+ <string>$(PRODUCT_BUNDLE_IDENTIFIER)</string>+ <key>CFBundleInfoDictionaryVersion</key>+ <string>6.0</string>+ <key>CFBundleLocalizations</key>+ <array>+ <string>en</string>+ <string>zh-Hans</string>+ </array>+ <key>CFBundleName</key>+ <string>$(PRODUCT_NAME)</string>+ <key>CFBundlePackageType</key>+ <string>APPL</string>+ <key>CFBundleShortVersionString</key>+ <string>1.0</string>+ <key>CFBundleVersion</key>+ <string>1</string>+</dict>+</plist>diff --git a/frontend-ios/Demo/ShellDemo.xcodeproj/project.pbxproj b/frontend-ios/Demo/ShellDemo.xcodeproj/project.pbxprojindex 0565314e..487b6760 100644--- a/frontend-ios/Demo/ShellDemo.xcodeproj/project.pbxproj+++ b/frontend-ios/Demo/ShellDemo.xcodeproj/project.pbxproj@@ -338,7 +338,7 @@buildSettings = {ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;CODE_SIGN_IDENTITY = "iPhone Developer";- INFOPLIST_FILE = ../Tests/ShellHostTests/Fixtures/Games/0100000000030000/DmGame.framework/Info.plist;+ INFOPLIST_FILE = Gen/Info.plist;LD_RUNPATH_SEARCH_PATHS = ("$(inherited)","@executable_path/Frameworks",@@ -370,7 +370,7 @@buildSettings = {ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;CODE_SIGN_IDENTITY = "iPhone Developer";- INFOPLIST_FILE = ../Tests/ShellHostTests/Fixtures/Games/0100000000030000/DmGame.framework/Info.plist;+ INFOPLIST_FILE = Gen/Info.plist;LD_RUNPATH_SEARCH_PATHS = ("$(inherited)","@executable_path/Frameworks",diff --git a/frontend-ios/Demo/project.yml b/frontend-ios/Demo/project.ymlindex 4f9742e2..8ee07e7d 100644--- a/frontend-ios/Demo/project.yml+++ b/frontend-ios/Demo/project.yml@@ -31,6 +31,10 @@ targets:type: folderbuildPhase: resources- path: ../AppIcon.icon # the app icon, shared with the shell app (dm/ios/project-shell.yml)+ info:+ path: Gen/Info.plist+ properties:+ CFBundleLocalizations: [en, zh-Hans] # the string catalogs of ShellUI and ShellHost, so iOS offers them to the package bundlesdependencies:- package: ShellUIproduct: ShellUIdiff --git a/frontend-ios/Sources/ShellHost/HostText.swift b/frontend-ios/Sources/ShellHost/HostText.swiftindex 13dfc6cc..59bf6f91 100644--- a/frontend-ios/Sources/ShellHost/HostText.swift+++ b/frontend-ios/Sources/ShellHost/HostText.swift@@ -3,7 +3,7 @@ import ShellUI/// The host layer's own words, from `Resources/Localizable.xcstrings` (English source, like ShellUI).func hostText(_ key: String.LocalizationValue) -> String {- String(localized: key, bundle: ShellLanguage.bundle(.module))+ String(localized: key, bundle: .module)}/// What is wrong with a bundle that cannot run at all. Each cause has one plain sentence for the player.diff --git a/frontend-ios/Sources/ShellHost/ShellHostModel.swift b/frontend-ios/Sources/ShellHost/ShellHostModel.swiftindex fb192efa..acde06ce 100644--- a/frontend-ios/Sources/ShellHost/ShellHostModel.swift+++ b/frontend-ios/Sources/ShellHost/ShellHostModel.swift@@ -89,13 +89,12 @@ public struct ShellHostConfig: Sendable {deinit { defaultsObserver.map(NotificationCenter.default.removeObserver) }- /// What the details show of the shell settings besides the folders: the interface language and the overlay default.+ /// What the details show of the shell settings besides the folders: the overlay default.private static func choices(of settings: ShellSettingsStore) -> [String] {- [settings.language, settings.gameDefaults.sorted { $0.key < $1.key }.map { "\($0.key)=\($0.value)" }.joined(separator: ",")]+ [settings.gameDefaults.sorted { $0.key < $1.key }.map { "\($0.key)=\($0.value)" }.joined(separator: ",")]}- /// Builds the details again, in the same order. The texts the host writes follow the interface language, so a- /// change of it comes through here, and so does a change of a shell folder or of the performance overlay.+ /// Builds the details again, in the same order. A change of a shell folder or of the performance overlay comes through here.public func refreshAll() {shellChoices = Self.choices(of: shellSettings)details = entries.map(detail(for:))diff --git a/frontend-ios/Sources/ShellUI/LibraryView.swift b/frontend-ios/Sources/ShellUI/LibraryView.swiftindex 4d88a6c5..27b8a353 100644--- a/frontend-ios/Sources/ShellUI/LibraryView.swift+++ b/frontend-ios/Sources/ShellUI/LibraryView.swift@@ -36,8 +36,6 @@ public struct LibraryView: View {@State private var selectedID: String?@State private var settingsOpen: Bool@State private var shellSettingsOpen: Bool- /// The interface language in force. A change rebuilds the views, so every text is read again in the new language.- @State private var shellLanguage = ShellSettingsStore.current.language@State private var controllersOpen: Bool/// The game whose How to fix or How to update explanation is open.@State private var helpGameID: String?@@ -204,7 +202,6 @@ public struct LibraryView: View {.onAppear { self.layout = layout }.onChange(of: layout) { _, new in self.layout = new }}- .id(shellLanguage).animation(reduceMotion ? nil : .smooth(duration: 0.35), value: layout).animation(reduceMotion ? nil : .smooth(duration: 0.3), value: settingsOpen).animation(reduceMotion ? nil : .smooth(duration: 0.3), value: controllersOpen)@@ -234,10 +231,6 @@ public struct LibraryView: View {.onChange(of: games.map(\.id)) { _, ids inif !ids.contains(selectedID ?? "") { selectedID = ids.first; settingsOpen = false }}- .onReceive(NotificationCenter.default.publisher(for: UserDefaults.didChangeNotification)) { _ in- let language = ShellSettingsStore.current.language- if language != shellLanguage { shellLanguage = language }- }}@ViewBuilder private func library(_ selected: GameDetail, layout: ShellLayout, size: CGSize, insets: EdgeInsets) -> some View {diff --git a/frontend-ios/Sources/ShellUI/Resources/Localizable.xcstrings b/frontend-ios/Sources/ShellUI/Resources/Localizable.xcstringsindex 93ba2f37..f07a92e8 100644--- a/frontend-ios/Sources/ShellUI/Resources/Localizable.xcstrings+++ b/frontend-ios/Sources/ShellUI/Resources/Localizable.xcstrings@@ -49,22 +49,6 @@}}},- "Applies to the whole app.": {- "localizations": {- "en": {- "stringUnit": {- "state": "translated",- "value": "Applies to the whole app."- }- },- "zh-Hans": {- "stringUnit": {- "state": "translated",- "value": "对整个 App 生效。"- }- }- }- },"Back": {"localizations": {"en": {@@ -353,22 +337,6 @@}}},- "Follow device": {- "localizations": {- "en": {- "stringUnit": {- "state": "translated",- "value": "Follow device"- }- },- "zh-Hans": {- "stringUnit": {- "state": "translated",- "value": "跟随设备"- }- }- }- },"For a bug report": {"localizations": {"en": {@@ -545,22 +513,6 @@}}},- "Language": {- "localizations": {- "en": {- "stringUnit": {- "state": "translated",- "value": "Language"- }- },- "zh-Hans": {- "stringUnit": {- "state": "translated",- "value": "语言"- }- }- }- },"Library": {"localizations": {"en": {diff --git a/frontend-ios/Sources/ShellUI/ShellSettingsStore.swift b/frontend-ios/Sources/ShellUI/ShellSettingsStore.swiftindex 62a58e5a..b0ace987 100644--- a/frontend-ios/Sources/ShellUI/ShellSettingsStore.swift+++ b/frontend-ios/Sources/ShellUI/ShellSettingsStore.swift@@ -1,13 +1,12 @@import Foundation-/// The shell-level settings, one suite shared by every game: the game-data folder, the cloud-saves folder, the-/// interface language and the default performance HUD. A game's own settings and bookmarks win over these, and+/// The shell-level settings, one suite shared by every game: the game-data folder, the cloud-saves folder+/// and the default performance HUD. A game's own settings and bookmarks win over these, and/// these win over the built-in defaults (ShellSettingsStore priority: game > shell > built-in).public final class ShellSettingsStore: @unchecked Sendable {public static let suiteName = "shell-settings"public static let dataFolderKey = "globalDataBookmark"public static let cloudSavesKey = "globalCloudSavesBookmark"- public static let languageKey = "interfaceLanguage" // "" = follow the device, "zh-Hans", "en"public static let performanceHUDKey = "performanceHUD" // true/false; a game's own row wins when setpublic static let dataFolderNameKey = "globalDataFolderName"public static let cloudSavesNameKey = "globalCloudSavesFolderName"@@ -27,7 +26,6 @@ public final class ShellSettingsStore: @unchecked Sendable {/// The folders' names for the page, written by the host when the player picks them.public var dataFolderName: String? { defaults.string(forKey: Self.dataFolderNameKey) }public var cloudSavesFolderName: String? { defaults.string(forKey: Self.cloudSavesNameKey) }- public var language: String { defaults.string(forKey: Self.languageKey) ?? "" }public var performanceHUD: Bool? { // nil: no shell-level choice, the game's own row decidesdefaults.object(forKey: Self.performanceHUDKey) as? Bool}@@ -36,7 +34,6 @@ public final class ShellSettingsStore: @unchecked Sendable {public func storeCloudSavesFolderName(_ name: String) { defaults.set(name, forKey: Self.cloudSavesNameKey) }public func clearDataFolderName() { defaults.removeObject(forKey: Self.dataFolderNameKey) }public func clearCloudSavesFolderName() { defaults.removeObject(forKey: Self.cloudSavesNameKey) }- public func storeLanguage(_ code: String) { defaults.set(code, forKey: Self.languageKey) }public func storePerformanceHUD(_ on: Bool) { defaults.set(on, forKey: Self.performanceHUDKey) }/// The shell's value for each `DM_*` switch a game's own settings leave alone.@@ -44,21 +41,3 @@ public final class ShellSettingsStore: @unchecked Sendable {performanceHUD.map { ["DM_METAL_HUD": $0 ? "1" : "0"] } ?? [:]}}--/// The interface language the player chose. Empty follows the device.-public enum ShellLanguage {- public static let supported = ["zh-Hans", "en"]- nonisolated(unsafe) private static var cache: [String: Bundle] = [:]- private static let lock = NSLock()-- /// `bundle`, or its folder for the chosen language, so a string table is read in that language whatever the device uses.- public static func bundle(_ bundle: Bundle, language: String = ShellSettingsStore.current.language) -> Bundle {- guard supported.contains(language) else { return bundle }- let key = bundle.bundlePath + "|" + language- lock.lock(); defer { lock.unlock() }- if let found = cache[key] { return found }- guard let path = bundle.path(forResource: language, ofType: "lproj"), let localized = Bundle(path: path) else { return bundle }- cache[key] = localized- return localized- }-}diff --git a/frontend-ios/Sources/ShellUI/ShellSettingsView.swift b/frontend-ios/Sources/ShellUI/ShellSettingsView.swiftindex 84cf3f25..ba4d80d3 100644--- a/frontend-ios/Sources/ShellUI/ShellSettingsView.swift+++ b/frontend-ios/Sources/ShellUI/ShellSettingsView.swift@@ -4,17 +4,9 @@ import SwiftUI/// the library that a change belongs to the shell and not to a game.enum ShellSettingsRows {static let gameID = "shell"- static let language = "shell.language"static let hud = "shell.hud"static let targetPrefix = "shs.row."- static func languageRow(_ store: ShellSettingsStore) -> SettingRow {- SettingRow(id: language, label: ShellStrings.text("Language"), note: ShellStrings.text("Applies to the whole app."),- kind: .choice([SettingOption("", ShellStrings.text("Follow device")), SettingOption("zh-Hans", "中文"),- SettingOption("en", "English")]),- value: store.language)- }-static func hudRow(_ store: ShellSettingsStore) -> SettingRow {SettingRow(id: hud, label: ShellStrings.text("Performance overlay"), note: ShellStrings.text("Used by games that have no choice of their own."),kind: .toggle(on: "1", off: "0"), value: store.performanceHUD == true ? "1" : "0")@@ -23,14 +15,13 @@ enum ShellSettingsRows {/// A change of one of the rows, from the row itself or from the list of choices.static func apply(_ id: String, value: String, to store: ShellSettingsStore) {switch id {- case language where value.isEmpty || ShellLanguage.supported.contains(value): store.storeLanguage(value)case hud: store.storePerformanceHUD(value == "1")default: break}}}-/// The shell's own settings: the game-data folder, the cloud-saves folder, the language and the default performance+/// The shell's own settings: the game-data folder, the cloud-saves folder and the default performance/// overlay. A game's own choices win over these, and these win over the built-in defaults. It looks like a game's/// settings and takes a controller the same way, as a panel over the library.struct ShellSettingsView: View {@@ -86,11 +77,7 @@ struct ShellSettingsView: View {}}SettingsGroup(title: ShellStrings.text("Interface")) {- let language = ShellSettingsRows.languageRow(store), hud = ShellSettingsRows.hudRow(store)- SettingControl(gameID: ShellSettingsRows.gameID, row: language, targetPrefix: ShellSettingsRows.targetPrefix) {- ShellSettingsRows.apply(language.id, value: $0, to: store)- }.equatable()- Rectangle().fill(.white.opacity(0.06)).frame(height: 1)+ let hud = ShellSettingsRows.hudRow(store)SettingControl(gameID: ShellSettingsRows.gameID, row: hud, targetPrefix: ShellSettingsRows.targetPrefix) {ShellSettingsRows.apply(hud.id, value: $0, to: store)}.equatable()diff --git a/frontend-ios/Sources/ShellUI/ShellStyle.swift b/frontend-ios/Sources/ShellUI/ShellStyle.swiftindex 3589cd8a..54e8542f 100644--- a/frontend-ios/Sources/ShellUI/ShellStyle.swift+++ b/frontend-ios/Sources/ShellUI/ShellStyle.swift@@ -14,7 +14,7 @@ public enum ShellPalette {enum ShellStrings {static var bundle: Bundle { .module }- static func text(_ key: String.LocalizationValue) -> String { String(localized: key, bundle: ShellLanguage.bundle(bundle)) }+ static func text(_ key: String.LocalizationValue) -> String { String(localized: key, bundle: bundle) }}@MainActor public enum ShellFonts {diff --git a/frontend-ios/Tests/ShellHostTests/ShellSettingsStoreTests.swift b/frontend-ios/Tests/ShellHostTests/ShellSettingsStoreTests.swiftindex 9c5d455f..1ef2e5e8 100644--- a/frontend-ios/Tests/ShellHostTests/ShellSettingsStoreTests.swift+++ b/frontend-ios/Tests/ShellHostTests/ShellSettingsStoreTests.swift@@ -8,19 +8,18 @@ import ShellUI@Test func theOverlayChoiceIsNilUntilThePlayerMakesOne() {let store = shell()- #expect(store.performanceHUD == nil && store.gameDefaults.isEmpty && store.language == "")+ #expect(store.performanceHUD == nil && store.gameDefaults.isEmpty)store.storePerformanceHUD(true)#expect(store.performanceHUD == true && store.gameDefaults == ["DM_METAL_HUD": "1"])store.storePerformanceHUD(false)#expect(store.gameDefaults == ["DM_METAL_HUD": "0"])}- @Test func theFolderNamesAndTheLanguageAreKept() {+ @Test func theFolderNamesAreKept() {let store = shell()store.storeDataFolderName("Switch")store.storeCloudSavesFolderName("Game Saves")- store.storeLanguage("zh-Hans")- #expect(store.dataFolderName == "Switch" && store.cloudSavesFolderName == "Game Saves" && store.language == "zh-Hans")+ #expect(store.dataFolderName == "Switch" && store.cloudSavesFolderName == "Game Saves")}@Test func aGameChoiceWinsTheShellDefaultWinsTheBuiltInOne() throws {diff --git a/frontend-ios/Tests/ShellUITests/ShellStringsTests.swift b/frontend-ios/Tests/ShellUITests/ShellStringsTests.swiftindex cde6a799..ca319513 100644--- a/frontend-ios/Tests/ShellUITests/ShellStringsTests.swift+++ b/frontend-ios/Tests/ShellUITests/ShellStringsTests.swift@@ -28,21 +28,20 @@ import Testing@Test func theSettingsPageTextsAreThere() throws {let strings = try table("Localizable", in: "ShellUI")- for key in ["Settings", "Done", "Interface", "Language", "Follow device", "Performance overlay", "Game data", "Cloud saves", "Choose folder…"] {+ for key in ["Settings", "Done", "Interface", "Performance overlay", "Game data", "Cloud saves", "Choose folder…"] {#expect(strings[key] != nil, "\(key)")}}- @Test func theChosenLanguageSelectsTheStringTable() {- func text(_ language: String) -> String {- String(localized: "Done", bundle: ShellLanguage.bundle(ShellStrings.bundle, language: language))+ /// The app follows the system language: iOS picks the lproj of the bundle by the device's list, and the app's+ /// Info.plist declares en and zh-Hans (CFBundleLocalizations). So both lprojs must be in the package bundle.+ @Test func bothLanguagesAreCompiledIntoTheBundle() throws {+ func text(_ language: String) throws -> String {+ let path = try #require(ShellStrings.bundle.path(forResource: language, ofType: "lproj"), "\(language).lproj")+ return String(localized: "Done", bundle: try #require(Bundle(path: path)))}- #expect(ShellLanguage.supported == ["zh-Hans", "en"])- #expect(text("en") == "Done")- #expect(text("zh-Hans") != "Done" && !text("zh-Hans").isEmpty)- #expect(ShellLanguage.bundle(ShellStrings.bundle, language: "") == ShellStrings.bundle, "no choice follows the device")- #expect(ShellLanguage.bundle(ShellStrings.bundle, language: "fr") == ShellStrings.bundle, "an unknown choice follows the device")- let count = String(localized: "\(3) of \(5)", bundle: ShellLanguage.bundle(ShellStrings.bundle, language: "zh-Hans"))- #expect(count != "3 of 5", "an interpolated text is found in the chosen language too")+ #expect(try text("en") == "Done")+ #expect(try text("zh-Hans") != "Done")+ #expect(ShellStrings.bundle.path(forResource: "zh-Hant", ofType: "lproj") == nil, "Traditional Chinese has no catalog and falls back")}}diff --git a/patches/0055-ios-shell-declare-en-and-zh-hans-in-cfbundleloca.patch b/patches/0055-ios-shell-declare-en-and-zh-hans-in-cfbundleloca.patchnew file mode 100644index 00000000..e740bdd5--- /dev/null+++ b/patches/0055-ios-shell-declare-en-and-zh-hans-in-cfbundleloca.patch@@ -0,0 +1,25 @@+From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001+From: v0lumehi <[email protected]>+Date: Sun, 1 Nov 2026 16:42:17 +0100+Subject: [PATCH] ios shell: declare en and zh-Hans in CFBundleLocalizations++Upstream-Status: fork-only+Reason: Without CFBundleLocalizations iOS never offers zh-Hans to the shell's package bundles, so a device set to Chinese shows English. The shell follows the system language.+Issue: LNPANDY/NX2Apple#418++---+ dm/ios/project-shell.yml | 1 ++ 1 file changed, 1 insertion(+)++diff --git a/dm/ios/project-shell.yml b/dm/ios/project-shell.yml+index 1fc2956..2f92fc4 100644+--- a/dm/ios/project-shell.yml++++ b/dm/ios/project-shell.yml+@@ -48,6 +48,7 @@ targets:+ path: Gen/Info.plist+ properties:+ CFBundleDisplayName: ${DM_SHELL_NAME}++ CFBundleLocalizations: [en, zh-Hans] # ShellUI and ShellHost carry en and zh-Hans catalogs, iOS offers only the declared ones to the package bundles+ CFBundleVersion: $(CURRENT_PROJECT_VERSION)+ CFBundleShortVersionString: $(MARKETING_VERSION)+ UILaunchScreen: {}diff --git a/patches/series b/patches/seriesindex 2dcac5f0..16e1a39a 100644--- a/patches/series+++ b/patches/series@@ -33,3 +33,4 @@0051-nsp-shell-framework.patch0053-runtime-profile-every-site.patch0054-front-mac-start-with-the-pointer-hidden-when-the.patch+0055-ios-shell-declare-en-and-zh-hans-in-cfbundleloca.patch