I need to move all the hard coded strings in my source code in .resx files. Is there a tool that could help me find all the hardcoded strings within C# code?
-
Check my answer here: http://stackoverflow.com/questions/29533905/how-to-find-all-the-hardcoded-values-in-a-c-sharp-projectsolution – Simon Mourier Nov 22 '15 at 17:57
6 Answers
ReSharper 5 is obvious a choice, but many tips must be set so as to achieve your goals,
- Turn on solution wide analysis.
- Go to
ReSharper
|Options
|Code Inspection
|Inspection Severity
|Potential Code Quality Issues
|Element is localizable
set toShow as error
. - Go back to Solution Explorer and click on the project (csproj).
- In Properties panel under ReSharper category, set Localizable to Yes, Localizable Inspector to Pessimistic.
Then you can find almost all you need in Errors in Solution panel.
Hope this helps.

- 8,193
- 4
- 46
- 62

- 60,503
- 9
- 116
- 147
-
1Does this also work for XAML files? R# does not seem to see the Content/Text properties in XAML, only in the code behind? – Rodney Dec 07 '10 at 22:55
-
1
-
Thank you, Lex Li. I found this regular expression to find all potential localizable strings in xaml files http://devnet.jetbrains.com/thread/304983;jsessionid=1C2641DA7F7C3DAD0EFA85EDAA2A8798. One this that is missing in that regular expression is searching for Label attributes. – Rami A. Mar 15 '13 at 19:43
-
For me it does not work - many strings remain unmarked even in one cs file whereas other are marked ok. – Vojtěch Dohnal Feb 27 '15 at 11:23
-
@VojtěchDohnal, the ReSharper approach is only best effort, as it relies on the ReSharper engine, which might not be 100% correct all the time. Of course, you can report such issues to JetBrains and hope they can fix. – Lex Li Feb 28 '15 at 13:30
-
@LexLi localization isn't working with consts how can I configure it to do so? – johnny 5 May 17 '17 at 19:02
-
Unfortunately, this doesn't work with strings in attribute's parameters. – Andrii Viazovskyi Oct 21 '19 at 11:40
Or do a search based upon a regular expression like discussed here:
(?=(^((?!///).)*$)).*((".+?")|('.+?')).*

- 1,219
- 15
- 24
-
1Very good answer! Also, if somebody doesn't know how to use it: press 'Ctrl + F', then write regular expression into standard search text box, then press 'Alt + E', then search as usual. – Andrii Viazovskyi Oct 21 '19 at 11:48
This tool http://visuallocalizer.codeplex.com/ allows for batch-move strings to resources, together with other features. It is FOSS so maybe you can give it a try. (I am involved)

- 1,091
- 1
- 13
- 27
You could always do a search for the "
sign in all the .cs files. That should get you to most of them, without too much noise.

- 128,221
- 31
- 203
- 222
-
2Well, this is a bit of brute force becase of comments for example. Still I would recommend pairing it with assignment operator to narrow the searches - or use additional filtering - thank got there's linq:) . Use some powershell script or write a simple cs program to make is for you. Generally making a reg expression to find all – luckyluke Mar 22 '10 at 09:19
Resharper 5.0 (Beta) allows you to move strings to resources (it has built in Localization feature). Give it a try. Beta works fine, i use it every day and have no problems. Best of all it's free until out of beta. I even recommend using night builds as they seem to be stable.
Software localization and globalization have always been tough and at times unwanted tasks for developers. ReSharper 5 greatly simplifies working with resources by providing a full stack of features for resx files and resource usages in C# and VB.NET code, as well as in ASP.NET and XAML markup.
Dedicated features include Move string to resource, Find usages of resource and other navigation actions. Combined with refactoring support, inspections and fixes, you get a convenient localization environment.
-
Good heads-up, but I don't think it helps you find them in the first place, which is what the question is mainly asking. – rohancragg Mar 22 '10 at 09:32
Some are found by FxCop. Not sure what its limits are, I think it depends on parameter and property names (eg: a property called "Text" is considered to be localized).

- 63,782
- 15
- 129
- 193