[英]SwiftUI - Localization comment not visible in .xcloc file
I am trying to add the localization comment, but it does not show up in the exported localisations file (.xcloc file) when opened in the editor.我正在尝试添加本地化注释,但在编辑器中打开时它不会显示在导出的本地化文件(.xcloc 文件)中。
How can I add a localization comment to an array of values, so that it is actually visible in the exported file?如何将本地化注释添加到值数组,以便它在导出的文件中实际可见?
Here's my code:这是我的代码:
let fontWeightNames: [LocalizedStringKey] = ["Ultra Light", "Thin", "Light", "Regular", "Medium", "Semibold", "Bold", "Heavy", "Black"]
var currentFontWeightName: LocalizedStringKey {
fontWeightNames[fontWeights.firstIndex(of: currentFontWeight)!]
}
Text(currentFontWeightName, comment: "Inside Font Weight Picker")
I've tried your code and tested different scenarios but I can't tell why is this happening.我试过你的代码并测试了不同的场景,但我不知道为什么会这样。 The only thing I can say is that somehow it is related to the fact of having the localizations stored in variables.我唯一能说的是,它与将本地化存储在变量中这一事实有关。
If you store the values directly as Text views, it works.如果您将值直接存储为文本视图,它就可以工作。 I hope this could be helpful to you.我希望这对你有帮助。
struct ContentView: View {
private let fontWeightNames: [Text] = [
Text("Ultra Light", comment: "Ultra Light comment"),
Text("Thin", comment: "Thin comment"),
Text("Light", comment: "Light comment"),
Text("Regular", comment: "Regular"),
Text("Medium", comment: "Medium comment"),
Text("Semibold", comment: "Semibold comment"),
Text("Bold", comment: "Bold comment"),
Text("Heavy", comment: "Heavy"),
Text("Black", comment: "Black comment")
]
private var fontWeights: [Text] {
[fontWeightNames[2], fontWeightNames[1]]
}
private var currentFontWeight: Text {
fontWeightNames[1]
}
private var currentFontWeightName: Text {
fontWeightNames[fontWeights.firstIndex(of: currentFontWeight)!]
}
var body: some View {
currentFontWeightName
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.