Standardizing middleware to use configureOptions lambda
This commit is contained in:
parent
489250a8e1
commit
d9fc399531
|
|
@ -23,12 +23,12 @@ namespace LocalizationSample
|
|||
|
||||
public void Configure(IApplicationBuilder app, IStringLocalizer<Startup> SR)
|
||||
{
|
||||
var options = new RequestLocalizationOptions
|
||||
app.UseRequestLocalization(options =>
|
||||
{
|
||||
DefaultRequestCulture = new RequestCulture("en-US"),
|
||||
options.DefaultRequestCulture = new RequestCulture("en-US");
|
||||
|
||||
// Set options here to change middleware behavior
|
||||
SupportedCultures = new List<CultureInfo>
|
||||
options.SupportedCultures = new List<CultureInfo>
|
||||
{
|
||||
new CultureInfo("en-US"),
|
||||
new CultureInfo("en-AU"),
|
||||
|
|
@ -39,8 +39,8 @@ namespace LocalizationSample
|
|||
new CultureInfo("zh"),
|
||||
new CultureInfo("zh-CN"),
|
||||
new CultureInfo("zh-CHT")
|
||||
},
|
||||
SupportedUICultures = new List<CultureInfo>
|
||||
};
|
||||
options.SupportedUICultures = new List<CultureInfo>
|
||||
{
|
||||
new CultureInfo("en-US"),
|
||||
new CultureInfo("en-AU"),
|
||||
|
|
@ -51,17 +51,15 @@ namespace LocalizationSample
|
|||
new CultureInfo("zh"),
|
||||
new CultureInfo("zh-CN"),
|
||||
new CultureInfo("zh-CHT")
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
// Optionally create an app-specific provider with just a delegate, e.g. look up user preference from DB.
|
||||
// Inserting it as position 0 ensures it has priority over any of the default providers.
|
||||
//options.RequestCultureProviders.Insert(0, new CustomRequestCultureProvider(async context =>
|
||||
//{
|
||||
|
||||
//}));
|
||||
// Optionally create an app-specific provider with just a delegate, e.g. look up user preference from DB.
|
||||
// Inserting it as position 0 ensures it has priority over any of the default providers.
|
||||
//options.RequestCultureProviders.Insert(0, new CustomRequestCultureProvider(async context =>
|
||||
//{
|
||||
|
||||
app.UseRequestLocalization(options);
|
||||
//}));
|
||||
});
|
||||
|
||||
app.Use(async (context, next) =>
|
||||
{
|
||||
|
|
|
|||
|
|
@ -17,22 +17,24 @@ namespace Microsoft.AspNet.Builder
|
|||
/// requests based on information provided by the client.
|
||||
/// </summary>
|
||||
/// <param name="app">The <see cref="IApplicationBuilder"/>.</param>
|
||||
/// <param name="options">The options to configure the middleware with.</param>
|
||||
/// <param name="configureOptions">An action delegate to configure the provided <see cref="RequestLocalizationOptions"/>.</param>
|
||||
/// <returns>The <see cref="IApplicationBuilder"/>.</returns>
|
||||
public static IApplicationBuilder UseRequestLocalization(
|
||||
this IApplicationBuilder app,
|
||||
RequestLocalizationOptions options)
|
||||
Action<RequestLocalizationOptions> configureOptions)
|
||||
{
|
||||
if (app == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(app));
|
||||
}
|
||||
|
||||
if (options == null)
|
||||
if (configureOptions == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(options));
|
||||
throw new ArgumentNullException(nameof(configureOptions));
|
||||
}
|
||||
|
||||
var options = new RequestLocalizationOptions();
|
||||
configureOptions(options);
|
||||
|
||||
return app.UseMiddleware<RequestLocalizationMiddleware>(options);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -29,20 +29,18 @@ namespace LocalizationWebsite
|
|||
{
|
||||
loggerFactory.AddConsole(minLevel: LogLevel.Warning);
|
||||
|
||||
var options = new RequestLocalizationOptions
|
||||
app.UseRequestLocalization(options =>
|
||||
{
|
||||
DefaultRequestCulture = new RequestCulture("en-US"),
|
||||
SupportedCultures = new List<CultureInfo>()
|
||||
options.DefaultRequestCulture = new RequestCulture("en-US");
|
||||
options.SupportedCultures = new List<CultureInfo>()
|
||||
{
|
||||
new CultureInfo("fr-FR")
|
||||
},
|
||||
SupportedUICultures = new List<CultureInfo>()
|
||||
};
|
||||
options.SupportedUICultures = new List<CultureInfo>()
|
||||
{
|
||||
new CultureInfo("fr-FR")
|
||||
}
|
||||
};
|
||||
|
||||
app.UseRequestLocalization(options);
|
||||
};
|
||||
});
|
||||
|
||||
var stringLocalizer = stringLocalizerFactory.Create("Test", location: null);
|
||||
|
||||
|
|
|
|||
|
|
@ -29,20 +29,18 @@ namespace LocalizationWebsite
|
|||
{
|
||||
loggerFactory.AddConsole(minLevel: LogLevel.Warning);
|
||||
|
||||
var options = new RequestLocalizationOptions
|
||||
app.UseRequestLocalization(options =>
|
||||
{
|
||||
DefaultRequestCulture = new RequestCulture("en-US"),
|
||||
SupportedCultures = new List<CultureInfo>()
|
||||
options.DefaultRequestCulture = new RequestCulture("en-US");
|
||||
options.SupportedCultures = new List<CultureInfo>()
|
||||
{
|
||||
new CultureInfo("fr-FR")
|
||||
},
|
||||
SupportedUICultures = new List<CultureInfo>()
|
||||
};
|
||||
options.SupportedUICultures = new List<CultureInfo>()
|
||||
{
|
||||
new CultureInfo("fr-FR")
|
||||
}
|
||||
};
|
||||
|
||||
app.UseRequestLocalization(options);
|
||||
};
|
||||
});
|
||||
|
||||
var stringLocalizer = stringLocalizerFactory.Create("Test", location: null);
|
||||
|
||||
|
|
|
|||
|
|
@ -21,16 +21,15 @@ namespace Microsoft.Extensions.Localization.Tests
|
|||
var builder = new WebApplicationBuilder()
|
||||
.Configure(app =>
|
||||
{
|
||||
var options = new RequestLocalizationOptions
|
||||
app.UseRequestLocalization(options =>
|
||||
{
|
||||
DefaultRequestCulture = new RequestCulture("en-US"),
|
||||
SupportedCultures = new List<CultureInfo>
|
||||
options.DefaultRequestCulture = new RequestCulture("en-US");
|
||||
options.SupportedCultures = new List<CultureInfo>
|
||||
{
|
||||
new CultureInfo("ar-SA"),
|
||||
new CultureInfo("en-US")
|
||||
}
|
||||
};
|
||||
app.UseRequestLocalization(options);
|
||||
};
|
||||
});
|
||||
app.Run(context =>
|
||||
{
|
||||
var requestCultureFeature = context.Features.Get<IRequestCultureFeature>();
|
||||
|
|
@ -56,16 +55,15 @@ namespace Microsoft.Extensions.Localization.Tests
|
|||
var builder = new WebApplicationBuilder()
|
||||
.Configure(app =>
|
||||
{
|
||||
var options = new RequestLocalizationOptions
|
||||
app.UseRequestLocalization(options =>
|
||||
{
|
||||
DefaultRequestCulture = new RequestCulture("fr-FR"),
|
||||
SupportedCultures = new List<CultureInfo>
|
||||
options.DefaultRequestCulture = new RequestCulture("fr-FR");
|
||||
options.SupportedCultures = new List<CultureInfo>
|
||||
{
|
||||
new CultureInfo("ar-SA"),
|
||||
new CultureInfo("en-US")
|
||||
}
|
||||
};
|
||||
app.UseRequestLocalization(options);
|
||||
};
|
||||
});
|
||||
app.Run(context =>
|
||||
{
|
||||
var requestCultureFeature = context.Features.Get<IRequestCultureFeature>();
|
||||
|
|
@ -90,16 +88,15 @@ namespace Microsoft.Extensions.Localization.Tests
|
|||
var builder = new WebApplicationBuilder()
|
||||
.Configure(app =>
|
||||
{
|
||||
var options = new RequestLocalizationOptions
|
||||
app.UseRequestLocalization(options =>
|
||||
{
|
||||
DefaultRequestCulture = new RequestCulture("fr-FR"),
|
||||
SupportedCultures = new List<CultureInfo>
|
||||
options.DefaultRequestCulture = new RequestCulture("fr-FR");
|
||||
options.SupportedCultures = new List<CultureInfo>
|
||||
{
|
||||
new CultureInfo("ar-SA"),
|
||||
new CultureInfo("af-ZA")
|
||||
}
|
||||
};
|
||||
app.UseRequestLocalization(options);
|
||||
};
|
||||
});
|
||||
app.Run(context =>
|
||||
{
|
||||
var requestCultureFeature = context.Features.Get<IRequestCultureFeature>();
|
||||
|
|
@ -125,19 +122,18 @@ namespace Microsoft.Extensions.Localization.Tests
|
|||
var builder = new WebApplicationBuilder()
|
||||
.Configure(app =>
|
||||
{
|
||||
var options = new RequestLocalizationOptions()
|
||||
app.UseRequestLocalization(options =>
|
||||
{
|
||||
DefaultRequestCulture = new RequestCulture("en-US"),
|
||||
SupportedCultures = new List<CultureInfo>
|
||||
options.DefaultRequestCulture = new RequestCulture("en-US");
|
||||
options.SupportedCultures = new List<CultureInfo>
|
||||
{
|
||||
new CultureInfo("ar-YE")
|
||||
},
|
||||
SupportedUICultures = new List<CultureInfo>
|
||||
};
|
||||
options.SupportedUICultures = new List<CultureInfo>
|
||||
{
|
||||
new CultureInfo("ar-YE")
|
||||
}
|
||||
};
|
||||
app.UseRequestLocalization(options);
|
||||
};
|
||||
});
|
||||
app.Run(context =>
|
||||
{
|
||||
var requestCultureFeature = context.Features.Get<IRequestCultureFeature>();
|
||||
|
|
|
|||
|
|
@ -22,22 +22,21 @@ namespace Microsoft.Extensions.Localization.Tests
|
|||
var builder = new WebApplicationBuilder()
|
||||
.Configure(app =>
|
||||
{
|
||||
var options = new RequestLocalizationOptions()
|
||||
app.UseRequestLocalization(options =>
|
||||
{
|
||||
DefaultRequestCulture = new RequestCulture("en-US"),
|
||||
SupportedCultures = new List<CultureInfo>
|
||||
options.DefaultRequestCulture = new RequestCulture("en-US");
|
||||
options.SupportedCultures = new List<CultureInfo>
|
||||
{
|
||||
new CultureInfo("ar-SA")
|
||||
},
|
||||
SupportedUICultures = new List<CultureInfo>
|
||||
};
|
||||
options.SupportedUICultures = new List<CultureInfo>
|
||||
{
|
||||
new CultureInfo("ar-SA")
|
||||
}
|
||||
};
|
||||
var provider = new CookieRequestCultureProvider();
|
||||
provider.CookieName = "Preferences";
|
||||
options.RequestCultureProviders.Insert(0, provider);
|
||||
app.UseRequestLocalization(options);
|
||||
};
|
||||
var provider = new CookieRequestCultureProvider();
|
||||
provider.CookieName = "Preferences";
|
||||
options.RequestCultureProviders.Insert(0, provider);
|
||||
});
|
||||
app.Run(context =>
|
||||
{
|
||||
var requestCultureFeature = context.Features.Get<IRequestCultureFeature>();
|
||||
|
|
@ -65,22 +64,21 @@ namespace Microsoft.Extensions.Localization.Tests
|
|||
var builder = new WebApplicationBuilder()
|
||||
.Configure(app =>
|
||||
{
|
||||
var options = new RequestLocalizationOptions()
|
||||
app.UseRequestLocalization(options =>
|
||||
{
|
||||
DefaultRequestCulture = new RequestCulture("en-US"),
|
||||
SupportedCultures = new List<CultureInfo>
|
||||
options.DefaultRequestCulture = new RequestCulture("en-US");
|
||||
options.SupportedCultures = new List<CultureInfo>
|
||||
{
|
||||
new CultureInfo("ar-SA")
|
||||
},
|
||||
SupportedUICultures = new List<CultureInfo>
|
||||
};
|
||||
options.SupportedUICultures = new List<CultureInfo>
|
||||
{
|
||||
new CultureInfo("ar-SA")
|
||||
}
|
||||
};
|
||||
var provider = new CookieRequestCultureProvider();
|
||||
provider.CookieName = "Preferences";
|
||||
options.RequestCultureProviders.Insert(0, provider);
|
||||
app.UseRequestLocalization(options);
|
||||
};
|
||||
var provider = new CookieRequestCultureProvider();
|
||||
provider.CookieName = "Preferences";
|
||||
options.RequestCultureProviders.Insert(0, provider);
|
||||
});
|
||||
app.Run(context =>
|
||||
{
|
||||
var requestCultureFeature = context.Features.Get<IRequestCultureFeature>();
|
||||
|
|
@ -104,22 +102,21 @@ namespace Microsoft.Extensions.Localization.Tests
|
|||
var builder = new WebApplicationBuilder()
|
||||
.Configure(app =>
|
||||
{
|
||||
var options = new RequestLocalizationOptions()
|
||||
app.UseRequestLocalization(options =>
|
||||
{
|
||||
DefaultRequestCulture = new RequestCulture("en-US"),
|
||||
SupportedCultures = new List<CultureInfo>
|
||||
options.DefaultRequestCulture = new RequestCulture("en-US");
|
||||
options.SupportedCultures = new List<CultureInfo>
|
||||
{
|
||||
new CultureInfo("ar-SA")
|
||||
},
|
||||
SupportedUICultures = new List<CultureInfo>
|
||||
};
|
||||
options.SupportedUICultures = new List<CultureInfo>
|
||||
{
|
||||
new CultureInfo("ar-SA")
|
||||
}
|
||||
};
|
||||
var provider = new CookieRequestCultureProvider();
|
||||
provider.CookieName = "Preferences";
|
||||
options.RequestCultureProviders.Insert(0, provider);
|
||||
app.UseRequestLocalization(options);
|
||||
};
|
||||
var provider = new CookieRequestCultureProvider();
|
||||
provider.CookieName = "Preferences";
|
||||
options.RequestCultureProviders.Insert(0, provider);
|
||||
});
|
||||
app.Run(context =>
|
||||
{
|
||||
var requestCultureFeature = context.Features.Get<IRequestCultureFeature>();
|
||||
|
|
|
|||
|
|
@ -23,25 +23,24 @@ namespace Microsoft.Extensions.Localization.Tests
|
|||
var builder = new WebApplicationBuilder()
|
||||
.Configure(app =>
|
||||
{
|
||||
var options = new RequestLocalizationOptions()
|
||||
app.UseRequestLocalization(options =>
|
||||
{
|
||||
DefaultRequestCulture = new RequestCulture("en-US"),
|
||||
SupportedCultures = new List<CultureInfo>
|
||||
options.DefaultRequestCulture = new RequestCulture("en-US");
|
||||
options.SupportedCultures = new List<CultureInfo>
|
||||
{
|
||||
new CultureInfo("ar")
|
||||
},
|
||||
SupportedUICultures = new List<CultureInfo>
|
||||
};
|
||||
options.SupportedUICultures = new List<CultureInfo>
|
||||
{
|
||||
new CultureInfo("ar")
|
||||
}
|
||||
};
|
||||
options.RequestCultureProviders.Insert(0, new CustomRequestCultureProvider(context =>
|
||||
{
|
||||
var culture = GetCultureInfoFromUrl(context, options.SupportedCultures);
|
||||
var requestCulture = new ProviderCultureResult(culture);
|
||||
return Task.FromResult(requestCulture);
|
||||
}));
|
||||
app.UseRequestLocalization(options);
|
||||
};
|
||||
options.RequestCultureProviders.Insert(0, new CustomRequestCultureProvider(context =>
|
||||
{
|
||||
var culture = GetCultureInfoFromUrl(context, options.SupportedCultures);
|
||||
var requestCulture = new ProviderCultureResult(culture);
|
||||
return Task.FromResult(requestCulture);
|
||||
}));
|
||||
});
|
||||
app.Run(context =>
|
||||
{
|
||||
var requestCultureFeature = context.Features.Get<IRequestCultureFeature>();
|
||||
|
|
|
|||
|
|
@ -21,20 +21,18 @@ namespace Microsoft.Extensions.Localization.Tests
|
|||
var builder = new WebApplicationBuilder()
|
||||
.Configure(app =>
|
||||
{
|
||||
var options = new RequestLocalizationOptions()
|
||||
app.UseRequestLocalization(options =>
|
||||
{
|
||||
DefaultRequestCulture = new RequestCulture("en-US"),
|
||||
SupportedCultures = new List<CultureInfo>
|
||||
options.DefaultRequestCulture = new RequestCulture("en-US");
|
||||
options.SupportedCultures = new List<CultureInfo>
|
||||
{
|
||||
new CultureInfo("ar-SA")
|
||||
},
|
||||
SupportedUICultures = new List<CultureInfo>
|
||||
};
|
||||
options.SupportedUICultures = new List<CultureInfo>
|
||||
{
|
||||
new CultureInfo("ar-YE")
|
||||
}
|
||||
};
|
||||
|
||||
app.UseRequestLocalization(options);
|
||||
};
|
||||
});
|
||||
app.Run(context =>
|
||||
{
|
||||
var requestCultureFeature = context.Features.Get<IRequestCultureFeature>();
|
||||
|
|
@ -58,11 +56,10 @@ namespace Microsoft.Extensions.Localization.Tests
|
|||
var builder = new WebApplicationBuilder()
|
||||
.Configure(app =>
|
||||
{
|
||||
var options = new RequestLocalizationOptions
|
||||
app.UseRequestLocalization(options =>
|
||||
{
|
||||
DefaultRequestCulture = new RequestCulture("en-US"),
|
||||
};
|
||||
app.UseRequestLocalization(options);
|
||||
options.DefaultRequestCulture = new RequestCulture("en-US");
|
||||
});
|
||||
app.Run(context =>
|
||||
{
|
||||
var requestCultureFeature = context.Features.Get<IRequestCultureFeature>();
|
||||
|
|
@ -86,19 +83,18 @@ namespace Microsoft.Extensions.Localization.Tests
|
|||
var builder = new WebApplicationBuilder()
|
||||
.Configure(app =>
|
||||
{
|
||||
var options = new RequestLocalizationOptions()
|
||||
app.UseRequestLocalization(options =>
|
||||
{
|
||||
DefaultRequestCulture = new RequestCulture("en-US"),
|
||||
SupportedCultures = new List<CultureInfo>
|
||||
options.DefaultRequestCulture = new RequestCulture("en-US");
|
||||
options.SupportedCultures = new List<CultureInfo>
|
||||
{
|
||||
new CultureInfo("ar-SA")
|
||||
},
|
||||
SupportedUICultures = new List<CultureInfo>
|
||||
};
|
||||
options.SupportedUICultures = new List<CultureInfo>
|
||||
{
|
||||
new CultureInfo("ar-SA")
|
||||
}
|
||||
};
|
||||
app.UseRequestLocalization(options);
|
||||
};
|
||||
});
|
||||
app.Run(context =>
|
||||
{
|
||||
var requestCultureFeature = context.Features.Get<IRequestCultureFeature>();
|
||||
|
|
@ -121,19 +117,18 @@ namespace Microsoft.Extensions.Localization.Tests
|
|||
var builder = new WebApplicationBuilder()
|
||||
.Configure(app =>
|
||||
{
|
||||
var options = new RequestLocalizationOptions()
|
||||
app.UseRequestLocalization(options =>
|
||||
{
|
||||
DefaultRequestCulture = new RequestCulture("en-US"),
|
||||
SupportedCultures = new List<CultureInfo>
|
||||
options.DefaultRequestCulture = new RequestCulture("en-US");
|
||||
options.SupportedCultures = new List<CultureInfo>
|
||||
{
|
||||
new CultureInfo("ar-SA")
|
||||
},
|
||||
SupportedUICultures = new List<CultureInfo>
|
||||
};
|
||||
options.SupportedUICultures = new List<CultureInfo>
|
||||
{
|
||||
new CultureInfo("ar-SA")
|
||||
}
|
||||
};
|
||||
app.UseRequestLocalization(options);
|
||||
};
|
||||
});
|
||||
app.Run(context =>
|
||||
{
|
||||
var requestCultureFeature = context.Features.Get<IRequestCultureFeature>();
|
||||
|
|
@ -156,19 +151,18 @@ namespace Microsoft.Extensions.Localization.Tests
|
|||
var builder = new WebApplicationBuilder()
|
||||
.Configure(app =>
|
||||
{
|
||||
var options = new RequestLocalizationOptions()
|
||||
app.UseRequestLocalization(options =>
|
||||
{
|
||||
DefaultRequestCulture = new RequestCulture("en-US"),
|
||||
SupportedCultures = new List<CultureInfo>
|
||||
options.DefaultRequestCulture = new RequestCulture("en-US");
|
||||
options.SupportedCultures = new List<CultureInfo>
|
||||
{
|
||||
new CultureInfo("ar-SA")
|
||||
},
|
||||
SupportedUICultures = new List<CultureInfo>
|
||||
};
|
||||
options.SupportedUICultures = new List<CultureInfo>
|
||||
{
|
||||
new CultureInfo("ar-SA")
|
||||
}
|
||||
};
|
||||
app.UseRequestLocalization(options);
|
||||
};
|
||||
});
|
||||
app.Run(context =>
|
||||
{
|
||||
var requestCultureFeature = context.Features.Get<IRequestCultureFeature>();
|
||||
|
|
@ -192,19 +186,18 @@ namespace Microsoft.Extensions.Localization.Tests
|
|||
var builder = new WebApplicationBuilder()
|
||||
.Configure(app =>
|
||||
{
|
||||
var options = new RequestLocalizationOptions()
|
||||
app.UseRequestLocalization(options =>
|
||||
{
|
||||
DefaultRequestCulture = new RequestCulture("en-US"),
|
||||
SupportedCultures = new List<CultureInfo>
|
||||
options.DefaultRequestCulture = new RequestCulture("en-US");
|
||||
options.SupportedCultures = new List<CultureInfo>
|
||||
{
|
||||
new CultureInfo("ar-SA")
|
||||
},
|
||||
SupportedUICultures = new List<CultureInfo>
|
||||
};
|
||||
options.SupportedUICultures = new List<CultureInfo>
|
||||
{
|
||||
new CultureInfo("ar-SA")
|
||||
}
|
||||
};
|
||||
app.UseRequestLocalization(options);
|
||||
};
|
||||
});
|
||||
app.Run(context =>
|
||||
{
|
||||
var requestCultureFeature = context.Features.Get<IRequestCultureFeature>();
|
||||
|
|
@ -228,23 +221,22 @@ namespace Microsoft.Extensions.Localization.Tests
|
|||
var builder = new WebApplicationBuilder()
|
||||
.Configure(app =>
|
||||
{
|
||||
var options = new RequestLocalizationOptions()
|
||||
app.UseRequestLocalization(options =>
|
||||
{
|
||||
DefaultRequestCulture = new RequestCulture("en-US"),
|
||||
SupportedCultures = new List<CultureInfo>
|
||||
options.DefaultRequestCulture = new RequestCulture("en-US");
|
||||
options.SupportedCultures = new List<CultureInfo>
|
||||
{
|
||||
new CultureInfo("ar-SA")
|
||||
},
|
||||
SupportedUICultures = new List<CultureInfo>
|
||||
};
|
||||
options.SupportedUICultures = new List<CultureInfo>
|
||||
{
|
||||
new CultureInfo("ar-YE")
|
||||
}
|
||||
};
|
||||
var provider = new QueryStringRequestCultureProvider();
|
||||
provider.QueryStringKey = "c";
|
||||
provider.UIQueryStringKey = "uic";
|
||||
options.RequestCultureProviders.Insert(0, provider);
|
||||
app.UseRequestLocalization(options);
|
||||
};
|
||||
var provider = new QueryStringRequestCultureProvider();
|
||||
provider.QueryStringKey = "c";
|
||||
provider.UIQueryStringKey = "uic";
|
||||
options.RequestCultureProviders.Insert(0, provider);
|
||||
});
|
||||
app.Run(context =>
|
||||
{
|
||||
var requestCultureFeature = context.Features.Get<IRequestCultureFeature>();
|
||||
|
|
@ -268,23 +260,22 @@ namespace Microsoft.Extensions.Localization.Tests
|
|||
var builder = new WebApplicationBuilder()
|
||||
.Configure(app =>
|
||||
{
|
||||
var options = new RequestLocalizationOptions()
|
||||
app.UseRequestLocalization(options =>
|
||||
{
|
||||
DefaultRequestCulture = new RequestCulture("en-US"),
|
||||
SupportedCultures = new List<CultureInfo>
|
||||
options.DefaultRequestCulture = new RequestCulture("en-US");
|
||||
options.SupportedCultures = new List<CultureInfo>
|
||||
{
|
||||
new CultureInfo("FR")
|
||||
},
|
||||
SupportedUICultures = new List<CultureInfo>
|
||||
};
|
||||
options.SupportedUICultures = new List<CultureInfo>
|
||||
{
|
||||
new CultureInfo("FR")
|
||||
}
|
||||
};
|
||||
var provider = new QueryStringRequestCultureProvider();
|
||||
provider.QueryStringKey = "c";
|
||||
provider.UIQueryStringKey = "uic";
|
||||
options.RequestCultureProviders.Insert(0, provider);
|
||||
app.UseRequestLocalization(options);
|
||||
};
|
||||
var provider = new QueryStringRequestCultureProvider();
|
||||
provider.QueryStringKey = "c";
|
||||
provider.UIQueryStringKey = "uic";
|
||||
options.RequestCultureProviders.Insert(0, provider);
|
||||
});
|
||||
app.Run(context =>
|
||||
{
|
||||
var requestCultureFeature = context.Features.Get<IRequestCultureFeature>();
|
||||
|
|
|
|||
Loading…
Reference in New Issue