Title: Localizable.strings not working inside a List
Tags: swift;list;swiftui;localization;localizable.strings
Question: 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(&quot;game-number #\(gameNumber)&quot;)
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:
&quot;app-title&quot; = &quot;Wähle ein Spiel!&quot;;
&quot;update-games&quot; = &quot;Spiele erneuern&quot;;
&quot;join-random-game&quot; = &quot;Zufallsspiel beitreten&quot;;
&quot;game-number #%d&quot; = &quot;Spiel #%d&quot;;
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:
Replaced %d by %lld
Removed the # char on both sides
Replaced game-number by just game
Tried to use Text(LocalizedStringKey(&quot;game-number #\(gameNumber)&quot;))
Tried to use Text(String(format: NSLocalizedString(&quot;game-number #%d&quot;, comment: &quot;&quot;), gameNumber)) - always shows the EN string &quot;Game #...&quot;
Nothing has helped, what could be wrong here please?
UPDATE:
I have received nice suggestions at the Hacking with Swift forum.
Comment: @Larme please take a look at my updated question! I have added a simple test project to it, to demo my problem. Unfortunately `Text(LocalizedStringKey("game-number #\(gameNumber)"))` does not help there either.

Comment: Not really localized, unfortunately - your suggestion `Text(String(format: NSLocalizedString("game-number #%d", comment: ""), gameNumber))` only displays the English string "Game" for me. Regardless of the language I select in the Menu.

Comment: Use verbatim or LocalizedStringKey? Or are you saying that the other ones with a placeholder (and so a variable) works too? See https://developer.apple.com/documentation/swiftui/text

Comment: And `Text(LocalizedStringKey("game-number #\(gameModel.gid)"))` it doesn't fork either?

Comment: I'm not a SwiftUI user, so... But `Text(String(format: NSLocalizedString("game-number #%d", comment: ""), gameNumber))` seems to work... I don't know why though...

Here is the accepted answer: 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(&quot;game-number #\(String(gameNumber))&quot;)  // << here !!
with combination in .strings
&quot;game-number #%@&quot; = &quot;Game #%@&quot;;
&quot;game-number #%@&quot; = &quot;Spiel #%@&quot;;
&quot;game-number #%@&quot; = &quot;Игра #%@&quot;;
Tested with Xcode 13 / iOS 15


{'source': 'StackExchangeDataset', 'subset': 'stackoverflow.com', 'metadata': {'AnswerCount': 1, 'CommentCount': 5, 'ContentLicense': 'CC BY-SA 4.0', 'CreationDate': '2021:00:11/13/21', 'FavoriteCount': 1.0, 'PostTypeId': 1, 'Tags': '<swift><list><swiftui><localization><localizable.strings>', 'Title': 'Localizable.strings not working inside a List', 'ViewCount': 196, 'id': 69958449, 'user_AboutMe': '<ul>\n<li>I am experienced in many technical areas and programming languages.</li>\n<li>I like writing efficient, easy to read code.</li>\n<li>I am a friendly person  even in heated discussions or stressful work situations.</li>\n</ul>\n', 'user_AccountId': 55135.0, 'user_DisplayName': 'Alexander Farber', 'user_Reputation': 20059.0, 'user_Views': 5749.0, 'user_id': 165071.0}}