【问题标题】:Localizable.strings works for String, but not for Double and Integer 32Localizable.strings 适用于 String,但不适用于 Double 和 Integer 32
【发布时间】:2021-06-06 16:29:49
【问题描述】:

作为 Swift 新手,我正在尝试在 Github 本地化 a simple SwiftUI and Core Data project

我已将以下en.lproj/Localizable.strings 文件添加到我的项目中:

"elo-rating %@" = "Elo rating: %@";
"avg-time %@" = "Average time: %@";
"avg-score %@" = "Average score: %@";

在我的自定义 SwiftUI 视图 TopRow.swift 中,我正在尝试使用上述 3 个键:

struct TopRow: View {
    let topEntity:TopEntity
    
    var body: some View {
        HStack {
            DownloadImage(url: topEntity.photo ?? "TODO")
                .frame(width: 60, height: 60)
            Spacer()
            Text(topEntity.given ?? "Unknown Person")
                .frame(minWidth: 60, maxWidth: .infinity, alignment: .leading)
            Spacer()
            VStack {
                Text("elo-rating \(topEntity.elo)")
                Text("avg-time \(topEntity.avg_time ?? "")")
                Text("avg-score \(topEntity.avg_score)")
            }.fixedSize(horizontal: true, vertical: false)
        }.font(.footnote)
    }
}

但是只有平均时间的中间文本被正确本地化:

我也尝试了以下几行但没有成功:

"elo-rating %@" = "Elo rating: %ld";
"elo-rating %ld" = "Elo rating: %ld";
"elo-rating %lld" = "Elo rating: %lld";

它只是不起作用 :-) 请帮我找出我的错误。

【问题讨论】:

标签: ios swift swiftui localization swiftui-text


【解决方案1】:

仅使用%d%d 用于整数类型

"elo-rating %d" = "Elo rating: %d";

对于平均分数,使用%lf

"avg-score %lf" = "Average score: %lf";

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-06-29
    • 2013-09-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多