我正在使用Swift在XCODE 6.3上制作ios应用。而且我的应用程序将具有选择语言功能,如下图所示
我已经有了使用当地语言的故事板。但是我无法找到如何通过按钮以编程方式从应用程序更改本地化。
任何人都知道该怎么做
我正在使用Swift在XCODE 6.3上制作ios应用。而且我的应用程序将具有选择语言功能,如下图所示
我已经有了使用当地语言的故事板。但是我无法找到如何通过按钮以编程方式从应用程序更改本地化。
任何人都知道该怎么做
Answers:
这是一种使用Swift快速更改它的方法,将扩展函数添加到String:
extension String {
func localized(lang:String) ->String {
let path = NSBundle.mainBundle().pathForResource(lang, ofType: "lproj")
let bundle = NSBundle(path: path!)
return NSLocalizedString(self, tableName: nil, bundle: bundle!, value: "", comment: "")
}}
斯威夫特4:
extension String {
func localized(_ lang:String) ->String {
let path = Bundle.main.path(forResource: lang, ofType: "lproj")
let bundle = Bundle(path: path!)
return NSLocalizedString(self, tableName: nil, bundle: bundle!, value: "", comment: "")
}}
然后假设您已使用lang_id.lproj设置了常规Localizable.strings(例如en.lproj,de.lproj等),则可以在需要的任何地方使用它:
var val = "MY_LOCALIZED_STRING".localized("de")
这允许仅通过更新密钥来更改语言。UserDefaults
这是基于@dijipiji的出色答案。这是Swift 3版本。
extension String {
var localized: String {
if let _ = UserDefaults.standard.string(forKey: "i18n_language") {} else {
// we set a default, just in case
UserDefaults.standard.set("fr", forKey: "i18n_language")
UserDefaults.standard.synchronize()
}
let lang = UserDefaults.standard.string(forKey: "i18n_language")
let path = Bundle.main.path(forResource: lang, ofType: "lproj")
let bundle = Bundle(path: path!)
return NSLocalizedString(self, tableName: nil, bundle: bundle!, value: "", comment: "")
}
}
用法
只需添加 .localized
到您的字符串中,如下所示:
"MyString".localized
, MyString
作为Localizable.strings
文件中的密钥。
改变语言
UserDefaults.standard.set("en", forKey: "i18n_language")
updateStrings()
方法,在其中我重置了这些字符串。Hardik,如果您希望在更改语言时加载整个其他故事板,那么我认为这不是正确的解决方案。出于好奇,为什么首先需要加载另一个故事板?似乎很麻烦。
Swift 4中的可用代码:
extension Bundle {
private static var bundle: Bundle!
public static func localizedBundle() -> Bundle! {
if bundle == nil {
let appLang = UserDefaults.standard.string(forKey: "app_lang") ?? "ru"
let path = Bundle.main.path(forResource: appLang, ofType: "lproj")
bundle = Bundle(path: path!)
}
return bundle;
}
public static func setLanguage(lang: String) {
UserDefaults.standard.set(lang, forKey: "app_lang")
let path = Bundle.main.path(forResource: lang, ofType: "lproj")
bundle = Bundle(path: path!)
}
}
和
extension String {
func localized() -> String {
return NSLocalizedString(self, tableName: nil, bundle: Bundle.localizedBundle(), value: "", comment: "")
}
func localizeWithFormat(arguments: CVarArg...) -> String{
return String(format: self.localized(), arguments: arguments)
}
}
呼叫:
let localizedString = "enter".localized()
设置新的语言环境(例如“ ru”):
Bundle.setLanguage(lang: "ru")
斯威夫特4.2
就我而言,如果用户更改语言设置,则必须在运行时更新2件事。
1. Localizable.strings
2.故事板的本地化
我让@John Pang代码更加快捷
BundleExtension.swift
import UIKit
private var bundleKey: UInt8 = 0
final class BundleExtension: Bundle {
override func localizedString(forKey key: String, value: String?, table tableName: String?) -> String {
return (objc_getAssociatedObject(self, &bundleKey) as? Bundle)?.localizedString(forKey: key, value: value, table: tableName) ?? super.localizedString(forKey: key, value: value, table: tableName)
}
}
extension Bundle {
static let once: Void = { object_setClass(Bundle.main, type(of: BundleExtension())) }()
static func set(language: Language) {
Bundle.once
let isLanguageRTL = Locale.characterDirection(forLanguage: language.code) == .rightToLeft
UIView.appearance().semanticContentAttribute = isLanguageRTL == true ? .forceRightToLeft : .forceLeftToRight
UserDefaults.standard.set(isLanguageRTL, forKey: "AppleTe zxtDirection")
UserDefaults.standard.set(isLanguageRTL, forKey: "NSForceRightToLeftWritingDirection")
UserDefaults.standard.set([language.code], forKey: "AppleLanguages")
UserDefaults.standard.synchronize()
guard let path = Bundle.main.path(forResource: language.code, ofType: "lproj") else {
log(.error, "Failed to get a bundle path.")
return
}
objc_setAssociatedObject(Bundle.main, &bundleKey, Bundle(path: path), objc_AssociationPolicy.OBJC_ASSOCIATION_RETAIN_NONATOMIC);
}
}
语言速记
import Foundation
enum Language: Equatable {
case english(English)
case chinese(Chinese)
case korean
case japanese
enum English {
case us
case uk
case australian
case canadian
case indian
}
enum Chinese {
case simplified
case traditional
case hongKong
}
}
extension Language {
var code: String {
switch self {
case .english(let english):
switch english {
case .us: return "en"
case .uk: return "en-GB"
case .australian: return "en-AU"
case .canadian: return "en-CA"
case .indian: return "en-IN"
}
case .chinese(let chinese):
switch chinese {
case .simplified: return "zh-Hans"
case .traditional: return "zh-Hant"
case .hongKong: return "zh-HK"
}
case .korean: return "ko"
case .japanese: return "ja"
}
}
var name: String {
switch self {
case .english(let english):
switch english {
case .us: return "English"
case .uk: return "English (UK)"
case .australian: return "English (Australia)"
case .canadian: return "English (Canada)"
case .indian: return "English (India)"
}
case .chinese(let chinese):
switch chinese {
case .simplified: return "简体中文"
case .traditional: return "繁體中文"
case .hongKong: return "繁體中文 (香港)"
}
case .korean: return "한국어"
case .japanese: return "日本語"
}
}
}
extension Language {
init?(languageCode: String?) {
guard let languageCode = languageCode else { return nil }
switch languageCode {
case "en", "en-US": self = .english(.us)
case "en-GB": self = .english(.uk)
case "en-AU": self = .english(.australian)
case "en-CA": self = .english(.canadian)
case "en-IN": self = .english(.indian)
case "zh-Hans": self = .chinese(.simplified)
case "zh-Hant": self = .chinese(.traditional)
case "zh-HK": self = .chinese(.hongKong)
case "ko": self = .korean
case "ja": self = .japanese
default: return nil
}
}
}
这样使用
var language: [Language] = [.korean, .english(.us), .english(.uk), .english(.australian), .english(.canadian), .english(.indian),
.chinese(.simplified), .chinese(.traditional), .chinese(.hongKong),
.japanese]
Bundle.set(language: languages[indexPath.row].language)
“ Locale.current.languageCode ”将始终返回系统设置语言。因此,我们必须使用“ Locale.preferredLanguages.first ”。但是,返回值看起来像“ ko-US”。这是问题!因此,我使LocaleManager仅获得语言代码。
LocaleManager.swift
import Foundation
struct LocaleManager {
/// "ko-US" → "ko"
static var languageCode: String? {
guard var splits = Locale.preferredLanguages.first?.split(separator: "-"), let first = splits.first else { return nil }
guard 1 < splits.count else { return String(first) }
splits.removeLast()
return String(splits.joined(separator: "-"))
}
static var language: Language? {
return Language(languageCode: languageCode)
}
}
这样使用
guard let languageCode = LocaleManager.languageCode, let title = RemoteConfiguration.shared.logIn?.main?.title?[languageCode] else {
return NSLocalizedString("Welcome!", comment: "")
}
return title
杰里米的答案(在这里)在Swift 4上也很好用(我刚刚用一个简单的应用程序进行了测试,并且更改了初始视图控制器中使用的语言)。
这是同一段代码的Swift版本(出于某些原因,我的队友更喜欢仅Swift而不是与Objective-C混合,所以我翻译了它):
import UIKit
private var kBundleKey: UInt8 = 0
class BundleEx: Bundle {
override func localizedString(forKey key: String, value: String?, table tableName: String?) -> String {
if let bundle = objc_getAssociatedObject(self, &kBundleKey) {
return (bundle as! Bundle).localizedString(forKey: key, value: value, table: tableName)
}
return super.localizedString(forKey: key, value: value, table: tableName)
}
}
extension Bundle {
static let once: Void = {
object_setClass(Bundle.main, type(of: BundleEx()))
}()
class func setLanguage(_ language: String?) {
Bundle.once
let isLanguageRTL = Bundle.isLanguageRTL(language)
if (isLanguageRTL) {
UIView.appearance().semanticContentAttribute = .forceRightToLeft
} else {
UIView.appearance().semanticContentAttribute = .forceLeftToRight
}
UserDefaults.standard.set(isLanguageRTL, forKey: "AppleTextDirection")
UserDefaults.standard.set(isLanguageRTL, forKey: "NSForceRightToLeftWritingDirection")
UserDefaults.standard.synchronize()
let value = (language != nil ? Bundle.init(path: (Bundle.main.path(forResource: language, ofType: "lproj"))!) : nil)
objc_setAssociatedObject(Bundle.main, &kBundleKey, value, objc_AssociationPolicy.OBJC_ASSOCIATION_RETAIN_NONATOMIC);
}
class func isLanguageRTL(_ languageCode: String?) -> Bool {
return (languageCode != nil && Locale.characterDirection(forLanguage: languageCode!) == .rightToLeft)
}
}
花了几天后,我实际上找到了解决方案。不需要重新启动,非常优雅:http : //www.factorialcomplexity.com/blog/2015/01/28/how-to-change-localization-internally-in-your-ios-application.html,检查方法2。不需要手动重新建立所有标题和文本,只需覆盖自定义NSBundle类别的本地化即可。像魅力一样,在Obj-C和Swift项目(经过一些调整)上均可工作。我怀疑它是否会被苹果公司批准,但实际上确实如此。
斯威夫特4
UserDefaults.standard.set(["es", "de", "it"], forKey: "AppleLanguages")
UserDefaults.standard.synchronize()
迅捷3
NSUserDefaults.standardUserDefaults().setObject(["es", "de", "it"], forKey: "AppleLanguages")
NSUserDefaults.standardUserDefaults().synchronize()
资料来源:这里
由whiteagle链接的解决方案实际上可以实时切换语言。这是帖子。
我将其中的示例代码简化为单个.h / .m,它将在内存中即时更改语言。我已经展示了如何从Swift 3调用它。
标头:
//
// NSBundle+Language.h
// ios_language_manager
//
// Created by Maxim Bilan on 1/10/15.
// Copyright (c) 2015 Maxim Bilan. All rights reserved.
//
#import <Foundation/Foundation.h>
@interface NSBundle (Language)
+ (void)setLanguage:(NSString *)language;
@end
实现方式:
//
// NSBundle+Language.m
// ios_language_manager
//
// Created by Maxim Bilan on 1/10/15.
// Copyright (c) 2015 Maxim Bilan. All rights reserved.
//
#import "NSBundle+Language.h"
#import <UIKit/UIKit.h>
#import <objc/runtime.h>
static const char kBundleKey = 0;
@interface BundleEx : NSBundle
@end
@implementation BundleEx
- (NSString *)localizedStringForKey:(NSString *)key value:(NSString *)value table:(NSString *)tableName
{
NSBundle *bundle = objc_getAssociatedObject(self, &kBundleKey);
if (bundle) {
return [bundle localizedStringForKey:key value:value table:tableName];
}
else {
return [super localizedStringForKey:key value:value table:tableName];
}
}
@end
@implementation NSBundle (Language)
+ (void)setLanguage:(NSString *)language
{
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
object_setClass([NSBundle mainBundle], [BundleEx class]);
});
BOOL isLanguageRTL = [self isLanguageRTL:language];
if (isLanguageRTL) {
if ([[[UIView alloc] init] respondsToSelector:@selector(setSemanticContentAttribute:)]) {
[[UIView appearance] setSemanticContentAttribute:
UISemanticContentAttributeForceRightToLeft];
}
}else {
if ([[[UIView alloc] init] respondsToSelector:@selector(setSemanticContentAttribute:)]) {
[[UIView appearance] setSemanticContentAttribute:UISemanticContentAttributeForceLeftToRight];
}
}
[[NSUserDefaults standardUserDefaults] setBool:isLanguageRTL forKey:@"AppleTextDirection"];
[[NSUserDefaults standardUserDefaults] setBool:isLanguageRTL forKey:@"NSForceRightToLeftWritingDirection"];
[[NSUserDefaults standardUserDefaults] synchronize];
id value = language ? [NSBundle bundleWithPath:[[NSBundle mainBundle] pathForResource:language ofType:@"lproj"]] : nil;
objc_setAssociatedObject([NSBundle mainBundle], &kBundleKey, value, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
}
+ (BOOL)isLanguageRTL:(NSString *)languageCode
{
return ([NSLocale characterDirectionForLanguage:languageCode] == NSLocaleLanguageDirectionRightToLeft);
}
@end
要从Swift调用此方法,请确保您的桥接头具有:
#import "NSBundle+Language.h"
然后从您的代码中调用:
Bundle.setLanguage("es")
注意事项:
我没有提供任何示例代码来显示语言选择器或其他内容。原始链接文章确实包含一些内容。
我更改了此代码以不永久更改任何内容。下次运行该应用程序时,它仍将尝试使用用户的首选语言。(一个例外是从右到左语言,请参见下文)
您可以在加载视图之前随时执行此操作,新字符串将生效。但是,如果您需要更改已加载的视图,则可能需要按照原始文章所述重新初始化rootViewController。
这应该适用于从右到左的语言,但是它在NSUserDefaults中为这些语言设置了两个内部持久性首选项。您可能希望通过在应用退出时将语言设置回用户的默认值来撤消该操作:Bundle.setLanguage(Locale.preferredLanguages.first!)
NSLocalizedStringWithDefaultValue
并且没有将我的本地化文本添加到情节提要中:(
首先-这是个坏主意,Apple
建议您使用iOS选择的语言进行本地化。
但是,如果您真的需要它,可以为此目的提供一些小服务
enum LanguageName: String {
case undefined
case en
case es
case fr
case uk
case ru
case de
case pt
}
let DynamicLanguageServiceDidDetectLanguageSwitchNotificationKey = "DynamicLanguageServiceDidDetectLanguageSwitchNotificationKey"
func dynamicLocalizableString(_ key: String) -> String {
return LanguageService.service.dynamicLocalizedString(key)
}
class LanguageService {
private struct Defaults {
static let keyCurrentLanguage = "KeyCurrentLanguage"
}
static let service:LanguageService = LanguageService()
var languageCode: String {
get {
return language.rawValue
}
}
var currentLanguage:LanguageName {
get {
var currentLanguage = UserDefaults.roxy.object(forKey: Defaults.keyCurrentLanguage)
if currentLanguage == nil {
currentLanguage = Locale.preferredLanguages[0]
}
if var currentLanguage = currentLanguage as? String,
let lang = LanguageName(rawValue: currentLanguage.truncatedBy(by:2)) {
return lang
}
return LanguageName.en
}
}
var defaultLanguageForLearning:LanguageName {
get {
var language: LanguageName = .es
if currentLanguage == language {
language = .en
}
return language
}
}
func switchToLanguage(_ lang:LanguageName) {
language = lang
NotificationCenter.default.post(name: NSNotification.Name(rawValue: DynamicLanguageServiceDidDetectLanguageSwitchNotificationKey), object: nil)
}
func clearLanguages() {
UserDefaults.roxy.setValue(nil, forKey:Defaults.keyCurrentLanguage)
print(UserDefaults.roxy.synchronize())
}
private var localeBundle:Bundle?
fileprivate var language: LanguageName = LanguageName.en {
didSet {
let currentLanguage = language.rawValue
UserDefaults.roxy.setValue(currentLanguage, forKey:Defaults.keyCurrentLanguage)
UserDefaults.roxy.synchronize()
setLocaleWithLanguage(currentLanguage)
}
}
// MARK: - LifeCycle
private init() {
prepareDefaultLocaleBundle()
}
//MARK: - Private
fileprivate func dynamicLocalizedString(_ key: String) -> String {
var localizedString = key
if let bundle = localeBundle {
localizedString = NSLocalizedString(key, bundle: bundle, comment: "")
} else {
localizedString = NSLocalizedString(key, comment: "")
}
return localizedString
}
private func prepareDefaultLocaleBundle() {
var currentLanguage = UserDefaults.roxy.object(forKey: Defaults.keyCurrentLanguage)
if currentLanguage == nil {
currentLanguage = Locale.preferredLanguages[0]
}
if let currentLanguage = currentLanguage as? String {
updateCurrentLanguageWithName(currentLanguage)
}
}
private func updateCurrentLanguageWithName(_ languageName: String) {
if let lang = LanguageName(rawValue: languageName) {
language = lang
}
}
private func setLocaleWithLanguage(_ selectedLanguage: String) {
if let pathSelected = Bundle.main.path(forResource: selectedLanguage, ofType: "lproj"),
let bundleSelected = Bundle(path: pathSelected) {
localeBundle = bundleSelected
} else if let pathDefault = Bundle.main.path(forResource: LanguageName.en.rawValue, ofType: "lproj"),
let bundleDefault = Bundle(path: pathDefault) {
localeBundle = bundleDefault
}
}
}
然后将rootViewControllerClass设置为:
import Foundation
protocol Localizable {
func localizeUI()
}
和
class LocalizableViewController: UIViewController, Localizable {
// MARK: - LifeCycle
override func viewDidLoad() {
super.viewDidLoad()
NotificationCenter.default.addObserver(self, selector: #selector(self.localizeUI), name: NSNotification.Name(rawValue:DynamicLanguageServiceDidDetectLanguageSwitchNotificationKey), object: nil)
}
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
localizeUI()
}
deinit {
NotificationCenter.default.removeObserver(self)
}
}
extension LocalizableViewController: Localizable {
// MARK: - Localizable
func localizeUI() {
fatalError("Must Override to provide inApp localization functionality")
}
}
比继承每个控制器LocalizableViewController
并实现localizeUI()
而不是像这样NSLocalizedString
使用dynamicLocalizableString
:
func localizeOnceUI() {
label.text = dynamicLocalizableString("keyFrom<"Localizable.strings">")
}
切换语言:
LanguageService.service.switchToLanguage(.en)
另请注意-如果要动态本地化小部件或其他应用程序部件,则需要其他步骤和逻辑修改。
这是我对字符串扩展的解决方案。@Das答案提高了安全性。
extension String {
var localized: String {
guard let path = Bundle.main.path(forResource: Locale.current.regionCode?.lowercased(), ofType: "lproj"), let bundle = Bundle(path: path) else {
return NSLocalizedString(self, tableName: nil, bundle: Bundle.main, value: "", comment: "")
}
return NSLocalizedString(self, tableName: nil, bundle: bundle, value: "", comment: "")
}
}
这是Swift 4的更新答案
let language = "es" // replace with Locale code
guard let path = Bundle.main.path(forResource: language, ofType: "lproj") else {
return self
}
guard let bundle = Bundle(path: path) else {
return self
}
return NSLocalizedString(self, tableName: nil, bundle: bundle, value: "", comment: "")
class ViewController: UIViewController {
@IBOutlet weak var resetOutlet: MyButton! {
didSet {
resetOutlet.setTitle("RESET".localized().uppercased(), for: .normal)
}
}`
}
extension String {
func localized(tableName: String = "Localizable") -> String {
if let languageCode = Locale.current.languageCode, let preferredLanguagesFirst = Locale.preferredLanguages.first?.prefix(2) {
if languageCode != preferredLanguagesFirst {
if let path = Bundle.main.path(forResource: "en", ofType: "lproj") {
let bundle = Bundle.init(path: path)
return NSLocalizedString(self, tableName: tableName, bundle: bundle!, value: self, comment: "")
}
}
}
return NSLocalizedString(self, tableName: tableName, value: self, comment: "")
}
}
最新的Swift语法:
import Foundation
extension String {
func localized(lang:String) ->String {
let path = Bundle.main.path(forResource: lang, ofType: "lproj")
let bundle = Bundle(path: path!)
return NSLocalizedString(self, tableName: nil, bundle: bundle!, value: "", comment: "")
}
}
如果您需要立即转换系统字符串(返回,取消,完成...),则这是John Pang的解决方案的扩展:
private var kBundleKey: UInt8 = 0
class BundleEx: Bundle {
override func localizedString(forKey key: String, value: String?, table tableName: String?) -> String {
if let bundle = objc_getAssociatedObject(self, &kBundleKey) {
return (bundle as! Bundle).localizedString(forKey: key, value: value, table: tableName)
}
return super.localizedString(forKey: key, value: value, table: tableName)
}
}
private var kBundleUIKitKey: UInt8 = 0
class BundleUIKitEx: Bundle {
override func localizedString(forKey key: String, value: String?, table tableName: String?) -> String {
if let bundle = objc_getAssociatedObject(self, &kBundleUIKitKey) {
return (bundle as! Bundle).localizedString(forKey: key, value: value, table: tableName)
}
return super.localizedString(forKey: key, value: value, table: tableName)
}
}
extension Bundle {
static let once: Void = {
object_setClass(Bundle.main, type(of: BundleEx()))
object_setClass(Bundle(identifier:"com.apple.UIKit"), type(of: BundleUIKitEx()))
}()
class func setLanguage(_ language: String?) {
Bundle.once
let isLanguageRTL = Bundle.isLanguageRTL(language)
if (isLanguageRTL) {
UIView.appearance().semanticContentAttribute = .forceRightToLeft
} else {
UIView.appearance().semanticContentAttribute = .forceLeftToRight
}
UserDefaults.standard.set(isLanguageRTL, forKey: "AppleTextDirection")
UserDefaults.standard.set(isLanguageRTL, forKey: "NSForceRightToLeftWritingDirection")
UserDefaults.standard.synchronize()
let value = (language != nil ? Bundle.init(path: (Bundle.main.path(forResource: language, ofType: "lproj"))!) : nil)
objc_setAssociatedObject(Bundle.main, &kBundleKey, value, objc_AssociationPolicy.OBJC_ASSOCIATION_RETAIN_NONATOMIC);
if let uiKitBundle = Bundle(identifier: "com.apple.UIKit") {
var valueUIKit: Bundle? = nil
if let lang = language,
let path = uiKitBundle.path(forResource: lang, ofType: "lproj") {
valueUIKit = Bundle(path: path)
}
objc_setAssociatedObject(uiKitBundle, &kBundleUIKitKey, valueUIKit, objc_AssociationPolicy.OBJC_ASSOCIATION_RETAIN_NONATOMIC);
}
class func isLanguageRTL(_ languageCode: String?) -> Bool {
return (languageCode != nil && Locale.characterDirection(forLanguage: languageCode!) == .rightToLeft)
}
}
如果要转换系统字符串,则必须对UIKit Bundle做同样的事情。
这就是苹果公司关于更改语言的说法;
通常,您不应在应用程序内更改iOS系统语言(通过使用AppleLanguages首选项键)。这违反了在设置应用程序中切换语言的基本iOS用户模型,并且还使用了未记录的首选项键,这意味着将来某个时候,键名可能会更改,这会破坏您的应用程序。
因此,建议您将用户导航到应用程序的常规设置页面,该页面可在
设置-> [您的应用名称]->首选语言
为了直接打开应用程序设置从您的应用程序,您可以使用以下代码段;
对于斯威夫特;
let settingsURL = URL(string: UIApplication.openSettingsURLString)!
UIApplication.shared.open(settingsURL, options: [:], completionHandler: nil)
对于Obj-C;
NSURL *settingsURL = [NSURL URLWithString:UIApplicationOpenSettingsURLString];
[[UIApplication sharedApplication] openURL:settingsURL options:@{} completionHandler:nil];
提示: 在导航到设置页面之前,最好弹出对话框并说出用户切换到设置页面后应该执行的操作,这对于您的应用程序来说是更好的用户体验。
如何在您的应用程序中支持每个应用程序的语言设置:https :
//developer.apple.com/news/?id=u2cfuj88
如何从应用程序中的自定义语言选择器过渡到
到系统范围内对应用程序内语言选择器的支持,如果您支持iOS 13或macOS Catalina或更高版本,则不再需要提供一种在应用程序中选择语言的方法。如果当前提供这样的UI,则应将其删除,以免引起客户混乱以及与系统的潜在冲突。
如果您想引导人们进行系统设置以进行语言选择,则可以使用直接在iOS上的“设置”应用程序中启动的流程来替换应用程序的自定义UI。
在iOS上,添加以下内容:
UIApplication.shared.open(URL(string: UIApplication.openSettingsURLString)!)
在macOS上,将用户引导至“系统偏好设置”>“语言和区域”以为您的应用添加每种语言的设置。