UPGRADE YOUR SKILLS: Learn advanced Swift and SwiftUI on Hacking with Swift+! >>

SOLVED: Localizable.strings

Forums > SwiftUI

I have some string that show depending on score, however it not showing in the Localizable.strings

resultMessage = NSLocalizedString("Congratulation! You answered all \(numberQuestions) questions correctly. There are \(questionLeft) other questions that are possible. Try again and see if can get another perfect score.", comment: "100%")

"Congratulation! You answered all %lld questions correctly. There are %lld other questions that are possible. Try again and see if can get another perfect score." = "Congratulation! You answered all %lld questions correctly. There are %lld other questions that are possible. Try again and see if can get another perfect score.";
resultMessage = NSLocalizedString("Well done. Your score is \(correctNumber) out of \(numberQuestions) (\(formattedPercent)). You would have passed, however you got a question wrong. Try again as practice makes perfect!", comment: "Pass")

"Well done. Your score is %lld out of %lld (%@). You would have passed, however you got a question wrong. Try again as practice makes perfect!" = "Well done. Your score is %lld out of %lld (%@). You would have passed, however you got a question wrong. Try again as practice makes perfect!";

numberQuestions, correctNumber are Int and formattedPercent is a formated string

What I am doing wrong?

2      

Hi,

this is not how NSLocalizedString is meant to be used. This will look up the Localizable.strings using the provided value as a key. So if you want to have dynamic data, you need to use format strings and have something like: "You answered all the %d questions" in your Localizable file,.

You can then combine String(format: ) init with NSLocalizedString like this:

String(format: NSLocalizedString("You answered all the %d questions", comment: ""), numberQuestions)

2      

Thank you @nemecek-filip, soory for the slow reply as yo reply showed me the current way I was display the Text and had to redo that section of my app. But now got it to work (and translate) correctly.

2      

BUILD THE ULTIMATE PORTFOLIO APP Most Swift tutorials help you solve one specific problem, but in my Ultimate Portfolio App series I show you how to get all the best practices into a single app: architecture, testing, performance, accessibility, localization, project organization, and so much more, all while building a SwiftUI app that works on iOS, macOS and watchOS.

Get it on Hacking with Swift+

Sponsor Hacking with Swift and reach the world's largest Swift community!

Archived topic

This topic has been closed due to inactivity, so you can't reply. Please create a new topic if you need to.

All interactions here are governed by our code of conduct.

 
Unknown user

You are not logged in

Log in or create account
 

Link copied to your pasteboard.