Skip to content

Commit 4d4e639

Browse files
committed
added delegate to make the GetRequestUserLanguage more extensible
1 parent 086ad9c commit 4d4e639

File tree

1 file changed

+21
-19
lines changed

1 file changed

+21
-19
lines changed

src/i18n/Helpers/HttpContextExtensions.cs

+21-19
Original file line numberDiff line numberDiff line change
@@ -194,29 +194,31 @@ public static LanguageItem[] GetRequestUserLanguages(this System.Web.HttpContext
194194
if (UserLanguages == null)
195195
{
196196
// Construct UserLanguages list and cache it for the rest of the request.
197-
context.Items["i18n.UserLanguages"]
198-
= UserLanguages
199-
= LanguageItem.ParseHttpLanguageHeader(
200-
context.Request.Headers["Accept-Language"]);
201-
// NB: originally we passed LocalizedApplication.Current.DefaultLanguageTag
202-
// here as the second parameter i.e. to specify the PAL. However, this was
203-
// found to be incorrect when operating i18n with EarlyUrlLocalization disabled,
204-
// as SetPrincipalAppLanguageForRequest was not being called, that normally
205-
// overwriting the PAL set erroneously here.
197+
context.Items["i18n.UserLanguages"]
198+
= UserLanguages = GetRequestUserLanguagesImplementation(context);
199+
// NB: originally we passed LocalizedApplication.Current.DefaultLanguageTag
200+
// here as the second parameter i.e. to specify the PAL. However, this was
201+
// found to be incorrect when operating i18n with EarlyUrlLocalization disabled,
202+
// as SetPrincipalAppLanguageForRequest was not being called, that normally
203+
// overwriting the PAL set erroneously here.
206204
}
207205
return UserLanguages;
208206
}
209207

210-
/// <summary>
211-
/// Add a Content-Language HTTP header to the response, based on any languages
212-
/// that have provided resources during the request.
213-
/// </summary>
214-
/// <param name="context">Context of the current request.</param>
215-
/// <returns>
216-
/// true if header added; false if no languages provided content during the request and
217-
/// so no header was added.
218-
/// </returns>
219-
public static bool SetContentLanguageHeader(this System.Web.HttpContext context)
208+
public delegate LanguageItem[] GetRequestUserLanguagesProc(System.Web.HttpContextBase context);
209+
210+
public static GetRequestUserLanguagesProc GetRequestUserLanguagesImplementation { get; set; } = (context) => LanguageItem.ParseHttpLanguageHeader(context.Request.Headers["Accept-Language"]);
211+
212+
/// <summary>
213+
/// Add a Content-Language HTTP header to the response, based on any languages
214+
/// that have provided resources during the request.
215+
/// </summary>
216+
/// <param name="context">Context of the current request.</param>
217+
/// <returns>
218+
/// true if header added; false if no languages provided content during the request and
219+
/// so no header was added.
220+
/// </returns>
221+
public static bool SetContentLanguageHeader(this System.Web.HttpContext context)
220222
{
221223
return context.GetHttpContextBase().SetContentLanguageHeader();
222224
}

0 commit comments

Comments
 (0)