以编程方式在运行 iOS 时动态更改语言

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/5109245/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-30 19:00:42  来源:igfitidea点击:

Changing language on the fly, in running iOS, programmatically

iphoneioslocalizationruntime

提问by gabrielstuff

I've been stackling and googling for hours. And I'm kind of desperate now. I would like to change the language of my application inside the app not only with the default language.

我已经堆积和谷歌搜索了几个小时。而我现在有点绝望。我想不仅使用默认语言更改应用程序内应用程序的语言。

From what I've tried I stuck like everybody with the reboot step. Meaning, apples forces you to restart the app manually. Meaning you have to quit the app and then starting it up again.

根据我的尝试,我像每个人一样坚持重启步骤。意思是,苹果强制您手动重新启动应用程序。这意味着您必须退出应用程序,然后重新启动它。

Well, after googling, I was trying to setup an alarm and then forcing later the app to exit with

好吧,在谷歌搜索之后,我试图设置一个警报,然后强迫应用程序退出

exit(0);

My bad, apple seems not to like this and prevent developer from using it... I guess I'm not pointing in the right direction.

我的不好,苹果似乎不喜欢这个并阻止开发人员使用它......我想我没有指向正确的方向。

Finally, despite all the problem, I could meet I would like to discuss about that.

最后,尽管存在所有问题,但我可以见面,我想讨论一下。

Any hints?

任何提示?



EDIT, infos from APPLE

编辑,来自苹果的信息

In general, you should not change the iOS system language (via use of the AppleLanguages pref key) from within your application. This goes against the basic iOS user model for switching languages in the Settings app, and also uses a preference key that is not documented, meaning that at some point in the future, the key name could change, which would break your application.

If you want to switch languages in your application, you can do so via manually loading resource files in your bundle. You can use NSBundle:pathForResource:ofType:inDirectory:forLocalization: for this purpose, but keep in mind that your application would be responsible for all loading of localized data.

Regarding the exit(0) question, Apple DTS cannot comment on the app approval process. You should contact [email protected] to get an answer for this question.

通常,您不应在应用程序中更改 iOS 系统语言(通过使用 AppleLanguages 首选项键)。这与用于在“设置”应用中切换语言的基本 iOS 用户模型背道而驰,并且还使用了未记录的首选项键,这意味着在将来的某个时候,键名称可能会更改,这会破坏您的应用程序。

如果你想在你的应用程序中切换语言,你可以通过在你的包中手动加载资源文件来实现。您可以使用 NSBundle:pathForResource:ofType:inDirectory:forLocalization: 为此目的,但请记住,您的应用程序将负责所有本地化数据的加载。

关于 exit(0) 问题,Apple DTS 无法对应用审批流程发表评论。您应该联系 [email protected] 以获得此问题的答案。

Well, I have to choose so far.

好吧,我必须选择到目前为止。

回答by Swissdude

This is a fairly old question, but I was just struggling with the same problem and found this solution:

这是一个相当古老的问题,但我只是在解决同样的问题并找到了这个解决方案:

http://aggressive-mediocrity.blogspot.com/2010/03/custom-localization-system-for-your.html

http://aggressive-mediocrity.blogspot.com/2010/03/custom-localization-system-for-your.html

Which does exactly what you need (and might be helpful for others who with the same problem :)

这正是您所需要的(并且可能对遇到相同问题的其他人有所帮助:)

回答by anoop4real

Below link has a nice implementation of having custom language from with in the application.

下面的链接有一个很好的实现,可以在应用程序中使用自定义语言。

manual language selection in an iOS-App (iPhone and iPad)

在 iOS 应用程序(iPhone 和 iPad)中手动选择语言

Attempted a SWIFT version find it here LanguageSettings_Swift

尝试使用 SWIFT 版本在此处找到它 LanguageSettings_Swift

LanguageChange

语言更改

-anoop

-anoop

回答by meronix

yes, i had the same problem, then i managed it with my own language setting in my prefFile, where i set a variable for the language setting:

是的,我遇到了同样的问题,然后我在我的 prefFile 中使用我自己的语言设置进行了管理,在那里我为语言设置设置了一个变量:

// write a new value in file and set the var
- (void)changeLangInPrefFile:(NSString *)newLanguage {
    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
    NSString *documentsDirectory = [paths objectAtIndex:0];
    NSString *path = [documentsDirectory stringByAppendingPathComponent:@"myPreference.plist"];
    NSMutableDictionary *data = [[NSMutableDictionary alloc] initWithContentsOfFile: path];
    //here add elements to data file and write data to file
    [data setObject:newLanguage forKey:@"language"];
    [data writeToFile:path atomically:YES];
    [data release];

// NSString *chosenLang; <- declared in .h file
    if (chosenLang != nil){
        [chosenLang release];
        chosenLang = nil;
    }
    chosenLang = [[NSString alloc] initWithString:(@"%@",newLanguage)];

}

// read the language from file and set the var:
- (void)readFromFileInBundleDocuments {
    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
    NSString *documentsDirectory = [paths objectAtIndex:0];
    NSString *path = [documentsDirectory stringByAppendingPathComponent:@"myPreference.plist"];
    NSMutableDictionary *savedStock = [[NSMutableDictionary alloc] initWithContentsOfFile:path];

    NSString *chosenLangTemp = [savedStock objectForKey:@"language"];
    NSLog (@"read in file: %@", chosenLangTemp);
    if (chosenLang != nil){
        [chosenLang release];
        chosenLang = nil;
    }
    chosenLang = [[NSString alloc] initWithString:(@"%@",chosenLangTemp)];
    [savedStock release];
}

then i load all the contents from different files depending on the language for example i can load "an_image_eng.png" or "an_image_ita.png", or have 2 different .xib file and for the text to load i use different dictionary-files, one for each language, with all words/expressions translated, i just load the chosen one and read in it the right expression for every text to be load (the code to load it is similar to the method i wrote in this example, you can just arrange it to read the right word for every expression: just look at the value for objectForKey in the right dictionary file, where objectForKey is the word to translate and its value is the word translated)...

然后我根据语言加载来自不同文件的所有内容,例如我可以加载“an_image_eng.png”或“an_image_ita.png”,或者有 2 个不同的 .xib 文件和文本加载我使用不同的字典文件,每种语言一个,翻译所有单词/表达式,我只加载所选的一个并在其中读取要加载的每个文本的正确表达式(加载它的代码类似于我在本示例中编写的方法,您可以只需安排它为每个表达式读取正确的单词:只需查看正确字典文件中 objectForKey 的值,其中 objectForKey 是要翻译的单词,其值是翻译的单词)...

回答by Ryan

Generally, the language the user sees is determined by the locale setting, which is a system-wide setting. Only the user can change it, and when he does, SpringBoard and every running application on the device must restart. There is no way around this because all system apps and frameworks assume that the locale doesn't change once they start running. Changing the apps and frameworks to not require a relaunch would be very difficult for Apple to do.

通常,用户看到的语言由区域设置决定,这是一个系统范围的设置。只有用户可以更改它,当他更改时,SpringBoard 和设备上每个正在运行的应用程序都必须重新启动。没有办法解决这个问题,因为所有系统应用程序和框架都假设语言环境一旦开始运行就不会改变。将应用程序和框架更改为不需要重新启动对 Apple 来说是非常困难的。

I'm guessing that you either want to vary the language of your app's interface completely independently of the system locale setting, or you want to use the system locale setting by default but allow the user to override it for just your app.

我猜您要么想完全独立于系统区域设置来改变应用程序界面的语言,要么您想默认使用系统区域设置,但允许用户仅为您的应用程序覆盖它。

You can get the current locale and examine its various values using +[NSLocale currentLocale]. To display your app's user interface in a language that is independent of the system locale, you'll need to avoid usage of NSLocalizedString()entirely, and use some sort of custom state of your own to determine which strings to display to the user and how to modify the interface to fit your app's language. It'll be up to you to keep your app's language state and modify its user interface appropriately.

您可以使用 获取当前语言环境并检查其各种值+[NSLocale currentLocale]。要以独立于系统区域设置的语言显示您的应用程序的用户界面,您需要NSLocalizedString()完全避免使用,并使用您自己的某种自定义状态来确定向用户显示哪些字符串以及如何修改适合您应用程序语言的界面。保持应用程序的语言状态并适当修改其用户界面取决于您。

回答by Pincha

This is an old question, but i was developing an helper that notifies me when the language change on the fly.

这是一个老问题,但我正在开发一个帮助程序,当语言即时更改时会通知我。

Take a look at the code of helper:

看一下helper的代码:

import Foundation

class LocalizableLanguage {

    // MARK: Constants

    fileprivate static let APPLE_LANGUAGE_KEY = "AppleLanguages"

    /// Notification Name to observe when language change
    static let ApplicationDidChangeLanguage = Notification.Name("ApplicationDidChangeLanguage")

    // MARK: Properties

    /// An array with all available languages as String
    static var availableLanguages: [String]? = {
        return UserDefaults.standard.object(forKey: APPLE_LANGUAGE_KEY) as? [String]
    }()

    /// The first element of available languages that is the current language
    static var currentLanguageCode: String? = {
        return availableLanguages?.first
    }()

    /// The current language code with just 2 characters
    static var currentShortLanguageCode: String? = {
        guard let currentLanguageCode = currentLanguageCode else {
            return nil
        }

        let strIndex = currentLanguageCode.index(currentLanguageCode.startIndex, offsetBy: 2)
        return currentLanguageCode.substring(to: strIndex)
    }()

    // MARK: Handle functions

    /// This accepts the short language code or full language code
    /// Setting this will send a notification with name "ApplicationDidChangeLanguage", that can be observed in order to refresh your localizable strings
    class func setLanguage(withCode langCode: String) {

        let matchedLangCode = availableLanguages?.filter {
            
NotificationCenter.default.addObserver(forName: LocalizableLanguage.ApplicationDidChangeLanguage, object: nil, queue: nil) { notification in
            guard let langCode = notification.object as? String else {
                return
            }
            self.accountStore.languageCode.value = langCode
        } 
.contains(langCode) }.first guard let fullLangCode = matchedLangCode else { return } var reOrderedArray = availableLanguages?.filter {
LocalizableLanguage.setLanguage(withCode: "en")
.contains(langCode) == false } reOrderedArray?.insert(fullLangCode, at: 0) guard let langArray = reOrderedArray else { return } UserDefaults.standard.set(langArray, forKey: APPLE_LANGUAGE_KEY) UserDefaults.standard.synchronize() LocalizableLanguage.refreshAppBundle() NotificationCenter.default.post(name: ApplicationDidChangeLanguage, object: fullLangCode) } } // MARK: Refresh Bundle Helper private extension LocalizableLanguage { class func refreshAppBundle() { MethodSwizzleGivenClassName(cls: Bundle.self, originalSelector: #selector(Bundle.localizedString(forKey:value:table:)), overrideSelector: #selector(Bundle.specialLocalizedStringForKey(_:value:table:))) } class func MethodSwizzleGivenClassName(cls: AnyClass, originalSelector: Selector, overrideSelector: Selector) { let origMethod: Method = class_getInstanceMethod(cls, originalSelector); let overrideMethod: Method = class_getInstanceMethod(cls, overrideSelector); if (class_addMethod(cls, originalSelector, method_getImplementation(overrideMethod), method_getTypeEncoding(overrideMethod))) { class_replaceMethod(cls, overrideSelector, method_getImplementation(origMethod), method_getTypeEncoding(origMethod)); } else { method_exchangeImplementations(origMethod, overrideMethod); } } } extension Bundle { func specialLocalizedStringForKey(_ key: String, value: String?, table tableName: String?) -> String { let availableLanguages = UserDefaults.standard.object(forKey: LocalizableLanguage.APPLE_LANGUAGE_KEY) as? [String] let currentLanguageCode = availableLanguages?.first ?? "en-US" let currentShortLanguageCode = currentLanguageCode.substring(to: currentLanguageCode.index(currentLanguageCode.startIndex, offsetBy: 2)) let path = Bundle.main.path(forResource: currentLanguageCode, ofType: "lproj") ?? Bundle.main.path(forResource: currentShortLanguageCode, ofType: "lproj") ?? Bundle.main.path(forResource: "Base", ofType: "lproj") guard self == Bundle.main, let bundlePath = path, let bundle = Bundle(path: bundlePath) else { return self.specialLocalizedStringForKey(key, value: value, table: tableName) } return bundle.specialLocalizedStringForKey(key, value: value, table: tableName) } }

You just need to copy that code and put in your project.

您只需要复制该代码并将其放入您的项目中。

Then, you simple implement the listener like this:

然后,您可以像这样简单地实现侦听器:

import Foundation

extension String {

    var localized: String {
        return NSLocalizedString(self, comment: "")
    }

}

Note that this line self.accountStore.languageCode.value = langCodeis what i need to refresh when the app language as changed, then i can easily change all strings of my ViewModels in order to change the language to the user immediately.

请注意,self.accountStore.languageCode.value = langCode当应用程序语言更改时,我需要刷新这一行,然后我可以轻松更改 ViewModel 的所有字符串,以便立即将语言更改为用户。

In order to change the language, you can just call:

为了改变语言,你可以调用:

main.view.title = "Title test";

Other helper that could be nice to you is:

其他可能对你很好的帮手是:

"main.view.title".localized

So if you have in your localizable files something like that:

因此,如果您在可本地化的文件中有这样的内容:

enum LanguageName: String {
    case undefined
    case en
    case es
}

let DynamicLanguageServiceDidDetectLanguageSwitchNotificationKey = "DynamicLanguageServiceDidDetectLanguageSwitchNotificationKey"

func dynamicLocalizableString(_ key: String) -> String {
    return LanguageService.service.dynamicLocalizedString(key)
}

class LanguageService {

    private struct Defaults {
        static let keyAppleLanguage = "AppleLanguages"
        static let keyCurrentLanguage = "KeyCurrentLanguage"
    }

    static let service:LanguageService = LanguageService()

    var languageCode: String {
        get {
            return language.rawValue
        }
    }

    var currentLanguage:LanguageName {
        get {
            var currentLanguage = UserDefaults.standard.object(forKey: Defaults.keyCurrentLanguage)
            if let currentLanguage = currentLanguage as? String {
                UserDefaults.standard.set([currentLanguage], forKey: Defaults.keyAppleLanguage)
                UserDefaults.standard.synchronize()
            } else {
                if let languages = UserDefaults.standard.object(forKey: Defaults.keyAppleLanguage) as? [String] {
                    currentLanguage = languages.first
                }
            }
            if let currentLanguage = currentLanguage as? String, 
                let lang = LanguageName(rawValue: currentLanguage) {
                return lang
            }
            return LanguageName.undefined
        }
    }

    func switchToLanguage(_ lang:LanguageName) {
        language = lang
        NotificationCenter.default.post(name: NSNotification.Name(rawValue: DynamicLanguageServiceDidDetectLanguageSwitchNotificationKey), object: nil)
    }

    private var localeBundle:Bundle?

    fileprivate var language: LanguageName = LanguageName.en {
        didSet {
            let currentLanguage = language.rawValue

            UserDefaults.standard.set([currentLanguage], forKey:Defaults.keyAppleLanguage)
            UserDefaults.standard.setValue(currentLanguage, forKey:Defaults.keyCurrentLanguage)
            UserDefaults.standard.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.standard.object(forKey: Defaults.keyCurrentLanguage)
        if let currentLanguage = currentLanguage as? String {
            UserDefaults.standard.set([currentLanguage], forKey: Defaults.keyAppleLanguage)
            UserDefaults.standard.synchronize()
        } else {
            if let languages = UserDefaults.standard.object(forKey: Defaults.keyAppleLanguage) as? [String] {
                currentLanguage = languages.first
            }
        }

        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
        }
    }
}

You can simple call:

您可以简单地调用:

protocol Localizable {
    func localizeUI()
}

And you have your string translated.

你已经翻译了你的字符串。

回答by Manish Nahar

With iOS 13 users can select App-specific language. if you really want to provide the facility to select language via app only then you can provide the facility to open settings within the app to select language. https://developer.apple.com/videos/play/wwdc2019/403/

使用 iOS 13 用户可以选择应用程序特定的语言。如果您真的想提供仅通过应用程序选择语言的功能,那么您可以提供在应用程序中打开设置以选择语言的功能。 https://developer.apple.com/videos/play/wwdc2019/403/

回答by gbk

According to Apple guidelinesthis is not a good idea to change language in the app programmatically, but in case u have no power to change requested behaviour, you can do something like next:

据此,以Apple guidelines编程方式更改应用程序中的语言不是一个好主意,但如果您无权更改请求的行为,您可以执行以下操作:

  1. Prepare some service to manage your language even after app restart

    class LocalizableViewController: UIViewController {
    
        // 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")
        }
    }
    
  2. Add some rules to make sure you UI components will be always updated:

    final class WelcomeTableViewController: LoadableTableViewController
    
  3. Implement them

    LanguageService.service.switchToLanguage(.en)
    
  4. Inherit any controller u want to conform dynamic app switch functionality and implement localizeUI()func

    label.text = dynamicLocalizableString(<KEY_IN_STRINGS>)
    
  5. Switch language as needed:

    enum LanguageName: String {
        case undefined
        case en
        case es
    }
    
    let DynamicLanguageServiceDidDetectLanguageSwitchNotificationKey = "DynamicLanguageServiceDidDetectLanguageSwitchNotificationKey"
    
    func dynamicLocalizableString(_ key: String) -> String {
        return LanguageService.service.dynamicLocalizedString(key)
    }
    
    class LanguageService {
    
        private struct Defaults {
            static let keyAppleLanguage = "AppleLanguages"
            static let keyCurrentLanguage = "KeyCurrentLanguage"
        }
    
        static let service:LanguageService = LanguageService()
    
        var languageCode: String {
            get {
                return language.rawValue
            }
        }
    
        var currentLanguage:LanguageName {
            get {
                var currentLanguage = UserDefaults.standard.object(forKey: Defaults.keyCurrentLanguage)
                if let currentLanguage = currentLanguage as? String {
                    UserDefaults.standard.set([currentLanguage], forKey: Defaults.keyAppleLanguage)
                    UserDefaults.standard.synchronize()
                } else {
                    if let languages = UserDefaults.standard.object(forKey: Defaults.keyAppleLanguage) as? [String] {
                        currentLanguage = languages.first
                    }
                }
                if let currentLanguage = currentLanguage as? String, 
                    let lang = LanguageName(rawValue: currentLanguage) {
                    return lang
                }
                return LanguageName.undefined
            }
        }
    
        func switchToLanguage(_ lang:LanguageName) {
            language = lang
            NotificationCenter.default.post(name: NSNotification.Name(rawValue: DynamicLanguageServiceDidDetectLanguageSwitchNotificationKey), object: nil)
        }
    
        private var localeBundle:Bundle?
    
        fileprivate var language: LanguageName = LanguageName.en {
            didSet {
                let currentLanguage = language.rawValue
    
                UserDefaults.standard.set([currentLanguage], forKey:Defaults.keyAppleLanguage)
                UserDefaults.standard.setValue(currentLanguage, forKey:Defaults.keyCurrentLanguage)
                UserDefaults.standard.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.standard.object(forKey: Defaults.keyCurrentLanguage)
            if let currentLanguage = currentLanguage as? String {
                UserDefaults.standard.set([currentLanguage], forKey: Defaults.keyAppleLanguage)
                UserDefaults.standard.synchronize()
            } else {
                if let languages = UserDefaults.standard.object(forKey: Defaults.keyAppleLanguage) as? [String] {
                    currentLanguage = languages.first
                }
            }
    
            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
            }
        }
    }
    
  6. All localizabled string should be set as :

    protocol Localizable {
        func localizeUI()
    }
    
  1. 即使在应用程序重新启动后,准备一些服务来管理您的语言

    class LocalizableViewController: UIViewController {
    
        // 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")
        }
    }
    
  2. 添加一些规则以确保您的 UI 组件将始终更新:

    final class WelcomeTableViewController: LoadableTableViewController
    
  3. 实施它们

    LanguageService.service.switchToLanguage(.en)
    
  4. 继承您想要符合动态应用程序切换功能并实现localizeUI()func 的任何控制器

    label.text = dynamicLocalizableString(<KEY_IN_STRINGS>)
    
  5. 根据需要切换语言:

    ##代码##
  6. 所有本地化字符串应设置为:

    ##代码##

Note: dont forget to add Localizable.stringswith same codes as in LanguageName

注意:不要忘记添加Localizable.strings与中相同的代码LanguageName

enter image description here

在此处输入图片说明