mirror of
https://github.com/xweiba/location-spoofer.git
synced 2026-09-25 16:11:54 +08:00
fix(i18n): 修复首选语言回退并准备 v1.0.8
This commit is contained in:
@@ -0,0 +1,33 @@
|
||||
import Foundation
|
||||
|
||||
/// Chooses the app language from the first preferred language only. iOS normally
|
||||
/// scans the whole preference list, which can select Chinese when Italian is first
|
||||
/// and Chinese is second; this app intentionally falls back to English instead.
|
||||
enum AppLocalization {
|
||||
static func identifier(for preferredLanguages: [String]) -> String {
|
||||
guard let first = preferredLanguages.first,
|
||||
Locale(identifier: first).languageCode == "zh" else {
|
||||
return "en"
|
||||
}
|
||||
return Bundle.preferredLocalizations(
|
||||
from: ["zh-Hans", "zh-Hant"], forPreferences: [first]
|
||||
).first ?? "zh-Hans"
|
||||
}
|
||||
|
||||
static let identifier = identifier(for: Locale.preferredLanguages)
|
||||
static let locale = Locale(identifier: identifier)
|
||||
|
||||
// An explicit .lproj bundle also covers String(localized:) calls made outside
|
||||
// SwiftUI views, where the view's locale environment is not available.
|
||||
private static let localizedBundle: Bundle = {
|
||||
guard let path = Bundle.main.path(forResource: identifier, ofType: "lproj"),
|
||||
let bundle = Bundle(path: path) else {
|
||||
return .main
|
||||
}
|
||||
return bundle
|
||||
}()
|
||||
|
||||
static func string(_ value: String.LocalizationValue) -> String {
|
||||
String(localized: value, bundle: localizedBundle)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user