-2

I need help creating a mvc3 website. I need to have 2 languages russian and english. By clicking on flag image the site language is changed:

flags:

<a id="rus" href="@Url.Content("~/Home/Index_en")" title=" english language"><small> english language </small></a> <a id="eng" href="#" title=" russian language"><small>russian language</small></a>

for example: change the menu=>

<ul id="mainMenu" >
        <nav class="dark">
            <li style="margin-left:1px; margin-bottom:5px;"><a href="@Url.Content("~/Home")">home</a></li>
            <li><a href="@Url.Content("~/About_us")">about us</a></li>
            <li><a href="#">ofers</a></li>

            <li><a href="@Url.Content("~/Apply")">Apply</a></li>
            <li><a href="#">contact</a></li>
</nav></ul>
JakeParis
  • 11,056
  • 3
  • 42
  • 65

3 Answers3

0

It is not a trivial task. You need custom routing, a controller hook (e.g. in OnActionExecuting) and some tricks with server-side culture changing. Also all your strings need to be in locale-specific resource files.

Here are a couple of links to help:

http://geekswithblogs.net/shaunxu/archive/2010/05/06/localization-in-asp.net-mvc-ndash-3-days-investigation-1-day.aspx

http://download1.parallels.com/SiteBuilder/Windows/docs/3.2/en_US/sitebulder-3.2-win-sdk-localization-pack-creation-guide/30801.htm

I used these as my reference to build a generic localisation library for my MVC apps.

Part 1 Custom routing

My custom route looks like this. It expects either a 2 letter or 2-2 letter language code (ISO format) e.g. en or en-EN etc:

//Special localisation route mapping - expects specific language/culture code as first param
routes.MapRoute(
    name: "Localisation",
    url: "{lang}/{controller}/{action}/{id}",
    defaults: new { lang = "en", controller = "Home", action = "List", id = UrlParameter.Optional },
    constraints: new { lang = @"[a-z]{2}|[a-z]{2}-[a-zA-Z]{2}" }
);

So links to change language will simply look like this (simplified version):

<a href="en">English language</a>
<a href="ru">Russian language</a>
iCollect.it Ltd
  • 92,391
  • 25
  • 181
  • 202
0

for example i create a site like:http://www.asp.net/mvc/overview/older-versions/mvc-music-store/mvc-music-store-part-1 mvc3 music store i want to add language.

thanks for help.

0

You can find the answer for jquery based resource location posted here https://stackoverflow.com/a/30610862/1239344

Community
  • 1
  • 1