Search code examples
c#winformsresharperlocalizable.strings

Localizable string warning R#


I'm a beginner in c# syntax, been programming in vb.net for quite a few years.

ToolStripMenuItem setPriorityDropdown = new ToolStripMenuItem {Text = "Set priority"};

In this code, R# warns that "Set priority" is a localizable string. I've searched online and found that to remove the warning you should use @ before the string, becoming @"Set priority", however for this case, R# continues to tell me it's localizable.

I couldn't get a proper answer of why a string shouldn't be localizable, and why R# warns about it with (at "first" glance) no option to turn it off. Why

setPriorityDropdown.DropDownItems.Add("Priority 1"... 

doesn't get the warning?

What's wrong about the first one? How can i fix it?


Solution

  • Check the answer to this question for the solution. Your R# setting is set to ignore verbatim strings and still report them as localizable. This means that R# wants you to move the "magic" string to a resource file that helps with language localization. This is so that if you wanted to deploy your application in a different language, you could easily define the translations in the resource files instead of searching through the entire code base. In reference to why using the object initializer syntax throws the error and not the Add() method, I am not sure. It could be that R# is complaining about another problem instead, like preferring that you use the object initializer syntax.