How to implement localization in Swift UI

后端 未结 6 2088
迷失自我
迷失自我 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:31

    For swift UI file, you just need to insert string key from localization .strings file

    import SwiftUI

    struct ContentView: View {
        var body: some View {
            VStack {
                Text("selectLanguage")
                Text("languagesList")
            }
    
    
    
        }
    }
    
    struct ContentView_Previews: PreviewProvider {
        static var previews: some View {
            ContentView()
                .environment(\.locale, .init(identifier: "en"))
        }
    }
    

    and this is an example from .strings file

    "selectLanguage" = "Select language";
    "languagesList" = "Languages list";
    

    result is here

提交回复
热议问题