We help IT Professionals succeed at work.

C# tool that replace hard coded strings, but leave the English version inside code.

dvplayltd asked
Dear experts,

I have a C# WinForm application that I should localize /replace hard coded string in extra file that could be translated by other person/. As the project is huge I’m searching a tool that to modify code automatically. And there is a major requirement – I want the English text to be leaved inside the code, because this is complicated messages and I want to see them when I testing application inside C# IDE.

Or what other approach I can use to localize, but to see the EN messages in VS 2008 even when application is not started?

Other is – most of my messages are with parameters inside them, for example this is a message in MessageBox “The operation you are about to start will affect “ + iCount + “ records”

Which tool you could recommended me? To do all work, or at least some part of work - the hard coded strings are may be 5000 ...
Watch Question

Freelance programmer / Consultant
I think the following is the ONLY tool available for this task:  The human eye


To AndyAinscow

I'm almost start searching the tool you recomended, then after few seconds I got that I already have this tool :-) jejeje :-)

Ok, then a tool which to do some part? Like to do repleacment with asking and to put the old En string in comment for example?
AndyAinscowFreelance programmer / Consultant

>>Ok, then a tool which to do some part? Like to do repleacment with asking and to put the old En string in comment for example?

As far as I know there isn't any such tool to automate things.  You have to do it the hard way when you use hard coded strings.
(Ctrl + F can be used to search so that might help track some things down, eg search for "a  then for "b ....)


To Andy

I use a lot of global search in all files at once with Ctrl + Shift + F / H so I know that.

I see there are many tools offering to replace hard - coded strings with resource file, is there a tool that at least ask me and one by one confirm to do that?  Then I can manually put old hard strings in comment. This is actually 50% manual, but still better that 100% manually .
Top Expert 2015
There is no tool that can do that, simply because there are strings in code that are not use for display, but for other purposes, such as comparisons, conditions, etc. No tool would be "intelligent" enough to be able to understand what a string is used for. Thus any tool would break the application by changing things that do not need to be changed.

The best solution, in my opinion, is what has been suggested: mark the lines that could be hard to understand with a comment.

For the purpose of integrating data or variable values in your strings, you can use a little know feature of String.Format.

Define you message with in only one resource:

“The operation you are about to start will affect {0} records”

Then display it with the following:

String.Format(<yourResource>,iCount)  //The operation you are about to start will affect {0} records

The {0} is a marker that will be replaced by the value of the second parameter to Format.

You can have more than one marker:

“The operation you are about to start will affect {0} records, starting at {1} and ending at {2}.”
AndyAinscowFreelance programmer / Consultant

I didn't recommend or mention using the find AND replace, I just suggested the inbuilt find functionality.

Letting any automated system do what you want (and I include the inbuilt find/replace in that) is really playing with fire.  Just one mistake and it could give you more work to repair things than doing everything yourself would have done.

Imagine in your code you have a field 'Booking Date' (database records) which gets changed to eg. 'Buchungsdatum'.  Your code will compile but then crash (or even worse - it doesn't crash but ignores it because of the clever error handling mechanism you have implemented) when in use.


To Jacques

Well, I know this style with Format, it not work fine for me. My messages usually are long 2-3 lines, with 2-5 options via radio buttons, so with format function or not they will not look more readable for coder  And when we are talking for 5000+ messages this extra “{0}” add extra size to my .exe which is every day disctibute via Internet to many PCs …


To Andy
Usually I start my questions with that I’m in coding business  18+ years, but this time I miss.
You are experience user, that is why I try to save some more explanation.

I know what the hard coded strings are, 50% of work I mean a tool that will show me one by one line that will make replace of string with resource, then with 1 click I ‘ll do it or leave it as it is and go on next. This is MUCH more faster than when I locate the position to do manually copy / paste …

Outside the question, often I start Replace ALL at once via all files, but make sure that the string are 100% specify. This is done primary for spelling mistake in messages, it is clear that for code this is not so much useful.


I didn't het answer actually, but thanks for your time.