Using Resharper to detect localizable strings

A few months I had to estimate how much time/effort was involved in localizing one .NET application. As part of this task I had to search for all the hard-coded strings in the source code that should be localizable, which is a tedious and very time-consuming task.

The good thing is that Resharper has good localization support which can save you many hours or even days of work – imagine having to go through all files and search for the strings manually! In this post I’ll show you how you can use Resharper to detect localizable strings and how you can enable or disable localization for a particular project, class, method or even an individual string.


Configuring localization inspection

If you want ReSharper to find and highlight strings that are localizable you must enable the localization features for each project – just select the project in the Solution Explorer, press F4 and ensure that the Localizable property has the value Yes:

01 enable localization support

Setting the Localizable Inspector property to Pessimistic means that all possible elements will be analyzed.


Finding localization issues

After configuring the projects in the solution you can now start searching for localization issues by right-clicking the solution file and select Find Code Issues. In the Inspection Results go to Potential Code Quality Issues > Element is localizable to see the results:

02 inspection results

Double-click any item to navigate to the source code:

03 string highlight

Resharper will highlight all hard-coded strings but usually there are many that should not be localized. Below you can see how to disable localization for a class, method or a string.


Setting classes or methods as localizable

You can use the [Localizable] attribute to specify if a class should be localized as or not:

04 class

The same applies to methods:

05 method

Please note that you can mark a class a localizable and one or more methods of that class as non-localizable.


Setting individual strings as non-localizable

One way to mark a string as non-localizable is to convert it to a verbatim string:

07 string1

As you can see the string is now being ignored by Resharper:

08 verbatim string

Constants are ignored as well:

09 const string

That’s it! Even though there is some manual work involved a good tool like Resharper can make your life much easier. I do recommend spending some time to learn how to use this kind of tools, you never know when you might need them!

Happy coding đŸ™‚


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.