Search code examples
asp.netresx

Use value from resx file in selected language


I have a ASP.NET MVC Website.

I use resources files to translate the website using

@Html.Encode(Resources.MY_STRING)

But in some pages, I would like to display the text in all languages. Is it possible to do it with resx files ?

Here is a example of what I want to do :

@Html.Encode(Resources.MY_STRING, "en-US")
@Html.Encode(Resources.MY_STRING, "fr-FR")

Of course it doesn't like this but is there a way to do it using .resx files ? Or should but these texts in an other configuration file...?


Solution

  • Yes, that is possible. But not as direct as your code.

    CultureInfo userCulture = CultureInfo.CreateSpecificCulture("en-US");
    string myString = HttpContext.GetGlobalResourceObject("MyResource", "MyString", userCulture).ToString();
    

    But maybe you just wanna store all languages for that particular case in one/all resources.