I have 2 resource file : Resources.resx(has some strings in Romanian) and Resources.en-US.resx (has the same strings in English).
I only want to change(in a dropdownlist, a listbox,...) witch resource file to use. It could be in _Layout.cshtml. I don't need to detect the user's culture.
Q: How can I select a resource file from a page ?
Edit : Can it be done without changing the default MapRoute ?
One way you can do it is to have the drop down just redirect the page to a language specific URL (this is quite nice as you can send around language specific links) then in a base class on your controller, set the Thread's locale.
This blog post covers what I am talking about in better detail: Localization in ASP.NET MVC – 3 Days Investigation, 1 Day Job
Check this Blog. Without changing default MapRoute.
The _Layout.cshtml page:
@using Resources;
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<title></title>
</head>
<body>
<div>
<form method="post">
@TestResource.SelectLanguage
<select name="lang">
<option></option>
<option value="en-GB" @(Culture == "en-GB" ? "selected=\"selected\"" : "")>English</option>
<option value="fr-FR" @(Culture == "fr-FR" ? "selected=\"selected\"" : "")>French</option>
<option value="de-DE" @(Culture == "de-DE" ? "selected=\"selected\"" : "")>German</option>
</select>
<input type="submit" value="@TestResource.Submit" />
</form>
</div>
@RenderBody()
</body>
</html>
The culture is set within the _PageStart.cshtml file:
@{
Layout = "~/_Layout.cshtml";
if(!Request["lang"].IsEmpty()){
Culture = UICulture = Request["lang"];
}
}
The final page is the Default page itself:
@using Resources;
<h1>@TestResource.Welcome</h1>
<p><img src="images/@TestResource.FlagImage" /></p>
http://www.mikesdotnetting.com/Article/183/Globalization-And-Localization-With-Razor-Web-Pages
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With