ReSharper Web Help

ReSharper | Refactor | Move
F6Ctrl+R,O

It is a common practice to store localizable strings in resource files when working on project internalization. ReSharper detects strings to be localized and highlights them, so you can easily find and move such strings from your source code to resource files. ReSharper will declare the corresponding resource entry and replace the string in the code with a resource usage.

Note

There are two algorithms that can be applied when ReSharper searches for localizable strings: Pessimistic and Optimistic. If the Pessimistic algorithm is chosen, ReSharper analyzes all possible elements, except those which have attribute Localizable(false). If the Optimistic algorithm is chosen, ReSharper analyzes only elements with attribute Localizable(true). Depending on these settings, ReSharper highlights strings and enables this quick-fix.

By default, the Optimistic algorithm is selected. To change the algorithm for the project, click Pessimistic in the Localizable Inspector list in the Properties window. To access this window, select the project node in the Solution Explorer, and then choose View | Properties Window on the main menu.

Tip

To find all localizable strings in your solution, set Localizable=Yes and Localizable Inspection=Pessimistic for the relevant projects, then find any such sting, which be highlighted with curly underline. Press Alt+Enter on it and choose Options for Inspection | Find all 'Element is Localizable' issues.

To move string to resource
  1. Place the caret at the string that should be localized.
  2. If a string is highlighted, you can use the corresponding quick-fix. Otherwise, choose ReSharper | Refactor | Move on the main menu or press F6Ctrl+R,O.
    Resources__Refactorings__Move_to_Resource_01
  3. In the Move to resource dialog box that appears, ReSharper automatically generates the name for the resource entry and proposes a resource file. If necessary, you can change the name in the Name text box and choose other resource file in the Resource File drop-down list.
    Resources__Refactorings__Move_to_Resource_02

    Tip

    You can specify the template for resource names in the Localization.

  4. Optionally, you can change the resource string value in the Value text area and add a comment in the Comment text area.
  5. Optionally, you can specify whether to search for identical strings and the search scope by selecting the value in the Find identical items in drop-down list.
  6. Click Next to apply the refactoring.
  7. If you selected the Find identical items in option and ReSharper finds any matching strings defined within the specified scope, you will be able to choose which of these strings should be replaced with usages of the new resource.

After applying the refactoring, specified occurrences of the string are replaced with corresponding resource usages:
Resources__Refactorings__Move_to_Resource_03
and the new resource declaration appears in the specified .resx file:
Resources__Refactorings__Move_to_Resource_04

Note

ReSharper provides the same functionality for ValidationAttribute and its inheritors. Pay attention, that access modifier in the .resx file should be Public, otherwise, the refactoring will not be available.

After the new resource is created you can override its value for other cultures. For more information, see Override Resource Entry.


This feature is supported in the following languages/technologies:

C# VB.NET HTML ASPX Razor JavaScript TypeScript CSS XML XAML RESX Build Scripts
feature_available feature_available feature_available feature_available feature_available

Tip

The instructions and examples given here address the use of the feature in C#. For details specific to other languages, see the corresponding topics in the ReSharper by Language section.