public LocalizedApplication(IRootServices i_RootServices = null) { // Default settings. DefaultLanguage = ("en"); CookieName = "i18n.langtag"; MessageKeyIsValueInDefaultLanguage = true; PermanentRedirects = false; // Attempt to determine ApplicationPath. // NB: if this method being called outside of a request handler, HttpContext.Current // fails. Normally, this results in a null being returned; however it has been observed // that it can also throw. try { var mycontext = System.Web.HttpContext.Current; if (mycontext != null && mycontext.Request.ApplicationPath != null) { ApplicationPath = mycontext.Request.ApplicationPath.TrimEnd('/'); } } catch (Exception) { } if (String.IsNullOrWhiteSpace(ApplicationPath)) { ApplicationPath = "/"; } // Use default package of root services. // Host app may override this. RootServices = i_RootServices ?? new DefaultRootServices(); // Install default handler for Set-PAL event. // The default handler applies the setting to both the CurrentCulture and CurrentUICulture // settings of the thread. SetPrincipalAppLanguageForRequestHandlers = delegate(System.Web.HttpContextBase context, ILanguageTag langtag) { if (langtag != null) { Thread.CurrentThread.CurrentCulture = Thread.CurrentThread.CurrentUICulture = langtag.GetCultureInfo(); } }; }
/// <summary> /// Conditionally installs the i18n response filter. /// </summary> /// <param name="context">The HTTP context.</param> /// <param name="rootServices">The root services.</param> public static void InstallResponseFilter(System.Web.HttpContextBase context, IRootServices rootServices) { if (rootServices == null) { rootServices = Current.RootServices; } // If the content type of the entity is eligible for processing AND the URL is not to be excluded, // wire up our filter to do the processing. The entity data will be run through the filter a // bit later on in the pipeline. if (Current.ContentTypesToLocalize != null && context.Response.ContentType != null && Current.ContentTypesToLocalize.Match(context.Response.ContentType).Success) // Include certain content types from being processed { if (Current.UrlsToExcludeFromProcessing != null && Current.UrlsToExcludeFromProcessing.Match(context.Request.RawUrl).Success) // Exclude certain URLs from being processed { DebugHelpers.WriteLine("InstallResponseFilter -- Bypassing filter, URL excluded: ({0}).", context.Request.RawUrl); } else if (context.Response.Headers["Content-Encoding"] != null || context.Response.Headers["Content-Encoding"] == "gzip") // Exclude responses that have already been compressed earlier in the pipeline { DebugHelpers.WriteLine("InstallResponseFilter -- Bypassing filter, response compressed."); } else { DebugHelpers.WriteLine("InstallResponseFilter -- Installing filter"); context.Response.Filter = new ResponseFilter( context, context.Response.Filter, UrlLocalizer.UrlLocalizationScheme == UrlLocalizationScheme.Void ? null : rootServices.EarlyUrlLocalizerForApp, rootServices.NuggetLocalizerForApp); } } else { DebugHelpers.WriteLine("InstallResponseFilter -- Bypassing filter, No content-type match: ({0}).", context.Response.ContentType); } }
public LocalizingModule( IRootServices rootServices) { m_rootServices = rootServices; }
public LocalizedApplication(IRootServices i_RootServices = null) { // Default settings. DefaultLanguage = ("en"); MessageKeyIsValueInDefaultLanguage = true; PermanentRedirects = false; // Attempt to determine ApplicationPath. // NB: if this method being called outside of a request handler, HttpContext.Current // fails. Normally, this results in a null being returned; however it has been observed // that it can also throw. try { var mycontext = System.Web.HttpContext.Current; if (mycontext != null && mycontext.Request.ApplicationPath != null) ApplicationPath = mycontext.Request.ApplicationPath.TrimEnd('/'); } catch (Exception) { } if (String.IsNullOrWhiteSpace(ApplicationPath)) { ApplicationPath = "/"; } // Use default package of root services. // Host app may override this. RootServices = i_RootServices ?? new DefaultRootServices(); // Install default handler for Set-PAL event. // The default handler applies the setting to both the CurrentCulture and CurrentUICulture // settings of the thread. SetPrincipalAppLanguageForRequestHandlers = delegate(System.Web.HttpContextBase context, ILanguageTag langtag) { if (langtag != null) { Thread.CurrentThread.CurrentCulture = Thread.CurrentThread.CurrentUICulture = langtag.GetCultureInfo(); } }; }