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.

Abhimuralidharan
3 min readJul 25, 2017
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 .

Edit scheme
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):

calculatorDisplay.text = NSLocalizedString(“Some localized string”, comment: “”)

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.

Localizable strings in storyboard:

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:

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

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.

“GsZ-Y5–7R1.normalTitle" = "Localized title for button";

Done!!!!!

Conclusion:

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!!

If you enjoyed reading this post, please share and recommend it so others can find it 💚💚💚💚💚💚 !!!!

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!

--

--

Abhimuralidharan
Abhimuralidharan

Written by Abhimuralidharan

iOS and tvOS developer, dreamer, photographer 🤨

Responses (4)