Answer the question
In order to leave comments, you need to log in
How to localize asp mvc application based on views?
Hello! It is necessary to make a bilingual site. Just for views, no resources needed.
I do everything according to the article blogs.msdn.com/b/vyunev/archive/2011/12/07/asp-net...
with grief in half started it, reading from cookies was not involved in the base controller, added:
string cultureName = null;
// Attempt to read the culture cookie from Request
HttpCookie cultureCookie = Request.Cookies["_culture"];
if (cultureCookie != null)
cultureName = cultureCookie.Value;
else
cultureName = Thread.CurrentThread.CurrentCulture.Name;
@{
var culture = System.Threading.Thread.CurrentThread.CurrentUICulture.Name.ToLowerInvariant();
}
@helper selected(string c, string culture)
{
if (c == culture)
{
@:checked="checked"
}
}
@using (Html.BeginForm("SetCulture", "Home"))
{
<fieldset>
<input name="culture" id="ru-ru" value="ru-ru" type="radio" @selected("ru-ru", culture) /> Русский <br />
<input name="culture" id="en-us" value="en-us" type="radio" @selected("en-us", culture) /> English
</fieldset>
}
...
@section Scripts {
@Scripts.Render("~/bundles/jqueryval")
<script type="text/javascript">
(function ($) {
$("input[type = 'radio']").click(function () {
$(this).parents("form").submit(); // post form
});
})(jQuery);
</script>
}
Answer the question
In order to leave comments, you need to log in
The author of the article refers to the fact that some languages have a different direction of writing from Russian, and the use of resource files will not give the desired effect. In your case - what is the reason for using different Views? Fundamentally great content ? I also personally dislike filling the controller with locale extraction logic. Make, for example, an AJAX request to a separate method by setting this value. And reading recommendations from 4 years ago is probably not the best idea.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question