@@ -104,6 +104,8 @@ public void ConfigureServices(IServiceCollection services)
104104 null , null , string . IsNullOrEmpty ( Appsettings . OtlpInstanceId ) , Appsettings . OtlpInstanceId ) )
105105 . AddOtlpTraces ( )
106106 . AddOtlpMetrics ( ) ;
107+
108+ services . AddLocalization ( options => options . ResourcesPath = "Resources" ) ;
107109 }
108110
109111 // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
@@ -115,10 +117,19 @@ public void Configure(IApplicationBuilder app, IWebHostEnvironment env, IService
115117 app . UsePathBase ( basePath ) ;
116118 }
117119
118- // Add localization middleware
119- var localizationOptions = app . ApplicationServices . GetService < Microsoft . Extensions . Options . IOptions < RequestLocalizationOptions > > ( ) . Value ;
120- app . UseRequestLocalization ( localizationOptions ) ;
121- app . UseMiddleware < LocalizationMiddleware > ( ) ;
120+ app . UseRequestLocalization ( options =>
121+ {
122+ var cultures = new [ ] { "en-US" , "zh-CN" } ;
123+
124+ options . DefaultRequestCulture = new RequestCulture ( cultures [ 0 ] ) ;
125+ options . AddSupportedCultures ( cultures ) ;
126+ options . AddSupportedUICultures ( cultures ) ;
127+ options . SetDefaultCulture ( cultures [ 0 ] ) ;
128+
129+ // Configure request culture providers
130+ options . RequestCultureProviders . Insert ( 0 , new QueryStringRequestCultureProvider ( ) ) ;
131+ options . RequestCultureProviders . Insert ( 1 , new AcceptLanguageHeaderRequestCultureProvider ( ) ) ;
132+ } ) ;
122133
123134 if ( env . IsDevelopment ( ) )
124135 {
@@ -175,26 +186,5 @@ private void AddSwaggerMiddleWare(IApplicationBuilder app)
175186 c . SwaggerEndpoint ( "v1/swagger.json" , "My API V1" ) ;
176187 } ) ;
177188 }
178-
179- private void AddLocalizationServices ( IServiceCollection services )
180- {
181- services . AddLocalization ( options => options . ResourcesPath = "Resources" ) ;
182- services . Configure < RequestLocalizationOptions > ( options =>
183- {
184- var supportedCultures = new [ ]
185- {
186- new CultureInfo ( "en-US" ) ,
187- new CultureInfo ( "zh-CN" )
188- } ;
189- options . DefaultRequestCulture = new RequestCulture ( "en-US" ) ;
190- options . SupportedCultures = supportedCultures ;
191- options . SupportedUICultures = supportedCultures ;
192-
193- // Configure request culture providers
194- options . RequestCultureProviders . Insert ( 0 , new QueryStringRequestCultureProvider ( ) ) ;
195- options . RequestCultureProviders . Insert ( 1 , new CookieRequestCultureProvider ( ) ) ;
196- options . RequestCultureProviders . Insert ( 2 , new AcceptLanguageHeaderRequestCultureProvider ( ) ) ;
197- } ) ;
198- }
199189 }
200190}
0 commit comments