ReSharper 2016.2 Help

Localization Inspections and quick-fixes

ReSharper provides a number of code inspections that help you localize your application by detecting localizable strings, problems with resources etc. in resource files and resource usages in code files. These inspections detect localization issues in design time in the open documents and allow you to find localization issues in specific scope up to the entire solution.

In design time, detected issues are highlighted to draw your attention. To resolve the highlighted issues, ReSharper provides a number of resource-specific quick-fixes.

Configuring localization inspection

By default, localization inspections are enabled in a project if the project contains at least one resource file.

One way of adjusting localization inspection is to change severity of specific inspections. You can find localization inspections (e.g.Element is localizable) in the Potential Code Quality Issues category on the Code Inspection | Inspection Severity page of ReSharper options.

You can also configure localization inspections per project.

To configure localization inspection in project

  1. Select the desited project in the Solution Explorer.
  2. In the Visual Studio menu, choose View | Properties Window or press F4.
  3. In the Visual Studio's Properties window, switch to the Categorized view and expand the ReSharper category.
  4. Select the desired value in the Localizable option. If the Default value is selected, the inspection is only performed if there is at least one resource file in the project. THe Yes and No values allow to enable/disable this inspection explicitly.
  5. Select the desired value in the Localizable inspector option. If the Pessimistic algorithm is chosen, ReSharper looks for localizable strings in all 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 defines whether a specific string is localizable, highlights localizable strings and enables the corresponding quick-fix.

The easiest way to disable localization inspection for the current project is to press Alt+Enter over a highlighted string in the editor and use the corresponding command in the action list:

Disabling localization inspection for project

This command command sets the Localizable property in the current project to No.

Quick-fixes for localization issues

If a quick-fix is available for a code issue detected with localization inspection, ReSharper displays the corresponding action indicator on the left of your caret. You can press Alt+Enter or click on the indicator icon to see the list of available actions, To apply a desired action, click on it or select it in the list and press Enter.

Here are some quick-fixes for localization inspections:

Move to resource

This quick-fix invokes Move to Resource Refactoring to move localizable string to a resource file. It is available when a string is highlighted with a curly underline.

Resources__Quick-Fixes_05
After applying this quick-fix, follow the steps of the Move to Resource Refactoring.

Use resource entry instead of literal

If ReSharper detects that some literal string is defined in resources, it suggests you to replace the string with the resource usage:

Resources__Quick-Fixes_15

After applying this quick-fix, the string is replaced with the resource usage.

Annotate type with 'Localizable(false)'

This group of quick-fixes sets false value to the Localizable attribute of the selected type.

Create resource file

If a resource file name is used in a code file, but you haven't created the resource file yet, ReSharper can do it for you. It highlights the resource file name in red and suggests the corresponding quick-fix:

Resources__Quick-Fixes_07
After applying the quick-fix, the missing resource file is created.

Create resource item

If a resource name is used in a code file, but you haven't declared this resource yet, ReSharper can do it for you. It highlights the resource name in red and suggests the corresponding quick-fix:

Resources__Quick-Fixes_08
After applying the quick-fix, the missing resource declaration is added in the resource file.

Declare resource entry

If there are several cultures organised in the culture hierarchy and there is a resource entry that is declared in a culture-specific resource file, but is not declared in the neutral culture, ReSharper highlights the resource declaration with fading and suggests the corresponding quick-fix:

ReSharper helps declare resource entry in the default culture
After applying the quick-fix, resource declaration is inserted into the neutral culture where you can replace its value with a new one.

Override resource entry

If there are several cultures organised in the culture hierarchy and there is a resource entry that is declared in the neutral culture, but is not overridden in one or more existing specific culture, ReSharper highlights the name of resource and suggests the corresponding quick-fix:

Resources__Quick-Fixes_09
After applying the quick-fix, resource declaration is inserted into the culture-specific resource file where you can replace its value with a new one.

Remove resource entry

ReSharper suggests this quick-fix in the following cases:

  • A resource entry has equal values in neutral and specific cultures;
  • There are two or more declarations with the same resource name;
  • There are several cultures organised in the culture hierarchy and there is resource entry that is declared in specific culture, but is not declared in neutral culture.
Resources__Quick-Fixes_03
After applying the quick-fix, resource declaration is removed from the current resource file.

Remove redundant type

According to the ReSharper analysis, specifying the string type for resource entry is redundant because it is the default resource entry type. ReSharper highlights attribute and its value with fading and suggests the quick-fix:

Resources__Quick-Fixes_06
After applying the quick-fix, the attribute and its value are removed from resource declaration.

Safe delete

If there are several cultures organised in the culture hierarchy and there is a resource entry that is declared in the neutral culture, but is not overridden in a culture-specific resource file, ReSharper highlights the name of the resource suggests this quick-fix:

Resources__Quick-Fixes_10
After applying this quick-fix, follow the steps of the Safe Delete Resource Refactoring.

See Also

Last modified: 15 December 2016