To demonstrate my SwiftUI localization problem I have prepared a simple test project at Github:
It displays a list of games in the ContentView.swift:
List($vm.currentGames, id: \.self) { $gameNumber in
NavigationLink(
destination: GameView(gameNumber: gameNumber)
) {
Text("game-number #\(gameNumber)")
}
}
which is coming from the GamesViewModel.swift:
class GamesViewModel: ObservableObject /*, WebSocketDelegate */ {
@Published var currentGames: [Int] = [20, 30]
@Published var displayedGame: Int = 0
And for localization in DE, EN, RU I have added Localizable.strings:
"app-title" = "Wähle ein Spiel!";
"update-games" = "Spiele erneuern";
"join-random-game" = "Zufallsspiel beitreten";
"game-number #%d" = "Spiel #%d";
While the top 3 entries work well (you can see them as app title and the 2 button labels in the screenshot above), the last entry does not work (shown by the red arrow in the screenshot),
I have unsuccessfully tried many things:
%d
by %lld
#
char on both sidesgame-number
by just game
Text(LocalizedStringKey("game-number #\(gameNumber)"))
Text(String(format: NSLocalizedString("game-number #%d", comment: ""), gameNumber))
- always shows the EN string "Game #..."Nothing has helped, what could be wrong here please?
UPDATE:
I have received nice suggestions at the Hacking with Swift forum.
Probably there is a bug for number formats, at least below works for strings.
List($vm.currentGames, id: \.self) { $gameNumber in
NavigationLink(
destination: GameView(gameNumber: gameNumber)
) {
Text("game-number #\(String(gameNumber))") // << here !!
}
}
with combination in .strings
"game-number #%@" = "Game #%@";
"game-number #%@" = "Spiel #%@";
"game-number #%@" = "Игра #%@";
Tested with Xcode 13 / iOS 15