Ive run into an issue where NSLocalizedString is always returning strings capitalized regardless of its input. localization was working and Im assuming I did something that caused this but I cannot seem to figure out exactly what changed.
Here's my code:
func localize(_ str: String) -> String {
print("str in: \(str)")
return NSLocalizedString(str, comment: "")
}
I call it like this:
let txt = self.localize("Question")
print("txt = \(txt)")
Output:
str in: Question
txt = QUESTION
Things Ive tried:
Ive grep'd all of my .strings files and confirmed there is no
'QUESTION' in there.
Removed app from Simulator and re-run app
Changed incoming string to something that doesn't exist in any file such as 'randomxxyxxy'
Ive tried searching for quite a while on this issue and wasn't able to find anything that was like this problem.
Any help is appreciated, Thank you
When your app is trying to localize a string but cannot find the translated text for it then it will show it in capitals. This is done to show you that the capitalized text is not localized. You can disable the capitalization of those cases by disabling the option: Show not-localized strings
This is how you do that:
- Edit the scheme
- Select the “Run” action and click the “Options” tab
- Uncheck the “Show non-localized strings” option
In your case I think that your strings' localization is not working and so they are capitalized because that setting is activated.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With