Search code examples
iosswiftswiftuilocalizationswiftui-text

Localizable.strings works for String, but not for Double and Integer 32


As a Swift newbie I am trying to localize a simple SwiftUI and Core Data project at Github:

screenshot

I have added the following en.lproj/Localizable.strings file to my project:

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

And in my custom SwiftUI View TopRow.swift I am trying to use the above 3 keys:

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)
    }
}

However only the middle Text with average time is localized properly:

emulator

I have also tried the following lines with no success:

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

It just does not work :-) Please help me to find my error.


Solution

  • Use only %d. %d is for an integer type

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

    For Average score, Use %lf.

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