Localization refactorings
ReSharper provides a set of resource-related refactorings that greatly simplify internationalizing your projects.
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.
tip
You can set the naming pattern for the created resources on the Code Editing | Localization page of ReSharper options.
Place the caret at the string that should be localized.
If the string is highlighted by the 'Element is localizable' inspection use the corresponding quick-fix (AltEnter)
Otherwise, press Ctrl0R,0O or choose ReSharper | Refactor | Move… from the main menu.
In the Move to resource dialog 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 field and choose other resource file in the Resource File list.
Optionally, you can change the resource string value in the Value text area and add a comment in the Comment text area.
Optionally, you can specify whether to search for identical strings and the search scope by selecting the value in the Find identical items in list.
By default, when the new resource is created the Localization Manager will open and display the resource.
To disable this behavior, clear the Show the new resource entry in Localization Manager checkbox.
Click Next to apply the refactoring.
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 and the new resource declaration appears in the specified .resx file.
After the new resource is created you can override its value for other cultures.
tip
To find all localizable strings in your solution, set Localizable=Yes and Localizable Inspector=Pessimistic for the relevant projects, then find any such string, which will be highlighted with curly underline. Press AltEnter on it and choose Inspection 'Element is localizable' | Find similar issues....
If your project contains multiple resource .resx files, this refactoring will help you move existing resources from one resource file to another. If there is only one .resx file in the current project, this refactoring is unavailable.
Place the caret at the resource usage in a code file:
or at the resource name in a .resx file:
Press Ctrl0R,0O or choose ReSharper | Refactor | Move… from the main menu. Alternatively, you can press CtrlShift0A, start typing the command name in the popup, and then choose it there.
In the Move resource dialog that appears, specify a target resource file where you want to move the resource.
Optionally, you can change the resource name.
Click Next to apply the refactoring.
You can use the Rename refactoring to quickly rename existing resources. After applying the refactoring, all resource declarations in resource files and all resource usages in code files are updated according to the new name.
Place the caret at the resource usage in a code file:
or at the resource name in a .resx file:
Press Ctrl0R,0R or choose ReSharper | Refactor | Rename… from the main menu. Alternatively, you can press CtrlShift0A, start typing the command name in the popup, and then choose it there.
In the Rename Resource dialog that appears, specify a new name for the resource.
Click Next to apply the refactoring.
The Inline Resource refactoring substitutes resource usages with the original string and optionally deletes the corresponding resource entries from resource files.
tip
If a string literal is too long, press Enter anywhere within the string and ReSharper will automatically put the right part of it to the next line and insert the
+
sign. Delete the+
and the string parts will be concatenated.
Place the caret at the resource usage in a code file:
or at the resource name in a .resx file:
Press Ctrl0R,0I or choose ReSharper | Refactor | Inline | Inline… from the main menu. Alternatively, you can press CtrlShift0A, start typing the command name in the popup, and then choose it there.
In the Inline Resource dialog that appears, specify refactoring options:
Inline all usages: if selected, replaces all resource usages in the project with the original string. If deselected, replaces only the resource usage where you invoked this refactoring. Note that this option works only if you invoked the refactoring from the code file.
Remove inlined resource declaration: if selected, removes resource declaration from all related resource files. If deselected, leaves declarations intact.
Click Next to apply the refactoring.
If you are going to delete a resource, use the Safe Delete refactoring to ensure that the delete operation is safe. If there are no resource usages found, the resource will be deleted right away. Otherwise, ReSharper will show all resource usages, allowing you to edit the corresponding code. Removing usages marked with the icon, will lead to compilation errors.
Place the caret at the resource usage in a code file:
or at the resource name in a .resx file:
Press Ctrl0R,0D or choose ReSharper | Refactor | Safe Delete… from the main menu. Alternatively, you can press CtrlShift0A, start typing the command name in the popup, and then choose it there.
If there are no usages of this resource in code files, the refactoring is applied and resource declarations are removed from all .resx files.
If there are usages of this resource in code files, the Safe Delete Resource dialog opens showing all conflicts.
If you have conflicts trying to safe-delete a resource, resolve them manually and click Refresh.
When all conflicts are resolved and disappear from the dialog, click Next to apply the refactoring.