Updating to new options pattern
This commit is contained in:
parent
5b1beb68b5
commit
5c2bdc8923
|
|
@ -7,7 +7,6 @@ using System.Globalization;
|
|||
using Microsoft.AspNet.Builder;
|
||||
using Microsoft.AspNet.Hosting;
|
||||
using Microsoft.AspNet.Http;
|
||||
using Microsoft.AspNet.Http.Features;
|
||||
using Microsoft.AspNet.Localization;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.Localization;
|
||||
|
|
@ -23,12 +22,12 @@ namespace LocalizationSample
|
|||
|
||||
public void Configure(IApplicationBuilder app, IStringLocalizer<Startup> SR)
|
||||
{
|
||||
app.UseRequestLocalization(options =>
|
||||
app.UseRequestLocalization(new RequestLocalizationOptions
|
||||
{
|
||||
options.DefaultRequestCulture = new RequestCulture("en-US");
|
||||
DefaultRequestCulture = new RequestCulture("en-US"),
|
||||
|
||||
// Set options here to change middleware behavior
|
||||
options.SupportedCultures = new List<CultureInfo>
|
||||
SupportedCultures = new List<CultureInfo>
|
||||
{
|
||||
new CultureInfo("en-US"),
|
||||
new CultureInfo("en-AU"),
|
||||
|
|
@ -39,8 +38,8 @@ namespace LocalizationSample
|
|||
new CultureInfo("zh"),
|
||||
new CultureInfo("zh-CN"),
|
||||
new CultureInfo("zh-CHT")
|
||||
};
|
||||
options.SupportedUICultures = new List<CultureInfo>
|
||||
},
|
||||
SupportedUICultures = new List<CultureInfo>
|
||||
{
|
||||
new CultureInfo("en-US"),
|
||||
new CultureInfo("en-AU"),
|
||||
|
|
@ -51,14 +50,14 @@ 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 =>
|
||||
//RequestCultureProviders.Insert(0, new CustomRequestCultureProvider(async context =>
|
||||
//{
|
||||
|
||||
//}));
|
||||
//}))
|
||||
});
|
||||
|
||||
app.Use(async (context, next) =>
|
||||
|
|
|
|||
|
|
@ -2,8 +2,8 @@
|
|||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
||||
|
||||
using System;
|
||||
using System.Globalization;
|
||||
using Microsoft.AspNet.Localization;
|
||||
using Microsoft.Extensions.Options;
|
||||
|
||||
namespace Microsoft.AspNet.Builder
|
||||
{
|
||||
|
|
@ -17,25 +17,15 @@ namespace Microsoft.AspNet.Builder
|
|||
/// requests based on information provided by the client.
|
||||
/// </summary>
|
||||
/// <param name="app">The <see cref="IApplicationBuilder"/>.</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,
|
||||
Action<RequestLocalizationOptions> configureOptions)
|
||||
public static IApplicationBuilder UseRequestLocalization(this IApplicationBuilder app)
|
||||
{
|
||||
if (app == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(app));
|
||||
}
|
||||
if (configureOptions == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(configureOptions));
|
||||
}
|
||||
|
||||
var options = new RequestLocalizationOptions();
|
||||
configureOptions(options);
|
||||
|
||||
return app.UseMiddleware<RequestLocalizationMiddleware>(options);
|
||||
return app.UseMiddleware<RequestLocalizationMiddleware>();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
|
@ -58,7 +48,7 @@ namespace Microsoft.AspNet.Builder
|
|||
throw new ArgumentNullException(nameof(options));
|
||||
}
|
||||
|
||||
return app.UseMiddleware<RequestLocalizationMiddleware>(options);
|
||||
return app.UseMiddleware<RequestLocalizationMiddleware>(Options.Create(options));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -2,6 +2,7 @@
|
|||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
||||
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.AspNet.Builder;
|
||||
using Microsoft.AspNet.Http;
|
||||
|
||||
namespace Microsoft.AspNet.Localization
|
||||
|
|
|
|||
|
|
@ -6,9 +6,10 @@ using System.Collections.Generic;
|
|||
using System.Globalization;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.AspNet.Builder;
|
||||
using Microsoft.AspNet.Http;
|
||||
using Microsoft.AspNet.Http.Features;
|
||||
using Microsoft.Extensions.Globalization;
|
||||
using Microsoft.Extensions.Options;
|
||||
|
||||
namespace Microsoft.AspNet.Localization
|
||||
{
|
||||
|
|
@ -29,7 +30,7 @@ namespace Microsoft.AspNet.Localization
|
|||
/// <param name="next">The <see cref="RequestDelegate"/> representing the next middleware in the pipeline.</param>
|
||||
/// <param name="options">The <see cref="RequestLocalizationOptions"/> representing the options for the
|
||||
/// <see cref="RequestLocalizationMiddleware"/>.</param>
|
||||
public RequestLocalizationMiddleware(RequestDelegate next, RequestLocalizationOptions options)
|
||||
public RequestLocalizationMiddleware(RequestDelegate next, IOptions<RequestLocalizationOptions> options)
|
||||
{
|
||||
if (next == null)
|
||||
{
|
||||
|
|
@ -42,7 +43,7 @@ namespace Microsoft.AspNet.Localization
|
|||
}
|
||||
|
||||
_next = next;
|
||||
_options = options;
|
||||
_options = options.Value;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
|
|
|||
|
|
@ -4,8 +4,9 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Globalization;
|
||||
using Microsoft.AspNet.Localization;
|
||||
|
||||
namespace Microsoft.AspNet.Localization
|
||||
namespace Microsoft.AspNet.Builder
|
||||
{
|
||||
/// <summary>
|
||||
/// Specifies options for the <see cref="RequestLocalizationMiddleware"/>.
|
||||
|
|
|
|||
|
|
@ -12,7 +12,8 @@
|
|||
"dependencies": {
|
||||
"Microsoft.AspNet.Http.Extensions": "1.0.0-*",
|
||||
"Microsoft.Extensions.Globalization.CultureInfoCache": "1.0.0-*",
|
||||
"Microsoft.Extensions.Localization.Abstractions": "1.0.0-*"
|
||||
"Microsoft.Extensions.Localization.Abstractions": "1.0.0-*",
|
||||
"Microsoft.Extensions.Options": "1.0.0-*"
|
||||
},
|
||||
"frameworks": {
|
||||
"net451": {},
|
||||
|
|
|
|||
|
|
@ -55,7 +55,6 @@ namespace Microsoft.Extensions.DependencyInjection
|
|||
{
|
||||
services.Configure(setupAction);
|
||||
}
|
||||
services.AddOptions();
|
||||
return services;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -29,17 +29,17 @@ namespace LocalizationWebsite
|
|||
{
|
||||
loggerFactory.AddConsole(minLevel: LogLevel.Warning);
|
||||
|
||||
app.UseRequestLocalization(options =>
|
||||
app.UseRequestLocalization(new RequestLocalizationOptions
|
||||
{
|
||||
options.DefaultRequestCulture = new RequestCulture("en-US");
|
||||
options.SupportedCultures = new List<CultureInfo>()
|
||||
DefaultRequestCulture = new RequestCulture("en-US"),
|
||||
SupportedCultures = new List<CultureInfo>()
|
||||
{
|
||||
new CultureInfo("fr-FR")
|
||||
};
|
||||
options.SupportedUICultures = new List<CultureInfo>()
|
||||
},
|
||||
SupportedUICultures = new List<CultureInfo>()
|
||||
{
|
||||
new CultureInfo("fr-FR")
|
||||
};
|
||||
}
|
||||
});
|
||||
|
||||
var stringLocalizer = stringLocalizerFactory.Create("Test", location: null);
|
||||
|
|
|
|||
|
|
@ -29,17 +29,17 @@ namespace LocalizationWebsite
|
|||
{
|
||||
loggerFactory.AddConsole(minLevel: LogLevel.Warning);
|
||||
|
||||
app.UseRequestLocalization(options =>
|
||||
app.UseRequestLocalization(new RequestLocalizationOptions
|
||||
{
|
||||
options.DefaultRequestCulture = new RequestCulture("en-US");
|
||||
options.SupportedCultures = new List<CultureInfo>()
|
||||
DefaultRequestCulture = new RequestCulture("en-US"),
|
||||
SupportedCultures = new List<CultureInfo>()
|
||||
{
|
||||
new CultureInfo("fr-FR")
|
||||
};
|
||||
options.SupportedUICultures = new List<CultureInfo>()
|
||||
},
|
||||
SupportedUICultures = new List<CultureInfo>()
|
||||
{
|
||||
new CultureInfo("fr-FR")
|
||||
};
|
||||
}
|
||||
});
|
||||
|
||||
var stringLocalizer = stringLocalizerFactory.Create("Test", location: null);
|
||||
|
|
|
|||
|
|
@ -6,7 +6,6 @@ using System.Globalization;
|
|||
using System.Threading.Tasks;
|
||||
using Microsoft.AspNet.Builder;
|
||||
using Microsoft.AspNet.Hosting;
|
||||
using Microsoft.AspNet.Http.Features;
|
||||
using Microsoft.AspNet.Localization;
|
||||
using Microsoft.AspNet.TestHost;
|
||||
using Xunit;
|
||||
|
|
@ -21,14 +20,14 @@ namespace Microsoft.Extensions.Localization.Tests
|
|||
var builder = new WebApplicationBuilder()
|
||||
.Configure(app =>
|
||||
{
|
||||
app.UseRequestLocalization(options =>
|
||||
app.UseRequestLocalization(new RequestLocalizationOptions
|
||||
{
|
||||
options.DefaultRequestCulture = new RequestCulture("en-US");
|
||||
options.SupportedCultures = new List<CultureInfo>
|
||||
DefaultRequestCulture = new RequestCulture("en-US"),
|
||||
SupportedCultures = new List<CultureInfo>
|
||||
{
|
||||
new CultureInfo("ar-SA"),
|
||||
new CultureInfo("en-US")
|
||||
};
|
||||
}
|
||||
});
|
||||
app.Run(context =>
|
||||
{
|
||||
|
|
@ -55,14 +54,14 @@ namespace Microsoft.Extensions.Localization.Tests
|
|||
var builder = new WebApplicationBuilder()
|
||||
.Configure(app =>
|
||||
{
|
||||
app.UseRequestLocalization(options =>
|
||||
app.UseRequestLocalization(new RequestLocalizationOptions
|
||||
{
|
||||
options.DefaultRequestCulture = new RequestCulture("fr-FR");
|
||||
options.SupportedCultures = new List<CultureInfo>
|
||||
DefaultRequestCulture = new RequestCulture("fr-FR"),
|
||||
SupportedCultures = new List<CultureInfo>
|
||||
{
|
||||
new CultureInfo("ar-SA"),
|
||||
new CultureInfo("en-US")
|
||||
};
|
||||
}
|
||||
});
|
||||
app.Run(context =>
|
||||
{
|
||||
|
|
@ -88,14 +87,14 @@ namespace Microsoft.Extensions.Localization.Tests
|
|||
var builder = new WebApplicationBuilder()
|
||||
.Configure(app =>
|
||||
{
|
||||
app.UseRequestLocalization(options =>
|
||||
app.UseRequestLocalization(new RequestLocalizationOptions
|
||||
{
|
||||
options.DefaultRequestCulture = new RequestCulture("fr-FR");
|
||||
options.SupportedCultures = new List<CultureInfo>
|
||||
DefaultRequestCulture = new RequestCulture("fr-FR"),
|
||||
SupportedCultures = new List<CultureInfo>
|
||||
{
|
||||
new CultureInfo("ar-SA"),
|
||||
new CultureInfo("af-ZA")
|
||||
};
|
||||
}
|
||||
});
|
||||
app.Run(context =>
|
||||
{
|
||||
|
|
@ -122,17 +121,17 @@ namespace Microsoft.Extensions.Localization.Tests
|
|||
var builder = new WebApplicationBuilder()
|
||||
.Configure(app =>
|
||||
{
|
||||
app.UseRequestLocalization(options =>
|
||||
app.UseRequestLocalization(new RequestLocalizationOptions
|
||||
{
|
||||
options.DefaultRequestCulture = new RequestCulture("en-US");
|
||||
options.SupportedCultures = new List<CultureInfo>
|
||||
DefaultRequestCulture = new RequestCulture("en-US"),
|
||||
SupportedCultures = new List<CultureInfo>
|
||||
{
|
||||
new CultureInfo("ar-YE")
|
||||
};
|
||||
options.SupportedUICultures = new List<CultureInfo>
|
||||
},
|
||||
SupportedUICultures = new List<CultureInfo>
|
||||
{
|
||||
new CultureInfo("ar-YE")
|
||||
};
|
||||
}
|
||||
});
|
||||
app.Run(context =>
|
||||
{
|
||||
|
|
|
|||
|
|
@ -22,21 +22,23 @@ namespace Microsoft.Extensions.Localization.Tests
|
|||
var builder = new WebApplicationBuilder()
|
||||
.Configure(app =>
|
||||
{
|
||||
app.UseRequestLocalization(options =>
|
||||
var options = new RequestLocalizationOptions
|
||||
{
|
||||
options.DefaultRequestCulture = new RequestCulture("en-US");
|
||||
options.SupportedCultures = new List<CultureInfo>
|
||||
DefaultRequestCulture = new RequestCulture("en-US"),
|
||||
SupportedCultures = new List<CultureInfo>
|
||||
{
|
||||
new CultureInfo("ar-SA")
|
||||
};
|
||||
options.SupportedUICultures = new List<CultureInfo>
|
||||
},
|
||||
SupportedUICultures = new List<CultureInfo>
|
||||
{
|
||||
new CultureInfo("ar-SA")
|
||||
};
|
||||
var provider = new CookieRequestCultureProvider();
|
||||
provider.CookieName = "Preferences";
|
||||
options.RequestCultureProviders.Insert(0, provider);
|
||||
});
|
||||
}
|
||||
};
|
||||
var provider = new CookieRequestCultureProvider();
|
||||
provider.CookieName = "Preferences";
|
||||
options.RequestCultureProviders.Insert(0, provider);
|
||||
|
||||
app.UseRequestLocalization(options);
|
||||
app.Run(context =>
|
||||
{
|
||||
var requestCultureFeature = context.Features.Get<IRequestCultureFeature>();
|
||||
|
|
@ -64,21 +66,22 @@ namespace Microsoft.Extensions.Localization.Tests
|
|||
var builder = new WebApplicationBuilder()
|
||||
.Configure(app =>
|
||||
{
|
||||
app.UseRequestLocalization(options =>
|
||||
var options = new RequestLocalizationOptions
|
||||
{
|
||||
options.DefaultRequestCulture = new RequestCulture("en-US");
|
||||
options.SupportedCultures = new List<CultureInfo>
|
||||
DefaultRequestCulture = new RequestCulture("en-US"),
|
||||
SupportedCultures = new List<CultureInfo>
|
||||
{
|
||||
new CultureInfo("ar-SA")
|
||||
};
|
||||
options.SupportedUICultures = new List<CultureInfo>
|
||||
},
|
||||
SupportedUICultures = new List<CultureInfo>
|
||||
{
|
||||
new CultureInfo("ar-SA")
|
||||
};
|
||||
var provider = new CookieRequestCultureProvider();
|
||||
provider.CookieName = "Preferences";
|
||||
options.RequestCultureProviders.Insert(0, provider);
|
||||
});
|
||||
}
|
||||
};
|
||||
var provider = new CookieRequestCultureProvider();
|
||||
provider.CookieName = "Preferences";
|
||||
options.RequestCultureProviders.Insert(0, provider);
|
||||
app.UseRequestLocalization(options);
|
||||
app.Run(context =>
|
||||
{
|
||||
var requestCultureFeature = context.Features.Get<IRequestCultureFeature>();
|
||||
|
|
@ -102,21 +105,22 @@ namespace Microsoft.Extensions.Localization.Tests
|
|||
var builder = new WebApplicationBuilder()
|
||||
.Configure(app =>
|
||||
{
|
||||
app.UseRequestLocalization(options =>
|
||||
var options = new RequestLocalizationOptions
|
||||
{
|
||||
options.DefaultRequestCulture = new RequestCulture("en-US");
|
||||
options.SupportedCultures = new List<CultureInfo>
|
||||
DefaultRequestCulture = new RequestCulture("en-US"),
|
||||
SupportedCultures = new List<CultureInfo>
|
||||
{
|
||||
new CultureInfo("ar-SA")
|
||||
};
|
||||
options.SupportedUICultures = new List<CultureInfo>
|
||||
},
|
||||
SupportedUICultures = new List<CultureInfo>
|
||||
{
|
||||
new CultureInfo("ar-SA")
|
||||
};
|
||||
var provider = new CookieRequestCultureProvider();
|
||||
provider.CookieName = "Preferences";
|
||||
options.RequestCultureProviders.Insert(0, provider);
|
||||
});
|
||||
}
|
||||
};
|
||||
var provider = new CookieRequestCultureProvider();
|
||||
provider.CookieName = "Preferences";
|
||||
options.RequestCultureProviders.Insert(0, provider);
|
||||
app.UseRequestLocalization(options);
|
||||
app.Run(context =>
|
||||
{
|
||||
var requestCultureFeature = context.Features.Get<IRequestCultureFeature>();
|
||||
|
|
|
|||
|
|
@ -23,24 +23,25 @@ namespace Microsoft.Extensions.Localization.Tests
|
|||
var builder = new WebApplicationBuilder()
|
||||
.Configure(app =>
|
||||
{
|
||||
app.UseRequestLocalization(options =>
|
||||
var options = new RequestLocalizationOptions
|
||||
{
|
||||
options.DefaultRequestCulture = new RequestCulture("en-US");
|
||||
options.SupportedCultures = new List<CultureInfo>
|
||||
DefaultRequestCulture = new RequestCulture("en-US"),
|
||||
SupportedCultures = new List<CultureInfo>
|
||||
{
|
||||
new CultureInfo("ar")
|
||||
};
|
||||
options.SupportedUICultures = new List<CultureInfo>
|
||||
},
|
||||
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);
|
||||
}));
|
||||
});
|
||||
}
|
||||
};
|
||||
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);
|
||||
app.Run(context =>
|
||||
{
|
||||
var requestCultureFeature = context.Features.Get<IRequestCultureFeature>();
|
||||
|
|
|
|||
|
|
@ -21,17 +21,17 @@ namespace Microsoft.Extensions.Localization.Tests
|
|||
var builder = new WebApplicationBuilder()
|
||||
.Configure(app =>
|
||||
{
|
||||
app.UseRequestLocalization(options =>
|
||||
app.UseRequestLocalization(new RequestLocalizationOptions
|
||||
{
|
||||
options.DefaultRequestCulture = new RequestCulture("en-US");
|
||||
options.SupportedCultures = new List<CultureInfo>
|
||||
DefaultRequestCulture = new RequestCulture("en-US"),
|
||||
SupportedCultures = new List<CultureInfo>
|
||||
{
|
||||
new CultureInfo("ar-SA")
|
||||
};
|
||||
options.SupportedUICultures = new List<CultureInfo>
|
||||
},
|
||||
SupportedUICultures = new List<CultureInfo>
|
||||
{
|
||||
new CultureInfo("ar-YE")
|
||||
};
|
||||
}
|
||||
});
|
||||
app.Run(context =>
|
||||
{
|
||||
|
|
@ -56,9 +56,9 @@ namespace Microsoft.Extensions.Localization.Tests
|
|||
var builder = new WebApplicationBuilder()
|
||||
.Configure(app =>
|
||||
{
|
||||
app.UseRequestLocalization(options =>
|
||||
app.UseRequestLocalization(new RequestLocalizationOptions
|
||||
{
|
||||
options.DefaultRequestCulture = new RequestCulture("en-US");
|
||||
DefaultRequestCulture = new RequestCulture("en-US")
|
||||
});
|
||||
app.Run(context =>
|
||||
{
|
||||
|
|
@ -83,17 +83,17 @@ namespace Microsoft.Extensions.Localization.Tests
|
|||
var builder = new WebApplicationBuilder()
|
||||
.Configure(app =>
|
||||
{
|
||||
app.UseRequestLocalization(options =>
|
||||
app.UseRequestLocalization(new RequestLocalizationOptions
|
||||
{
|
||||
options.DefaultRequestCulture = new RequestCulture("en-US");
|
||||
options.SupportedCultures = new List<CultureInfo>
|
||||
DefaultRequestCulture = new RequestCulture("en-US"),
|
||||
SupportedCultures = new List<CultureInfo>
|
||||
{
|
||||
new CultureInfo("ar-SA")
|
||||
};
|
||||
options.SupportedUICultures = new List<CultureInfo>
|
||||
},
|
||||
SupportedUICultures = new List<CultureInfo>
|
||||
{
|
||||
new CultureInfo("ar-SA")
|
||||
};
|
||||
}
|
||||
});
|
||||
app.Run(context =>
|
||||
{
|
||||
|
|
@ -117,17 +117,17 @@ namespace Microsoft.Extensions.Localization.Tests
|
|||
var builder = new WebApplicationBuilder()
|
||||
.Configure(app =>
|
||||
{
|
||||
app.UseRequestLocalization(options =>
|
||||
app.UseRequestLocalization(new RequestLocalizationOptions
|
||||
{
|
||||
options.DefaultRequestCulture = new RequestCulture("en-US");
|
||||
options.SupportedCultures = new List<CultureInfo>
|
||||
DefaultRequestCulture = new RequestCulture("en-US"),
|
||||
SupportedCultures = new List<CultureInfo>
|
||||
{
|
||||
new CultureInfo("ar-SA")
|
||||
};
|
||||
options.SupportedUICultures = new List<CultureInfo>
|
||||
},
|
||||
SupportedUICultures = new List<CultureInfo>
|
||||
{
|
||||
new CultureInfo("ar-SA")
|
||||
};
|
||||
}
|
||||
});
|
||||
app.Run(context =>
|
||||
{
|
||||
|
|
@ -151,17 +151,17 @@ namespace Microsoft.Extensions.Localization.Tests
|
|||
var builder = new WebApplicationBuilder()
|
||||
.Configure(app =>
|
||||
{
|
||||
app.UseRequestLocalization(options =>
|
||||
app.UseRequestLocalization(new RequestLocalizationOptions
|
||||
{
|
||||
options.DefaultRequestCulture = new RequestCulture("en-US");
|
||||
options.SupportedCultures = new List<CultureInfo>
|
||||
DefaultRequestCulture = new RequestCulture("en-US"),
|
||||
SupportedCultures = new List<CultureInfo>
|
||||
{
|
||||
new CultureInfo("ar-SA")
|
||||
};
|
||||
options.SupportedUICultures = new List<CultureInfo>
|
||||
},
|
||||
SupportedUICultures = new List<CultureInfo>
|
||||
{
|
||||
new CultureInfo("ar-SA")
|
||||
};
|
||||
}
|
||||
});
|
||||
app.Run(context =>
|
||||
{
|
||||
|
|
@ -186,17 +186,17 @@ namespace Microsoft.Extensions.Localization.Tests
|
|||
var builder = new WebApplicationBuilder()
|
||||
.Configure(app =>
|
||||
{
|
||||
app.UseRequestLocalization(options =>
|
||||
app.UseRequestLocalization(new RequestLocalizationOptions
|
||||
{
|
||||
options.DefaultRequestCulture = new RequestCulture("en-US");
|
||||
options.SupportedCultures = new List<CultureInfo>
|
||||
DefaultRequestCulture = new RequestCulture("en-US"),
|
||||
SupportedCultures = new List<CultureInfo>
|
||||
{
|
||||
new CultureInfo("ar-SA")
|
||||
};
|
||||
options.SupportedUICultures = new List<CultureInfo>
|
||||
},
|
||||
SupportedUICultures = new List<CultureInfo>
|
||||
{
|
||||
new CultureInfo("ar-SA")
|
||||
};
|
||||
}
|
||||
});
|
||||
app.Run(context =>
|
||||
{
|
||||
|
|
@ -221,22 +221,23 @@ namespace Microsoft.Extensions.Localization.Tests
|
|||
var builder = new WebApplicationBuilder()
|
||||
.Configure(app =>
|
||||
{
|
||||
app.UseRequestLocalization(options =>
|
||||
var options = new RequestLocalizationOptions
|
||||
{
|
||||
options.DefaultRequestCulture = new RequestCulture("en-US");
|
||||
options.SupportedCultures = new List<CultureInfo>
|
||||
DefaultRequestCulture = new RequestCulture("en-US"),
|
||||
SupportedCultures = new List<CultureInfo>
|
||||
{
|
||||
new CultureInfo("ar-SA")
|
||||
};
|
||||
options.SupportedUICultures = new List<CultureInfo>
|
||||
},
|
||||
SupportedUICultures = new List<CultureInfo>
|
||||
{
|
||||
new CultureInfo("ar-YE")
|
||||
};
|
||||
var provider = new QueryStringRequestCultureProvider();
|
||||
provider.QueryStringKey = "c";
|
||||
provider.UIQueryStringKey = "uic";
|
||||
options.RequestCultureProviders.Insert(0, provider);
|
||||
});
|
||||
}
|
||||
};
|
||||
var provider = new QueryStringRequestCultureProvider();
|
||||
provider.QueryStringKey = "c";
|
||||
provider.UIQueryStringKey = "uic";
|
||||
options.RequestCultureProviders.Insert(0, provider);
|
||||
app.UseRequestLocalization(options);
|
||||
app.Run(context =>
|
||||
{
|
||||
var requestCultureFeature = context.Features.Get<IRequestCultureFeature>();
|
||||
|
|
@ -260,22 +261,23 @@ namespace Microsoft.Extensions.Localization.Tests
|
|||
var builder = new WebApplicationBuilder()
|
||||
.Configure(app =>
|
||||
{
|
||||
app.UseRequestLocalization(options =>
|
||||
var options = new RequestLocalizationOptions
|
||||
{
|
||||
options.DefaultRequestCulture = new RequestCulture("en-US");
|
||||
options.SupportedCultures = new List<CultureInfo>
|
||||
DefaultRequestCulture = new RequestCulture("en-US"),
|
||||
SupportedCultures = new List<CultureInfo>
|
||||
{
|
||||
new CultureInfo("FR")
|
||||
};
|
||||
options.SupportedUICultures = new List<CultureInfo>
|
||||
},
|
||||
SupportedUICultures = new List<CultureInfo>
|
||||
{
|
||||
new CultureInfo("FR")
|
||||
};
|
||||
var provider = new QueryStringRequestCultureProvider();
|
||||
provider.QueryStringKey = "c";
|
||||
provider.UIQueryStringKey = "uic";
|
||||
options.RequestCultureProviders.Insert(0, provider);
|
||||
});
|
||||
}
|
||||
};
|
||||
var provider = new QueryStringRequestCultureProvider();
|
||||
provider.QueryStringKey = "c";
|
||||
provider.UIQueryStringKey = "uic";
|
||||
options.RequestCultureProviders.Insert(0, provider);
|
||||
app.UseRequestLocalization(options);
|
||||
app.Run(context =>
|
||||
{
|
||||
var requestCultureFeature = context.Features.Get<IRequestCultureFeature>();
|
||||
|
|
|
|||
|
|
@ -4,6 +4,7 @@
|
|||
using System;
|
||||
using System.Globalization;
|
||||
using System.Threading;
|
||||
using Microsoft.AspNet.Builder;
|
||||
using Xunit;
|
||||
|
||||
namespace Microsoft.AspNet.Localization.Tests
|
||||
|
|
|
|||
|
|
@ -21,7 +21,7 @@ namespace Microsoft.Extensions.Localization.Test
|
|||
|
||||
// Assert
|
||||
var services = collection.ToList();
|
||||
Assert.Equal(4, services.Count);
|
||||
Assert.Equal(2, services.Count);
|
||||
|
||||
Assert.Equal(typeof(IStringLocalizerFactory), services[0].ServiceType);
|
||||
Assert.Equal(typeof(ResourceManagerStringLocalizerFactory), services[0].ImplementationType);
|
||||
|
|
@ -30,12 +30,6 @@ namespace Microsoft.Extensions.Localization.Test
|
|||
Assert.Equal(typeof(IStringLocalizer<>), services[1].ServiceType);
|
||||
Assert.Equal(typeof(StringLocalizer<>), services[1].ImplementationType);
|
||||
Assert.Equal(ServiceLifetime.Transient, services[1].Lifetime);
|
||||
|
||||
Assert.Equal(typeof(IOptions<>), services[2].ServiceType);
|
||||
Assert.Equal(ServiceLifetime.Singleton, services[2].Lifetime);
|
||||
|
||||
Assert.Equal(typeof(IOptionsMonitor<>), services[3].ServiceType);
|
||||
Assert.Equal(ServiceLifetime.Singleton, services[3].Lifetime);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
|
|
@ -49,7 +43,7 @@ namespace Microsoft.Extensions.Localization.Test
|
|||
|
||||
// Assert
|
||||
var services = collection.ToList();
|
||||
Assert.Equal(5, services.Count);
|
||||
Assert.Equal(3, services.Count);
|
||||
|
||||
Assert.Equal(typeof(IStringLocalizerFactory), services[0].ServiceType);
|
||||
Assert.Equal(typeof(ResourceManagerStringLocalizerFactory), services[0].ImplementationType);
|
||||
|
|
@ -61,12 +55,6 @@ namespace Microsoft.Extensions.Localization.Test
|
|||
|
||||
Assert.Equal(typeof(IConfigureOptions<LocalizationOptions>), services[2].ServiceType);
|
||||
Assert.Equal(ServiceLifetime.Singleton, services[2].Lifetime);
|
||||
|
||||
Assert.Equal(typeof(IOptions<>), services[3].ServiceType);
|
||||
Assert.Equal(ServiceLifetime.Singleton, services[3].Lifetime);
|
||||
|
||||
Assert.Equal(typeof(IOptionsMonitor<>), services[4].ServiceType);
|
||||
Assert.Equal(ServiceLifetime.Singleton, services[4].Lifetime);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue