Search code examples
c#asp.netlocalizationglobalization

Using variables with localization


 MyResources.LocalizedText.Option1

I'm using localization on one of my web pages. As an example, when I want to display a text based on the page culture, I use the above code.

So far so good. Now I want to get the localizedText based on a variable as follows:

var option = "Option1",
MyResources.LocalizedText. //here I want to have the value of the variable option (which in this case is Option1).

How can I do that?

Thanks


Solution

  • Try

    MyResources.LocalizedText.ResourceManager.GetString(option, MyResources.LocalizedText.Culture)
    

    or

    MyResources.LocalizedText.ResourceManager.GetString(option)
    

    See here for description of .GetString method.