Finding non NSLocalized strings in Xcode 8 in swift 3 or ObjC

pinMadHon
3 min readMay 22, 2017

Localization is a process in which we move all our strings that are getting displayed at one place, so if there is any change say, “Ok” button will now be shown as “Okay” then we just need to make changes in one file only. This process can also be your first step in enabling your app to support for multiple languages, so that the display language of strings can be changed at run time. If the user is comfortable with (say) French, then the user must see all content in French. To achieve this you should maintain a string file which has all hard-coded strings that is in the code-base.

We all know, working with a lot of developers simultaneously, can lead to mishandling of strings, which can further lead to a mixture of localized and non-localized strings in the code-base.

Suppose a new requirement comes which says to have support for multiple languages in your app. This could be your biggest nightmare, knowing that your app is not ready for it because we never cared for strings. What will be your next step? You would want to know the strings that are not localized as quickly as you can, so you can plan to localize them. Is searching for NSLocalizedString in codebase and comparing each string in .strings file the only option left for you?

Well, Xcode has provided a neat and a very simple way to achieve that, which is possible with just a change in schema setting in Xcode.

#warning : If you have never done NSLocalization of any of your strings then you must first do it. Then worry about having it in localized (.string) file.

Please note, this solution works for code like this :

label.text = NSLocalizedString(“some string”, comment: “”)

or

label.text = NSLocalizedString(anyVariableName, comment: “”)

not this :

label.text = “some string”

This is how your schema looks like :

You can follow below steps :

  • Click the target in the Run destination menu and choose “Edit Scheme”.
  • On the right, select Options.
  • Select the “Show non-localized strings” checkbox.
  • Click the Close button.
  • Click Run to launch your app in this mode.

Alternatively,

Add the NSShowNonLocalizedStrings launch argument.

  • Click the target in the Run destination menu and choose Edit Scheme.
  • On the right, select Arguments
  • Add “-NSShowNonLocalizedStrings YES” into “Arguments Passed On Launch”.
  • Click the Close button.
  • Click Run to launch your app in this mode.

How does it work:

Enabling this setting in Xcode it,

  • Searches for NSLocalizedString at run time.
  • Looks for corresponding entry of key in strings file.
  • And if any match is not found it shows the text in uppercase on UI and prints an error message on console.

This kind of error will be shown :

Localizable string “Key” not found in strings table “Localizable” of bundle CFBundle

--

--