Search code examples
.netvb.netresharperresxlocalizable.strings

Cannot resolve resource item


I have a VB.NET project where I have a form (frmRun) and am using several resource files for different languages (i.e. English.resx, Portuguese.resx, etc.) In my code I have included the namespace for System.Resources and defined a resource manager as follows:

Private rm As ResourceManager

On startup or when a user selects a language from a menu, I set the resource manager:

 rm = New ResourceManager("MyRootNamespace." & currentItem.Text, System.Reflection.Assembly.GetExecutingAssembly())

where currentItem.Text is "English.resx", etc. Since rm is defined at the class level I can now easily choose the string I want to show for the selected language as such:

btnStartStop.Text = rm.GetString("btnStartStop_Start")

This resource string "btnStartStop_Start" is defined in both English.resx (in English) and in Portuguese.resx (in Portuguese).

I'm using JetBrains Resharper and the issue is that the IDE is showing errors in the vertical scrollbar for every line where I use the rm.GetString saying it can't resolve them. If I click on the lightbulb in the left column of the IDE, it tells me I can fix this by adding this to resource item. When I do, it's adding it to the forms resx file. In this case this string goes into "frmRun.resx" and the error goes away. But I'm not using frmRun.resx, I'm specifically telling it to use a different resx file (English.resx, etc.) Interestingly even though these show as errors in the vertical scollbar of my IDE, they are not compile errors and the app compiles/runs okay.

How can I make it ignore looking for these resources in the forms resx file besides telling it to hide/not show these via the inspection?


Solution

  • Your resource file should be the same name but with a language suffix.

    For example

    WinFormStrings.de-DE.resx for German

    WinFormStrings.fr-FR.resx for French

    The default will use the WinFormStrings.resx file.

    Calls to .GetString will then pick out the correct file based on the current thread culture

    A walkthrough that explains this can be found here: Walkthrough: Localizing Windows Forms