ReSharper 2024.3 Help

Quickly internationalize a .NET application

Let’s say you want to quickly add multi-language support to your app, but don’t want to start messing with RESX files. Indeed, there is an easier way. Given the following code:

try { double tax = CalculateTax(); } catch (TaxException e) { MessageBox.Show("Cannot calculate tax"); }

To move the string into a resource, move the caret over the string, open up the Refactor This menu Control+Shift+R and choose Move to Resource:

Applying the 'Move to Resource' refactoring

Now, if you don’t have a resource file, ReSharper will warn you about it:

Applying the 'Move to Resource' refactoring

Making one is easy, though:

Applying the 'Move to Resource' refactoring

And now if you try to move a string to a resource, ReSharper will notice the newly created RESX file and offer to put the string into it:

Applying the 'Move to Resource' refactoring

Once you accept the above settings, the string will be moved to the resource file:

<data name="Tax_Main_Cannot_calculate_tax" xml:space="preserve"> <value>Cannot calculate tax</value> </data>

And, of course, your code will be changed to use the resource string:

try { double tax = CalculateTax(); } catch (TaxException e) { MessageBox.Show(Resource1.Tax_Main_Cannot_calculate_tax); }
Last modified: 11 February 2024