Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

NSLocalizedString always returns capitalized text

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:

  1. Ive grep'd all of my .strings files and confirmed there is no
    'QUESTION' in there.

  2. Removed app from Simulator and re-run app

  3. 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

like image 720
Tim Avatar asked Dec 11 '22 05:12

Tim


1 Answers

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:

  1. Edit the scheme
  2. Select the “Run” action and click the “Options” tab
  3. Uncheck the “Show non-localized strings” option

enter image description here

In your case I think that your strings' localization is not working and so they are capitalized because that setting is activated.

like image 94
C. Kontos Avatar answered Dec 30 '22 21:12

C. Kontos