Skip to content

Commit

Permalink
Added support for changing default i18n cookie name. (#296)
Browse files Browse the repository at this point in the history
  • Loading branch information
turquoiseowl committed Sep 20, 2016
1 parent 286c942 commit b4d2395
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 1 deletion.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,9 @@ code shows the most common options:
// Change from the default of 'en'.
i18n.LocalizedApplication.Current.DefaultLanguage = "fr";

// Change from the default of 'i18n.langtag'.
i18n.LocalizedApplication.Current.CookieName = "i18n_langtag";

// Change from the of temporary redirects during URL localization
i18n.LocalizedApplication.Current.PermanentRedirects = true;

Expand Down
2 changes: 1 addition & 1 deletion src/i18n/Helpers/HttpContextExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,7 @@ public static LanguageTag GetInferredLanguage(this System.Web.HttpContextBase co
// 1. Inferred user languages (cookie and Accept-Language header)
// 2. App Languages.
LanguageTag lt = null;
System.Web.HttpCookie cookie_langtag = context.Request.Cookies.Get("i18n.langtag");
System.Web.HttpCookie cookie_langtag = context.Request.Cookies.Get(LocalizedApplication.Current.CookieName);
if (cookie_langtag != null) {
lt = LanguageHelpers.GetMatchingAppLanguage(cookie_langtag.Value); }
if (lt == null) {
Expand Down
6 changes: 6 additions & 0 deletions src/i18n/LocalizedApplication.cs
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,11 @@ public string DefaultLanguage
/// </remarks>
public string ApplicationPath { get; set; }

/// <summary>
/// The name for the i18n cookie. Defaults to "i18n.langtag".
/// </summary>
public string CookieName { get; set; }

/// <summary>
/// Declares a method type for handling the setting of the language.
/// </summary>
Expand Down Expand Up @@ -222,6 +227,7 @@ public LocalizedApplication(IRootServices i_RootServices = null)

// Default settings.
DefaultLanguage = ("en");
CookieName = "i18n.langtag";
MessageKeyIsValueInDefaultLanguage = true;
PermanentRedirects = false;

Expand Down

0 comments on commit b4d2395

Please sign in to comment.