Code inspection: Element is localizable
Category: Potential Code Quality Issues
ID: LocalizableElement
EditorConfig: resharper_localizable_element_highlighting=[error|warning|suggestion|hint|none]
Language: , C#, VB.NET
Requires SWA: No
tip
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.
tip
Even if the string literal is not highlighted by this inspection, you can still move it to the resource file with the Move to Resource refactoring.
As not every string needs to be moved to resources and localized, JetBrains Rider provides several ways to configure this inspection. When the 'Element is localizable' inspection is enabled, it works according to the flow chart below. Each step in the algorithm is explained under the chart.
![JetBrains Rider: How the 'Element is localizable' inspection works JetBrains Rider: How the 'Element is localizable' inspection works](https://resources.jetbrains.com/help/img/rider/2024.3/localizable_inspection_flowchart.png)
The Localizable project property defines how to treat strings in a project. To change this property, right-click the project in the Solution Explorer, select Properties | Inspections, and then choose Localizable > [Default | Yes | No].
If the current project or any other project that it references contains at least one resource file (.resx), JetBrains Rider will consider the project as localizable by default.
Further configuration is possible for specific functions and properties that can consume string values by marking them with
LocalizableAttribute
, which lets you explicitly enable[Localizable(true)]
or disable[Localizable(false)]
the localization inspection on the consumed strings.Note that symbols could be marked with this attribute via external annotations. For example, external annotations are used to mark
Console.WriteLine
with[Localizable(true)]
.The Localizable Inspector project property defines how to treat string literals that are not consumed by any member marked with
LocalizableAttribute
— Optimistic algorithm will ignore such strings, Pessimistic will flag them as localizable.To change this project property, right-click the project in the Solution Explorer, select Properties | Inspections, and then choose Localizable Inspector > [Optimistic | Pessimistic].
The easiest way to disable localization inspection for the current project is to press AltEnter over a highlighted string in the editor and use the corresponding command in the action list:
![JetBrains Rider: Disabling localization inspection for project JetBrains Rider: Disabling localization inspection for project](https://resources.jetbrains.com/help/img/rider/2024.3/Resources__Quick-Fixes_04.png)
This command sets the Localizable property in the current project to No.