2
2
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
3
3
4
4
using System ;
5
+ using Microsoft . AspNetCore . Mvc . DataAnnotations ;
5
6
using Microsoft . AspNetCore . Mvc . Localization . Internal ;
6
7
using Microsoft . AspNetCore . Mvc . Razor ;
7
8
using Microsoft . Extensions . Localization ;
8
9
9
10
namespace Microsoft . Extensions . DependencyInjection
10
11
{
11
12
/// <summary>
12
- /// Extension methods for configuring MVC view localization.
13
+ /// Extension methods for configuring MVC view and data annotations localization services .
13
14
/// </summary>
14
15
public static class MvcLocalizationMvcBuilderExtensions
15
16
{
16
17
/// <summary>
17
- /// Adds MVC view localization to the application.
18
+ /// Adds MVC view localization services to the application.
18
19
/// </summary>
19
20
/// <param name="builder">The <see cref="IMvcBuilder"/>.</param>
20
21
/// <returns>The <see cref="IMvcBuilder"/>.</returns>
@@ -29,7 +30,7 @@ public static IMvcBuilder AddViewLocalization(this IMvcBuilder builder)
29
30
}
30
31
31
32
/// <summary>
32
- /// Adds MVC view localization to the application.
33
+ /// Adds MVC view localization services to the application.
33
34
/// </summary>
34
35
/// <param name="builder">The <see cref="IMvcBuilder"/>.</param>
35
36
/// <param name="format">The view format for localized views.</param>
@@ -48,7 +49,7 @@ public static IMvcBuilder AddViewLocalization(
48
49
}
49
50
50
51
/// <summary>
51
- /// Adds MVC view localization to the application.
52
+ /// Adds MVC view localization services to the application.
52
53
/// </summary>
53
54
/// <param name="builder">The <see cref="IMvcBuilder"/>.</param>
54
55
/// <param name="setupAction">An action to configure the <see cref="LocalizationOptions"/>.</param>
@@ -67,7 +68,7 @@ public static IMvcBuilder AddViewLocalization(
67
68
}
68
69
69
70
/// <summary>
70
- /// Adds MVC view localization to the application.
71
+ /// Adds MVC view localization services to the application.
71
72
/// </summary>
72
73
/// <param name="builder">The <see cref="IMvcBuilder"/>.</param>
73
74
/// <param name="format">The view format for localized views.</param>
@@ -86,5 +87,233 @@ public static IMvcBuilder AddViewLocalization(
86
87
MvcLocalizationServices . AddLocalizationServices ( builder . Services , format , setupAction ) ;
87
88
return builder ;
88
89
}
90
+
91
+ /// <summary>
92
+ /// Adds MVC view and data annotations localization services to the application.
93
+ /// </summary>
94
+ /// <param name="builder">The <see cref="IMvcBuilder"/>.</param>
95
+ /// <returns>The <see cref="IMvcBuilder"/>.</returns>
96
+ /// <remarks>
97
+ /// Adding localization also adds support for views via
98
+ /// <see cref="MvcViewFeaturesMvcCoreBuilderExtensions.AddViews(IMvcCoreBuilder)"/> and the Razor view engine
99
+ /// via <see cref="MvcRazorMvcCoreBuilderExtensions.AddRazorViewEngine(IMvcCoreBuilder)"/>.
100
+ /// </remarks>
101
+ public static IMvcBuilder AddMvcLocalization ( this IMvcBuilder builder )
102
+ {
103
+ if ( builder == null )
104
+ {
105
+ throw new ArgumentNullException ( nameof ( builder ) ) ;
106
+ }
107
+
108
+ return AddMvcLocalization (
109
+ builder ,
110
+ localizationOptionsSetupAction : null ,
111
+ format : LanguageViewLocationExpanderFormat . Suffix ,
112
+ dataAnnotationsLocalizationOptionsSetupAction : null ) ;
113
+ }
114
+
115
+ /// <summary>
116
+ /// Adds MVC view and data annotations localization services to the application.
117
+ /// </summary>
118
+ /// <param name="builder">The <see cref="IMvcBuilder"/>.</param>
119
+ /// <param name="localizationOptionsSetupAction">An action to configure the <see cref="LocalizationOptions"/>.</param>
120
+ /// <returns>The <see cref="IMvcBuilder"/>.</returns>
121
+ /// <remarks>
122
+ /// Adding localization also adds support for views via
123
+ /// <see cref="MvcViewFeaturesMvcCoreBuilderExtensions.AddViews(IMvcCoreBuilder)"/> and the Razor view engine
124
+ /// via <see cref="MvcRazorMvcCoreBuilderExtensions.AddRazorViewEngine(IMvcCoreBuilder)"/>.
125
+ /// </remarks>
126
+ public static IMvcBuilder AddMvcLocalization (
127
+ this IMvcBuilder builder ,
128
+ Action < LocalizationOptions > localizationOptionsSetupAction )
129
+ {
130
+ if ( builder == null )
131
+ {
132
+ throw new ArgumentNullException ( nameof ( builder ) ) ;
133
+ }
134
+
135
+ return AddMvcLocalization (
136
+ builder ,
137
+ localizationOptionsSetupAction ,
138
+ LanguageViewLocationExpanderFormat . Suffix ,
139
+ dataAnnotationsLocalizationOptionsSetupAction : null ) ;
140
+ }
141
+
142
+ /// <summary>
143
+ /// Adds MVC view and data annotations localization services to the application.
144
+ /// </summary>
145
+ /// <param name="builder">The <see cref="IMvcBuilder"/>.</param>
146
+ /// <param name="format">The view format for localized views.</param>
147
+ /// <returns>The <see cref="IMvcBuilder"/>.</returns>
148
+ /// <remarks>
149
+ /// Adding localization also adds support for views via
150
+ /// <see cref="MvcViewFeaturesMvcCoreBuilderExtensions.AddViews(IMvcCoreBuilder)"/> and the Razor view engine
151
+ /// via <see cref="MvcRazorMvcCoreBuilderExtensions.AddRazorViewEngine(IMvcCoreBuilder)"/>.
152
+ /// </remarks>
153
+ public static IMvcBuilder AddMvcLocalization (
154
+ this IMvcBuilder builder ,
155
+ LanguageViewLocationExpanderFormat format )
156
+ {
157
+ if ( builder == null )
158
+ {
159
+ throw new ArgumentNullException ( nameof ( builder ) ) ;
160
+ }
161
+
162
+ return AddMvcLocalization (
163
+ builder ,
164
+ localizationOptionsSetupAction : null ,
165
+ format : format ,
166
+ dataAnnotationsLocalizationOptionsSetupAction : null ) ;
167
+ }
168
+
169
+ /// <summary>
170
+ /// Adds MVC view and data annotations localization services to the application.
171
+ /// </summary>
172
+ /// <param name="builder">The <see cref="IMvcBuilder"/>.</param>
173
+ /// <param name="localizationOptionsSetupAction">An action to configure the
174
+ /// <see cref="LocalizationOptions"/>.</param>
175
+ /// <param name="format">The view format for localized views.</param>
176
+ /// <returns>The <see cref="IMvcBuilder"/>.</returns>
177
+ /// <remarks>
178
+ /// Adding localization also adds support for views via
179
+ /// <see cref="MvcViewFeaturesMvcCoreBuilderExtensions.AddViews(IMvcCoreBuilder)"/> and the Razor view engine
180
+ /// via <see cref="MvcRazorMvcCoreBuilderExtensions.AddRazorViewEngine(IMvcCoreBuilder)"/>.
181
+ /// </remarks>
182
+ public static IMvcBuilder AddMvcLocalization (
183
+ this IMvcBuilder builder ,
184
+ Action < LocalizationOptions > localizationOptionsSetupAction ,
185
+ LanguageViewLocationExpanderFormat format )
186
+ {
187
+ if ( builder == null )
188
+ {
189
+ throw new ArgumentNullException ( nameof ( builder ) ) ;
190
+ }
191
+
192
+ return AddMvcLocalization (
193
+ builder ,
194
+ localizationOptionsSetupAction : localizationOptionsSetupAction ,
195
+ format : format ,
196
+ dataAnnotationsLocalizationOptionsSetupAction : null ) ;
197
+ }
198
+
199
+ /// <summary>
200
+ /// Adds MVC view and data annotations localization services to the application.
201
+ /// </summary>
202
+ /// <param name="builder">The <see cref="IMvcBuilder"/>.</param>
203
+ /// <param name="dataAnnotationsLocalizationOptionsSetupAction">An action to configure the
204
+ /// <see cref="MvcDataAnnotationsLocalizationOptions"/>.</param>
205
+ /// <returns>The <see cref="IMvcBuilder"/>.</returns>
206
+ /// <remarks>
207
+ /// Adding localization also adds support for views via
208
+ /// <see cref="MvcViewFeaturesMvcCoreBuilderExtensions.AddViews(IMvcCoreBuilder)"/> and the Razor view engine
209
+ /// via <see cref="MvcRazorMvcCoreBuilderExtensions.AddRazorViewEngine(IMvcCoreBuilder)"/>.
210
+ /// </remarks>
211
+ public static IMvcBuilder AddMvcLocalization (
212
+ this IMvcBuilder builder ,
213
+ Action < MvcDataAnnotationsLocalizationOptions > dataAnnotationsLocalizationOptionsSetupAction )
214
+ {
215
+ if ( builder == null )
216
+ {
217
+ throw new ArgumentNullException ( nameof ( builder ) ) ;
218
+ }
219
+
220
+ return AddMvcLocalization (
221
+ builder ,
222
+ localizationOptionsSetupAction : null ,
223
+ format : LanguageViewLocationExpanderFormat . Suffix ,
224
+ dataAnnotationsLocalizationOptionsSetupAction : dataAnnotationsLocalizationOptionsSetupAction ) ;
225
+ }
226
+
227
+ /// <summary>
228
+ /// Adds MVC view and data annotations localization services to the application.
229
+ /// </summary>
230
+ /// <param name="builder">The <see cref="IMvcBuilder"/>.</param>
231
+ /// <param name="localizationOptionsSetupAction">An action to configure the
232
+ /// <see cref="LocalizationOptions"/>.</param>
233
+ /// <param name="dataAnnotationsLocalizationOptionsSetupAction">An action to configure the
234
+ /// <see cref="MvcDataAnnotationsLocalizationOptions"/>.</param>
235
+ /// <returns>The <see cref="IMvcBuilder"/>.</returns>
236
+ /// <remarks>
237
+ /// Adding localization also adds support for views via
238
+ /// <see cref="MvcViewFeaturesMvcCoreBuilderExtensions.AddViews(IMvcCoreBuilder)"/> and the Razor view engine
239
+ /// via <see cref="MvcRazorMvcCoreBuilderExtensions.AddRazorViewEngine(IMvcCoreBuilder)"/>.
240
+ /// </remarks>
241
+ public static IMvcBuilder AddMvcLocalization (
242
+ this IMvcBuilder builder ,
243
+ Action < LocalizationOptions > localizationOptionsSetupAction ,
244
+ Action < MvcDataAnnotationsLocalizationOptions > dataAnnotationsLocalizationOptionsSetupAction )
245
+ {
246
+ if ( builder == null )
247
+ {
248
+ throw new ArgumentNullException ( nameof ( builder ) ) ;
249
+ }
250
+
251
+ return AddMvcLocalization (
252
+ builder ,
253
+ localizationOptionsSetupAction : localizationOptionsSetupAction ,
254
+ format : LanguageViewLocationExpanderFormat . Suffix ,
255
+ dataAnnotationsLocalizationOptionsSetupAction : dataAnnotationsLocalizationOptionsSetupAction ) ;
256
+ }
257
+
258
+ /// <summary>
259
+ /// Adds MVC view and data annotations localization services to the application.
260
+ /// </summary>
261
+ /// <param name="builder">The <see cref="IMvcBuilder"/>.</param>
262
+ /// <param name="format">The view format for localized views.</param>
263
+ /// <param name="dataAnnotationsLocalizationOptionsSetupAction">An action to configure the
264
+ /// <see cref="MvcDataAnnotationsLocalizationOptions"/>.</param>
265
+ /// <returns>The <see cref="IMvcBuilder"/>.</returns>
266
+ /// <remarks>
267
+ /// Adding localization also adds support for views via
268
+ /// <see cref="MvcViewFeaturesMvcCoreBuilderExtensions.AddViews(IMvcCoreBuilder)"/> and the Razor view engine
269
+ /// via <see cref="MvcRazorMvcCoreBuilderExtensions.AddRazorViewEngine(IMvcCoreBuilder)"/>.
270
+ /// </remarks>
271
+ public static IMvcBuilder AddMvcLocalization (
272
+ this IMvcBuilder builder ,
273
+ LanguageViewLocationExpanderFormat format ,
274
+ Action < MvcDataAnnotationsLocalizationOptions > dataAnnotationsLocalizationOptionsSetupAction )
275
+ {
276
+ if ( builder == null )
277
+ {
278
+ throw new ArgumentNullException ( nameof ( builder ) ) ;
279
+ }
280
+
281
+ return AddMvcLocalization (
282
+ builder ,
283
+ localizationOptionsSetupAction : null ,
284
+ format : format ,
285
+ dataAnnotationsLocalizationOptionsSetupAction : dataAnnotationsLocalizationOptionsSetupAction ) ;
286
+ }
287
+
288
+ /// <summary>
289
+ /// Adds MVC view and data annotations localization services to the application.
290
+ /// </summary>
291
+ /// <param name="builder">The <see cref="IMvcBuilder"/>.</param>
292
+ /// <param name="localizationOptionsSetupAction">An action to configure the <see cref="LocalizationOptions"/>.
293
+ /// Can be <c>null</c>.</param>
294
+ /// <param name="format">The view format for localized views.</param>
295
+ /// <param name="dataAnnotationsLocalizationOptionsSetupAction">An action to configure
296
+ /// the <see cref="MvcDataAnnotationsLocalizationOptions"/>. Can be <c>null</c>.</param>
297
+ /// <returns>The <see cref="IMvcBuilder"/>.</returns>
298
+ /// <remarks>
299
+ /// Adding localization also adds support for views via
300
+ /// <see cref="MvcViewFeaturesMvcCoreBuilderExtensions.AddViews(IMvcCoreBuilder)"/> and the Razor view engine
301
+ /// via <see cref="MvcRazorMvcCoreBuilderExtensions.AddRazorViewEngine(IMvcCoreBuilder)"/>.
302
+ /// </remarks>
303
+ public static IMvcBuilder AddMvcLocalization (
304
+ this IMvcBuilder builder ,
305
+ Action < LocalizationOptions > localizationOptionsSetupAction ,
306
+ LanguageViewLocationExpanderFormat format ,
307
+ Action < MvcDataAnnotationsLocalizationOptions > dataAnnotationsLocalizationOptionsSetupAction )
308
+ {
309
+ if ( builder == null )
310
+ {
311
+ throw new ArgumentNullException ( nameof ( builder ) ) ;
312
+ }
313
+
314
+ return builder
315
+ . AddViewLocalization ( format , localizationOptionsSetupAction )
316
+ . AddDataAnnotationsLocalization ( dataAnnotationsLocalizationOptionsSetupAction ) ;
317
+ }
89
318
}
90
319
}
0 commit comments