0

i have a web form and i want to change its titles for each control with the language thats chosen by a dropdown.

but i couldnt do it. I messed with json and complicated things.

here what i tried:

controller

string newstr = db.Countries.Where(c => c.CountryTag.Contains(incoming)).Select(c => c.CountryTag).First().ToString();
System.Globalization.CultureInfo ci = new System.Globalization.CultureInfo(newstr, false);
Resources.Global.Culture = ci;

view

<script type="text/javascript" language="javascript">
    function changeLang(chosen) {
        var lang = $("#Language").val();
        $.getJSON('@Url.Content("~/Home/Globalx/")', { incoming: lang }, function (data) {
            location.reload(false);
            $("#Language").options.selectedIndex = data;
        })
    }
</script>

<div>
    @Html.DropDownList("Language", (SelectList)ViewData["Language"], new { onchange = "changeLang(this)" })
</div>
<div>
     @Resources.Global.Wellcome
</div>

but it doesnt works. Im using resources as you can see in the code..

I just want to see the changed language on my page whenever i choose another language from my dropdown.

Like while using win forms System.Threading.Thread.CurrentThread.CurrentCulture = MyChosenCulture; in a DropDown_Change event bla bla.. but in web version.

so how can i achive this?

Berker Yüceer
  • 7,026
  • 18
  • 68
  • 102

1 Answers1

2

The process is actually the same as what you mention for WinForms, but you were looking at the wrong property (CurrentCulture is about formatting and parsing, it's CurrentUICulture that you need to make ResourceManager use a specific language version of your resources). So you can achieve your goal by replacing this line:

Resources.Global.Culture = ci;

With this one:

Thread.CurrentThread.CurrentUICulture = ci;
Clafou
  • 15,250
  • 7
  • 58
  • 89