如何设置 ViewController 的语言而不是设备的语言?

How can I set language of ViewController instead of device's language?

我想设置 ViewController 的语言(所有字符串都必须以我的语言加载),但设备的语言可能不同。 并且可以是不同的文本方向 LTR 或 RTL。 我该怎么做?

示例: 设备语言:俄语

视图控制器:英语

我对这种情况的处理方法如下

class Strings {

    static var sharedInstance: Strings = Strings()

    // MARK: Properties
    var name: String

    init(){
        switch /* your custom language */ {
        case /* english */:
            self.name = "name"
        }
        // you can add multiple choices here
        default:
            self.name = "russian name"
    }

}
  • 并在 VC
class ViewController: UIViewController {

    // MARK: Properties

    // MARK: Lifecycle Methods
    override func viewDidLoad() {
        super.viewDidLoad()
        // add it here if the app don't have the option to change the language while running
        // Strings.sharedInstance = Strings()
    }

    override func viewWillDisappear(_ animated: Bool) {
        super.viewWillDisappear(animated)
        // or add it here if the app does have the option to change the language while running
        Strings.sharedInstance = Strings()
    }

}