Localization inspections and quick-fixes
JetBrains Rider provides a number of code inspections that help you localize your application by detecting localizable strings, problems with resources and so on, 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, JetBrains Rider provides a number of resource-specific quick-fixes.
'Element is localizable' inspection
This inspection detects hard-coded string literals and suggests moving them to resource files. If the same string is already defined in resources, JetBrains Rider will suggest replacing the literal with the existing resource entry.
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:
This 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, JetBrains Rider displays the corresponding action indicator on the left of your caret. You can press Alt+Enter or click the indicator icon to see the list of available actions, To apply a desired action, click 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.
Use resource entry instead of literal
If JetBrains Rider detects that some string literal is already defined in resources, it suggests to replace the string with the corresponding resource usage:
After applying this quick-fix, the string is replaced with the resource usage.
Declare resource entry
If there are several cultures organised in a culture hierarchy, and there is a resource entry that is declared in a culture-specific resource file but is not declared in the default culture, JetBrains Rider highlights the resource declaration and suggests the corresponding quick-fix:
After applying the quick-fix, resource declaration is inserted into the default 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, which is declared in the default culture but is not overridden in one or more other cultures, JetBrains Rider highlights the name of resource and suggests the corresponding quick-fix(es):
After applying the quick-fix, resource declaration(s) is inserted into the culture-specific resource file(s) where you can specify correct values.
Remove resource entry
JetBrains Rider 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 default culture.
After applying the quick-fix, resource declaration is removed from the current resource file.
Remove redundant resource entry type
Specifying the string type for a resource entry is redundant because it is the default resource entry type. JetBrains Rider will suggest removing the redundant attribute:
Safe delete
If there are several cultures organised in the culture hierarchy and there is a resource entry, which is declared in the default culture but is not overridden in culture-specific resource files, JetBrains Rider highlights the name of the resource suggests this quick-fix:
After applying this quick-fix, follow the steps of the Safe Delete Resource refactoring.