Finding Non-localized Strings in xcode

If you have ever done some localization in xcode, you might already know how hard is it to track the non-localized strings used in the code and in storyboard. From xcode 7, there is an easy way to do that. Let me show you that.

Image for post
Image for post
https://stocksnao.io

I am not going to explain how to do localization in iOS in this article.

Rushing through the basics, we can do localize the string in two ways.

  • In code by using NSLocalizedString("someStringToLocalize", tableName: nil, bundle: Bundle.main, value: "", comment: "") .
  • Use storyboard localizations.

It’s common that we add the NSLocalizedString(: method in the code and to forget to add it in the Localizable.strings file. Also, we might localize the storyboard file and will add a new label later on in the UI which you will forget to add in the localized storyboard strings file.

To track these kind of silly mistakes, xcode 7 and above provides an option.

In the scheme editor take a look at the Options tab. In the following screenshot I have “Show non-localized strings” enabled .

Image for post
Image for post
Edit scheme
Image for post
Image for post
scheme editor

Show non-localized strings checkbox needs to be checked and we can select the application language as required. Then compile and run the app.

I have added a string as a label’s text (calculatorDisplay is a UILabel):

Also, the string “Some localized string” is not added in the Localizable.strings file. In this scenario, it will throw an error in the debugger.

Image for post
Image for post
Image for post
Image for post
Storyboard strings file

For the localizable strings in storyboard which are not added in the <YOUR_STORYBOARD_NAME>.strings(YOUR_LANGUAGE) file, the debugger will throw error like:

Image for post
Image for post
error for storyboard objects

Let’s check the first error:

  • Copy GsZ-Y5–7R1 mentioned in the error and search for it throughout the project.
Image for post
Image for post
searching storyboard object

It appears to be a UIButton’s Object ID and the localizable text is the UIButtons title . Click on the search result and it may highlight the object in storyboard.

The storyboard strings file normally looks like this:

Image for post
Image for post
storyboard strings file

Where , GsZ-Y5–7R1 is the objectid of a UIButton. Now copy the GsZ-Y5–7R1.normalTitle and add it to the strings file.

Done!!!!!

How to localize the strings file and localizing the storyboard files are not covered in this article. This process is pretty easy. I am planning to create an article on localization and internationlization in the near future.

Hope you learned something new today.

Note: Fabrizio Bernasconi mentioned a website to generate the localizable strings file. Just give it a try.

Generate Localizable.strings from XCode project:

http://xcode.fabriziobernasconi.it

Enjoy!!

You can follow me on Medium for fresh articles. Also, connect with me on LinkedIn.

If you have any comment, question, or recommendation, feel free to post them in the comment section below!

Written by

iOS and tvOS developer, dreamer, photographer 🤨

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store