How to implement localization in Swift UI

后端 未结 6 2090
迷失自我
迷失自我 2020-12-09 03:31

Can anybody help me? I can\'t find any description of the localization in Swift UI. Can anyone please give advice or better an example of how to localize for example T

6条回答
  •  暗喜
    暗喜 (楼主)
    2020-12-09 04:27

    To use Localazable in SwiftUI, you can perform this way:

    import SwiftUI to use LocalizedStringKey in your files

    //MARK: - File where you enum your keys to your Localized file
    enum ButtonName: LocalizedStringKey {
    case submit
    case cancel
    }
    
    //MARK: - Your Localized file where are your translation
    "submit" = "Submit is pressed";
    "cancel" = "Cancel";
    
    //MARK: - In your code
    let submitButtonName = ButtonName.submit.rawValue
    let cancelButtonName = ButtonName.cancel.rawValue
    
    VStack {
    Text(submitButtonName)
    Text(cancelButtonName)
    }
    

提交回复
热议问题