Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>you can create base controller that have the localization logic as below:</p> <pre><code> public abstract class LocalizedController : Controller { protected override void ExecuteCore() { HttpCookie cookie; string lang = GetCurrentCulture(); Thread.CurrentThread.CurrentUICulture = new CultureInfo(lang, false); // set the lang value into route data RouteData.Values["lang"] = lang; // save the location into cookie cookie = new HttpCookie("DPClick.CurrentUICulture", Thread.CurrentThread.CurrentUICulture.TwoLetterISOLanguageName) { Expires = DateTime.Now.AddYears(1) }; HttpContext.Response.SetCookie(cookie); base.ExecuteCore(); } private string GetCurrentCulture() { string lang; // set the culture from the route data (url) if (RouteData.Values["lang"] != null &amp;&amp; !string.IsNullOrWhiteSpace(RouteData.Values["lang"].ToString())) { lang = RouteData.Values["lang"].ToString(); if (Localization.Locales.TryGetValue(lang, out lang)) { return lang; } } // load the culture info from the cookie HttpCookie cookie = HttpContext.Request.Cookies["DPClick.CurrentUICulture"]; if (cookie != null) { // set the culture by the cookie content lang = cookie.Value; if (Localization.Locales.TryGetValue(lang, out lang)) { return lang; } } // set the culture by the location if not speicified lang = HttpContext.Request.UserLanguages[0]; if (Localization.Locales.TryGetValue(lang, out lang)) { return lang; } //English is default return Localization.Locales.FirstOrDefault().Value; } } </code></pre> <p>The above controller satisfy fashion 2 of your question if you want to ignore the culture folder just don't assign the lang in the RouteDate. offcourse to achieve fashion 2 you have to add routing for culture as below:</p> <pre><code> routes.MapRoute( "Localization", // Route name "{lang}/{controller}/{action}/{id}", // URL with parameters new {controller = "Default", action = "Index", id = UrlParameter.Optional}, // Parameter defaults new {lang = @"\w{2,3}(-\w{4})?(-\w{2,3})?"} ); </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload