我目前正在嘗試理解為什么這段代碼不能按預期作業:
// ContentView.swift (before var body: some View)
let name = "Emma"
// ContentView.swift (inside var body: some View)
Text("hello-name \(name)")
// Localizable.strings
"hello-name %@" = "Hello, my name is %@";
我也嘗試過使用NSLocalizedString,因為有時它可以解決問題:
// ContentView.swift (inside var body: some View)
Text(String(format: NSLocalizedString("hello-name %@", comment: "Name"), name))
Text(String(format: NSLocalizedString("hello-name %@", comment: "Name"), name as String))
Text(String(format: NSLocalizedString("hello-name %@", comment: "Name"), name as CVarArg))
但我還是不明白Hello, my name is Emma。你知道為什么嗎?謝謝!
uj5u.com熱心網友回復:
用作字串檔案"hello-name"中的鍵和第一個引數NSLocalizedString
uj5u.com熱心網友回復:
我終于發現問題出在哪里了!由于我太笨了,我填寫了錯誤的Localizable.strings檔案。
當我填寫英文檔案時,我的應用程式以法語(我的第一個 iOS 語言)啟動...
所以,下面的代碼作業得很好:
// ContentView.swift (before var body: some View)
let name = "Emma"
// ContentView.swift (inside var body: some View)
// They all work nicely!
Text("hello-name \(name)")
Text(String(format: NSLocalizedString("hello-name %@", comment: ""), name))
Text(String(format: NSLocalizedString("hello-name %@", comment: ""), name as CVarArg))
// Localizable.strings (with the good one this time)
"hello-name %@" = "Hello, my name is %@";
uj5u.com熱心網友回復:
你有多少 Localizable.strings 檔案?
嘗試宣告
"hello-name %@" = "Hello, my name is %@";
在您的所有語言檔案中。
轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/529564.html
