I have a jquery function that detects changing items from dropdown List I want to change the CurrentCulture using jquery in order to change LocalizatedValue in .net core , that's the jquery method containing my trial version
$('#dropdownList li').find("a").click(function () {
$('#dropdown-button').html($(this).html());
$("#dropdown-button").val($(this).text());
if (document.getElementById('dropdown-button').innerText === "Arab") {
Globalization.locale("ar")
} else if (document.getElementById('dropdown-button').innerText === "French") {
Globalization.locale("fr")
} else if (document.getElementById('dropdown-button').innerText === "English") {
Globalization.locale("en")
}
});
});
and there where I need the Current Culture Info in cs code
private string GetString(string name)
{
var query = localization.Where(l => l.LocalizedValue.Keys.Any(lv => lv == CultureInfo.CurrentCulture.Name));
var value = query.FirstOrDefault(l => l.Key == name);
return value.LocalizedValue[CultureInfo.CurrentCulture.Name];
}
Here is a working demo based on the official docs:
1.Create
SharedResource.csin the root project:2.Create
SharedResource.fr.resxinResourcesfolder to add the resources.Resourcesfolder is in root project.4.HomeController:
5.Startup.cs:
Result: