Mám tento problém s lokalizovanými reťazcami rozhrania:
var friendsNumber = 3
var firstString = NSLocalizedString("I have 3 friends.", comment: "") // the translation works good
var secondString = NSLocalizedString("I have (friendsNumber) friends.", comment: "") // the translation doesn’t work
Ako to môžem urobiť?
odpovede:
0 pre odpoveď č. 1V druhom prípade potrebujete formátovací reťazec.
var messageFormat = NSLocalizedString("I have %d friends.", comment: "")
var message = String(format: messageFormat, friendsNumber)
Potom v reťazcovom súbore skončíte s:
Angličtina:
"I have %d friends" = "I have %d friends";
španielsky:
"I have %d friends" = "Tengo %d amigos";
atď.